8000 GetRelease from GitHub store now tries to find a release with a tag matching the version with 'v' prefixed or the version directly by gulien · Pull Request #10 · tj/go-update · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

GetRelease from GitHub store now tries to find a release with a tag matching the version with 'v' prefixed or the version directly #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 34 additions & 11 deletions stores/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,27 @@ type Store struct {
Version string
}

// GetRelease returns the specified release or ErrNotFound.
func (s *Store) GetRelease(version string) (*update.Release, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

gh := github.NewClient(nil)
/*
GetRelease returns the specified release or ErrNotFound.

r, res, err := gh.Repositories.GetReleaseByTag(ctx, s.Owner, s.Repo, "v"+version)
It tries to find a GitHub release with a tag matching the given version
with "v" prefixed.

if res.StatusCode == 404 {
return nil, update.ErrNotFound
}
If this first step fails, it tries to find a GitHub release with a tag matching
exactly with the given version.
*/
func (s *Store) GetRelease(version string) (*update.Release, error) {
r, err := getGithubReleaseByTag("v" + version)

if err != nil {
if _, ok := err.(*update.ErrNotFound); ok {
return getGithubReleaseByTag(version)
}

return nil, err
}

return githubRelease(r), nil
return r, nil
}

// LatestReleases returns releases newer than Version, or nil.
Expand Down Expand Up @@ -61,6 +64,26 @@ func (s *Store) LatestReleases() (latest []*update.Release, err error) {
return
}

// getGithubReleaseByTag returns the specified release or ErrNotFound.
func getGithubReleaseByTag(tag string) (*update.Release, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

gh := github.NewClient(nil)

r, res, err := gh.Repositories.GetReleaseByTag(ctx, s.Owner, s.Repo, tag)

if res.StatusCode == 404 {
return nil, update.ErrNotFound
}

if err != nil {
return nil, err
}

return githubRelease(r), nil
}

// githubRelease returns a Release.
func githubRelease(r *github.RepositoryRelease) *update.Release {
out := &update.Release{
Expand Down
0