Make release note comment character configurable

This commit is contained in:
Jingwen Owen Ou 2014-12-24 22:33:47 -08:00
Родитель e1d835ca87
Коммит d655819f69
3 изменённых файлов: 60 добавлений и 11 удалений

Просмотреть файл

@ -10,6 +10,7 @@ import (
"strings"
"github.com/github/hub/Godeps/_workspace/src/github.com/octokit/go-octokit/octokit"
"github.com/github/hub/git"
"github.com/github/hub/github"
"github.com/github/hub/utils"
)
@ -109,7 +110,10 @@ func createRelease(cmd *Command, args *Args) {
var editor *github.Editor
if title == "" {
message := releaseMessage(tag, project.Name, branchName)
cs := git.CommentChar()
message, err := renderReleaseTpl(cs, tag, project.Name, branchName)
utils.Check(err)
editor, err = github.NewEditor("RELEASE", "release", message)
utils.Check(err)
@ -158,16 +162,6 @@ func createRelease(cmd *Command, args *Args) {
})
}
func releaseMessage(tag, projectName, currentBranch string) string {
message := `
# Creating release %s for %s from %s
#
# Write a message for this release. The first block
# of text is the title and the rest is description.
`
return fmt.Sprintf(message, tag, projectName, currentBranch)
}
type assetUploader struct {
Client *github.Client
Release *octokit.Release

37
commands/release_tpl.go Normal file
Просмотреть файл

@ -0,0 +1,37 @@
package commands
import (
"bytes"
"text/template"
)
const releaseTmpl = `{{.CS}} Creating release {{.TagName}} for {{.ProjectName}} from {{.BranchName}}
{{.CS}}
{{.CS}} Write a message for this release. The first block
{{.CS}} of text is the title and the rest is description.`
type releaseMsg struct {
CS string
TagName string
ProjectName string
BranchName string
}
func renderReleaseTpl(cs, tagName, projectName, branchName string) (string, error) {
t, err := template.New("releaseTmpl").Parse(releaseTmpl)
if err != nil {
return "", err
}
msg := &releaseMsg{
CS: cs,
TagName: tagName,
ProjectName: projectName,
BranchName: branchName,
}
var b bytes.Buffer
err = t.Execute(&b, msg)
return b.String(), err
}

Просмотреть файл

@ -0,0 +1,18 @@
package commands
import (
"testing"
"github.com/github/hub/Godeps/_workspace/src/github.com/bmizerany/assert"
)
func TestRenderReleaseTpl(t *testing.T) {
msg, err := renderReleaseTpl("#", "1.0", "hub", "master")
assert.Equal(t, nil, err)
expMsg := `# Creating release 1.0 for hub from master
#
# Write a message for this release. The first block
# of text is the title and the rest is description.`
assert.Equal(t, expMsg, msg)
}