diff options
author | Slack Coder <slackcoder@server.ky> | 2024-04-08 15:29:11 -0500 |
---|---|---|
committer | Slack Coder <slackcoder@server.ky> | 2024-07-18 11:47:49 -0500 |
commit | ae748859be8d6d3ed3c0929770f0c287ab6d6460 (patch) | |
tree | 284d3bf3d7fa496a9d334391eac996affc5a01b9 /internal/github/filesystem.go | |
parent | c2267767ca8ed06018d26a45b483c44b7c4234cf (diff) | |
download | mirror-ae748859be8d6d3ed3c0929770f0c287ab6d6460.tar.xz |
Port to Golangv0.0.1-dev
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 +} |