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 }