func uploadAssets(gh *github.Client, release *github.Release, assets []string, args *Args) { for _, asset := range assets { var label string parts := strings.SplitN(asset, "#", 2) asset = parts[0] if len(parts) > 1 { label = parts[1] } if args.Noop { if label == "" { ui.Errorf("Would attach release asset `%s'\n", asset) } else { ui.Errorf("Would attach release asset `%s' with label `%s'\n", asset, label) } } else { for _, existingAsset := range release.Assets { if existingAsset.Name == filepath.Base(asset) { err := gh.DeleteReleaseAsset(&existingAsset) utils.Check(err) break } } ui.Errorf("Attaching release asset `%s'...\n", asset) _, err := gh.UploadReleaseAsset(release, asset, label) utils.Check(err) } } }
func (updater *Updater) latestReleaseNameAndVersion() (name, version string) { // Create Client with a stub Host c := github.Client{Host: &github.Host{Host: updater.Host}} name, _ = c.GhLatestTagName() version = strings.TrimPrefix(name, "v") return }
func downloadReleaseAsset(asset github.ReleaseAsset, gh *github.Client) (err error) { assetReader, err := gh.DownloadReleaseAsset(asset.ApiUrl) if err != nil { return } defer assetReader.Close() assetFile, err := os.OpenFile(asset.Name, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0644) if err != nil { return } defer assetFile.Close() _, err = io.Copy(assetFile, assetReader) if err != nil { return } return }