diff --git a/commands/release.go b/commands/release.go index 66ac8881..63619b8c 100644 --- a/commands/release.go +++ b/commands/release.go @@ -84,36 +84,41 @@ func createRelease(cmd *Command, args *Args) { tag := args.LastParam() runInLocalRepo(func(localRepo *github.GitHubRepo, project *github.Project, client *github.Client) { - currentBranch, err := localRepo.CurrentBranch() - utils.Check(err) - branchName := currentBranch.ShortName() - - title, body, err := getTitleAndBodyFromFlags(flagReleaseMessage, flagReleaseFile) + release, err := client.Release(project, tag) utils.Check(err) - var editor *github.Editor - if title == "" { - message := releaseMessage(tag, project.Name, branchName) - editor, err = github.NewEditor("RELEASE", "release", message) + if release == nil { + currentBranch, err := localRepo.CurrentBranch() + utils.Check(err) + branchName := currentBranch.ShortName() + + title, body, err := getTitleAndBodyFromFlags(flagReleaseMessage, flagReleaseFile) 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) - } - params := octokit.ReleaseParams{ - TagName: tag, - 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 editor != nil { + defer editor.DeleteFile() + } } if flagReleaseAssets != "" { diff --git a/github/client.go b/github/client.go index 4819df3f..be365d73 100644 --- a/github/client.go +++ b/github/client.go @@ -266,6 +266,33 @@ func (client *Client) Releases(project *Project) (releases []octokit.Release, er 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) { url, err := octokit.ReleasesURL.Expand(octokit.M{"owner": project.Owner, "repo": project.Name}) if err != nil {