From 864e505a08f5017b0b93ec58d1ef977aaf222d76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Sat, 30 Jan 2016 20:55:13 +1100 Subject: [PATCH] Have `hub release` only ouput tag names for non-draft releases --- commands/release.go | 33 ++++++++++++++++++++------------- features/release.feature | 9 ++------- github/client.go | 32 +++++++++++++++++++++++--------- 3 files changed, 45 insertions(+), 29 deletions(-) diff --git a/commands/release.go b/commands/release.go index 6f88f19b..5c5c478e 100644 --- a/commands/release.go +++ b/commands/release.go @@ -89,21 +89,28 @@ func init() { } func listReleases(cmd *Command, args *Args) { - runInLocalRepo(func(localRepo *github.GitHubRepo, project *github.Project, client *github.Client) { - if args.Noop { - ui.Printf("Would request list of releases for %s\n", project) - } else { - releases, err := client.Releases(project) - utils.Check(err) - var outputs []string - for _, release := range releases { - out := fmt.Sprintf("%s (%s)\n%s", release.Name, release.TagName, release.Body) - outputs = append(outputs, out) - } + localRepo, err := github.LocalRepo() + utils.Check(err) - ui.Println(strings.Join(outputs, "\n\n")) + project, err := localRepo.MainProject() + utils.Check(err) + + gh := github.NewClient(project.Host) + + if args.Noop { + ui.Printf("Would request list of releases for %s\n", project) + } else { + releases, err := gh.FetchReleases(project) + utils.Check(err) + + for _, release := range releases { + if !release.Draft { + ui.Println(release.TagName) + } } - }) + } + + os.Exit(0) } func createRelease(cmd *Command, args *Args) { diff --git a/features/release.feature b/features/release.feature index 94c9617f..8c804536 100644 --- a/features/release.feature +++ b/features/release.feature @@ -30,11 +30,6 @@ Feature: hub release When I successfully run `hub release` Then the output should contain exactly: """ - will_paginate 1.2.0 (v1.2.0) - - - will_paginate 1.2.0-pre (v1.2.0-pre) - - - will_paginate 1.0.2 (v1.0.2)\n\n + v1.2.0-pre + v1.0.2\n """ diff --git a/github/client.go b/github/client.go index 862eb57c..04ceb6eb 100644 --- a/github/client.go +++ b/github/client.go @@ -245,23 +245,37 @@ func (client *Client) CreateRepository(project *Project, description, homepage s return } -func (client *Client) Releases(project *Project) (releases []octokit.Release, err error) { - url, err := octokit.ReleasesURL.Expand(octokit.M{"owner": project.Owner, "repo": project.Name}) +type Release struct { + Name string `json:"name"` + TagName string `json:"tag_name"` + Body string `json:"body"` + Draft bool `json:"draft"` + Prerelease bool `json:"prerelease"` + Assets []ReleaseAsset `json:"assets"` +} + +type ReleaseAsset struct { + Name string `json:"name"` + Label string `json:"label"` +} + +func (client *Client) FetchReleases(project *Project) (response []Release, err error) { + api, err := client.simpleApi() if err != nil { return } - api, err := client.api() + res, err := api.Get(fmt.Sprintf("repos/%s/%s/releases", project.Owner, project.Name)) if err != nil { - err = FormatError("getting release", err) + return + } + if res.StatusCode != 200 { + err = fmt.Errorf("Unexpected HTTP status code: %d", res.StatusCode) return } - releases, result := api.Releases(client.requestURL(url)).All() - if result.HasError() { - err = FormatError("getting release", result.Err) - return - } + response = []Release{} + err = res.Unmarshal(&response) return }