зеркало из https://github.com/mislav/hub.git
Have `hub release` only ouput tag names for non-draft releases
This commit is contained in:
Родитель
6ab30c80f1
Коммит
864e505a08
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
"""
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче