From 43f398e8798d82720aaf704f4cf9ff464d4e01c1 Mon Sep 17 00:00:00 2001 From: David Calavera Date: Fri, 20 Dec 2013 15:39:10 -0800 Subject: [PATCH] Write a message in the editor showing what you're doing. --- commands/release.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/commands/release.go b/commands/release.go index bccc3728..232f58d2 100644 --- a/commands/release.go +++ b/commands/release.go @@ -7,6 +7,7 @@ import ( "github.com/jingweno/gh/utils" "github.com/jingweno/go-octokit/octokit" "io" + "io/ioutil" "net/http" "os" "path/filepath" @@ -74,18 +75,19 @@ func release(cmd *Command, args *Args) { runInLocalRepo(func(localRepo *github.GitHubRepo, project *github.Project, gh *github.Client) { currentBranch, err := localRepo.CurrentBranch() utils.Check(err) + branchName := currentBranch.ShortName() title, body, err := github.GetTitleAndBodyFromFlags(flagReleaseMessage, flagReleaseFile) utils.Check(err) if title == "" { - title, body, err = github.GetTitleAndBodyFromEditor(nil) + title, body, err = writeReleaseTitleAndBody(project, tag, branchName) utils.Check(err) } params := octokit.ReleaseParams{ TagName: tag, - TargetCommitish: currentBranch.ShortName(), + TargetCommitish: branchName, Name: title, Body: body, Draft: flagReleaseDraft, @@ -100,6 +102,20 @@ func release(cmd *Command, args *Args) { }) } +func writeReleaseTitleAndBody(project *github.Project, tag, currentBranch string) (string, string, error) { + return github.GetTitleAndBodyFromEditor(func(messageFile string) error { + message := ` +# Creating release %s for %s from %s +# +# Write a message for this release. The first block +# of the text is the title and the rest is description. +` + message = fmt.Sprintf(message, tag, project.Name, currentBranch) + + return ioutil.WriteFile(messageFile, []byte(message), 0644) + }) +} + func runInLocalRepo(fn func(localRepo *github.GitHubRepo, project *github.Project, client *github.Client)) { localRepo := github.LocalRepo() project, err := localRepo.CurrentProject()