Show commented-out help text whenever an editor is opened

This shows commented-out text such as "Creating an issue for github/hub"
not only when `-m` or `-F` weren't passed, but also when they were
passed and `--edit` was used.
This commit is contained in:
Mislav Marohnić 2018-01-23 18:08:23 +01:00
Родитель 0ef312ec03
Коммит a4274c1615
3 изменённых файлов: 25 добавлений и 29 удалений

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

@ -362,6 +362,11 @@ func createIssue(cmd *Command, args *Args) {
Title: "issue",
}
messageBuilder.AddCommentedSection(fmt.Sprintf(`Creating an issue for %s
Write a message for this issue. The first block of
text is the title and the rest is the description.`, project))
if cmd.FlagPassed("message") {
messageBuilder.Message = flagIssueMessage
messageBuilder.Edit = flagIssueEdit
@ -371,23 +376,16 @@ func createIssue(cmd *Command, args *Args) {
messageBuilder.Edit = flagIssueEdit
} else {
messageBuilder.Edit = true
message := ""
helpMessage := fmt.Sprintf(`Creating an issue for %s
Write a message for this issue. The first block of
text is the title and the rest is the description.`, project)
workdir, _ := git.WorkdirName()
if workdir != "" {
template, err := github.ReadTemplate(github.IssueTemplate, workdir)
utils.Check(err)
if template != "" {
message = template
messageBuilder.Message = template
}
}
messageBuilder.Message = message
messageBuilder.AddCommentedSection(helpMessage)
}
title, body, err := messageBuilder.Extract()

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

@ -225,6 +225,11 @@ func pullRequest(cmd *Command, args *Args) {
utils.Check(fmt.Errorf("Can't find remote for %s", head))
}
messageBuilder.AddCommentedSection(fmt.Sprintf(`Requesting a pull to %s from %s
Write a message for this pull request. The first block
of text is the title and the rest is the description.`, fullBase, fullHead))
if cmd.FlagPassed("message") {
messageBuilder.Message = flagPullRequestMessage
messageBuilder.Edit = flagPullRequestEdit
@ -252,6 +257,10 @@ func pullRequest(cmd *Command, args *Args) {
utils.Check(err)
}
if commitLogs != "" {
messageBuilder.AddCommentedSection("\nChanges:\n\n" + strings.TrimSpace(commitLogs))
}
workdir, _ := git.WorkdirName()
if workdir != "" {
template, _ := github.ReadTemplate(github.PullRequestTemplate, workdir)
@ -260,16 +269,7 @@ func pullRequest(cmd *Command, args *Args) {
}
}
helpMessage := fmt.Sprintf(`Requesting a pull to %s from %s
Write a message for this pull request. The first block
of text is the title and the rest is the description.`, fullBase, fullHead)
if commitLogs != "" {
helpMessage = helpMessage + "\n\nChanges:\n\n" + strings.TrimSpace(commitLogs)
}
messageBuilder.Message = message
messageBuilder.AddCommentedSection(helpMessage)
}
title, body, err := messageBuilder.Extract()

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

@ -301,6 +301,11 @@ func createRelease(cmd *Command, args *Args) {
Title: "release",
}
messageBuilder.AddCommentedSection(fmt.Sprintf(`Creating release %s for %s
Write a message for this release. The first block of
text is the title and the rest is the description.`, tagName, project))
if cmd.FlagPassed("message") {
messageBuilder.Message = flagReleaseMessage
messageBuilder.Edit = flagReleaseEdit
@ -310,12 +315,6 @@ func createRelease(cmd *Command, args *Args) {
messageBuilder.Edit = flagReleaseEdit
} else {
messageBuilder.Edit = true
helpMessage := fmt.Sprintf(`Creating release %s for %s
Write a message for this release. The first block of
text is the title and the rest is the description.`, tagName, project.String())
messageBuilder.AddCommentedSection(helpMessage)
}
title, body, err := messageBuilder.Extract()
@ -388,6 +387,11 @@ func editRelease(cmd *Command, args *Args) {
Title: "release",
}
messageBuilder.AddCommentedSection(fmt.Sprintf(`Editing release %s for %s
Write a message for this release. The first block of
text is the title and the rest is the description.`, tagName, project))
if cmd.FlagPassed("message") {
messageBuilder.Message = flagReleaseMessage
messageBuilder.Edit = flagReleaseEdit
@ -398,12 +402,6 @@ func editRelease(cmd *Command, args *Args) {
} else {
messageBuilder.Edit = true
messageBuilder.Message = fmt.Sprintf("%s\n\n%s", release.Name, release.Body)
helpMessage := fmt.Sprintf(`Editing release %s for %s
Write a message for this release. The first block of
text is the title and the rest is the description.`, tagName, project.String())
messageBuilder.AddCommentedSection(helpMessage)
}
title, body, err := messageBuilder.Extract()