зеркало из https://github.com/mislav/hub.git
Check existence of release before creating it
This commit is contained in:
Родитель
c5ed2474ad
Коммит
f14a008893
|
@ -84,36 +84,41 @@ func createRelease(cmd *Command, args *Args) {
|
||||||
|
|
||||||
tag := args.LastParam()
|
tag := args.LastParam()
|
||||||
runInLocalRepo(func(localRepo *github.GitHubRepo, project *github.Project, client *github.Client) {
|
runInLocalRepo(func(localRepo *github.GitHubRepo, project *github.Project, client *github.Client) {
|
||||||
currentBranch, err := localRepo.CurrentBranch()
|
release, err := client.Release(project, tag)
|
||||||
utils.Check(err)
|
|
||||||
branchName := currentBranch.ShortName()
|
|
||||||
|
|
||||||
title, body, err := getTitleAndBodyFromFlags(flagReleaseMessage, flagReleaseFile)
|
|
||||||
utils.Check(err)
|
utils.Check(err)
|
||||||
|
|
||||||
var editor *github.Editor
|
if release == nil {
|
||||||
if title == "" {
|
currentBranch, err := localRepo.CurrentBranch()
|
||||||
message := releaseMessage(tag, project.Name, branchName)
|
utils.Check(err)
|
||||||
editor, err = github.NewEditor("RELEASE", "release", message)
|
branchName := currentBranch.ShortName()
|
||||||
|
|
||||||
|
title, body, err := getTitleAndBodyFromFlags(flagReleaseMessage, flagReleaseFile)
|
||||||
utils.Check(err)
|
utils.Check(err)
|
||||||
|
|
||||||
title, body, err = editor.EditTitleAndBody()
|
var editor *github.Editor
|
||||||
|
if title == "" {
|
||||||
|
message := releaseMessage(tag, project.Name, branchName)
|
||||||
|
editor, err = github.NewEditor("RELEASE", "release", message)
|
||||||
|
utils.Check(err)
|
||||||
|
|
||||||
|
title, body, err = editor.EditTitleAndBody()
|
||||||
|
utils.Check(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
params := octokit.ReleaseParams{
|
||||||
|
TagName: tag,
|
||||||
|
TargetCommitish: branchName,
|
||||||
|
Name: title,
|
||||||
|
Body: body,
|
||||||
|
Draft: flagReleaseDraft,
|
||||||
|
Prerelease: flagReleasePrerelease,
|
||||||
|
}
|
||||||
|
release, err = client.CreateRelease(project, params)
|
||||||
utils.Check(err)
|
utils.Check(err)
|
||||||
}
|
|
||||||
|
|
||||||
params := octokit.ReleaseParams{
|
if editor != nil {
|
||||||
TagName: tag,
|
defer editor.DeleteFile()
|
||||||
TargetCommitish: branchName,
|
}
|
||||||
Name: title,
|
|
||||||
Body: body,
|
|
||||||
Draft: flagReleaseDraft,
|
|
||||||
Prerelease: flagReleasePrerelease,
|
|
||||||
}
|
|
||||||
release, err := client.CreateRelease(project, params)
|
|
||||||
utils.Check(err)
|
|
||||||
|
|
||||||
if editor != nil {
|
|
||||||
defer editor.DeleteFile()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if flagReleaseAssets != "" {
|
if flagReleaseAssets != "" {
|
||||||
|
|
|
@ -266,6 +266,33 @@ func (client *Client) Releases(project *Project) (releases []octokit.Release, er
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (client *Client) Release(project *Project, tagName string) (release *octokit.Release, err error) {
|
||||||
|
url, err := octokit.ReleasesURL.Expand(octokit.M{"owner": project.Owner, "repo": project.Name})
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
api, err := client.api()
|
||||||
|
if err != nil {
|
||||||
|
err = FormatError("getting release", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
releases, result := api.Releases(client.requestURL(url)).All()
|
||||||
|
if result.HasError() {
|
||||||
|
err = FormatError("creating release", result.Err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, release := range releases {
|
||||||
|
if release.TagName == tagName {
|
||||||
|
return &release, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (client *Client) CreateRelease(project *Project, params octokit.ReleaseParams) (release *octokit.Release, err error) {
|
func (client *Client) CreateRelease(project *Project, params octokit.ReleaseParams) (release *octokit.Release, err error) {
|
||||||
url, err := octokit.ReleasesURL.Expand(octokit.M{"owner": project.Owner, "repo": project.Name})
|
url, err := octokit.ReleasesURL.Expand(octokit.M{"owner": project.Owner, "repo": project.Name})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче