diff options
Diffstat (limited to 'internal/github/filesystem.go')
-rw-r--r-- | internal/github/filesystem.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/internal/github/filesystem.go b/internal/github/filesystem.go new file mode 100644 index 0000000..3f069b4 --- /dev/null +++ b/internal/github/filesystem.go @@ -0,0 +1,63 @@ +package github + +import ( + "fmt" + "net/url" + "os" + "path" + "strings" +) + +func listReleasesByTagName(dst *url.URL) ([]string, error) { + entries, err := os.ReadDir(dst.Path) + if err != nil { + return nil, err + } + + var tagNames []string + for _, entry := range entries { + tagNames = append(tagNames, entry.Name()) + } + + return tagNames, nil +} + +// The path which project release assets are saved. +func localReleaseFilePath(dst *url.URL, tagName string) string { + return path.Join(dst.Path, tagName) +} + +func releaseName(tagName string) string { + version := tagName + if strings.HasPrefix(version, "v") { + version = strings.TrimLeft(version, "v") + } + + return version +} + +// The source filename for a Github release. +// +// # The source code URL provided by Github's API only references the tag name +// +// for the release. To make it useful for users, we rename to file to include +// the project name as their website does. +func releaseSourceFileName(project string, tagName string, ext string) string { + return fmt.Sprintf("%s-%s.%s", project, releaseName(tagName), ext) +} + +func removeRelease(dst *url.URL, tagName string) error { + fp := localReleaseFilePath(dst, tagName) + return os.RemoveAll(fp) +} + +func isFileExist(fp string) (bool, error) { + _, err := os.Stat(fp) + if os.IsNotExist(err) { + return false, nil + } else if err != nil { + return false, err + } + + return true, nil +} |