提交 0dc077ac 编写于 作者: J Jonny Stoten 提交者: Mislav Marohnić

Use scissors to separate comments from PR messages

This allows PR templates to include markdown headers with '#'
上级 5346928a
......@@ -269,18 +269,22 @@ Feature: hub pull-request
Hello
# Requesting a pull to mislav:master from mislav:topic
#
# Write a message for this pull request. The first block
# of text is the title and the rest is the description.
#
# Changes:
#
# SHA1SHA (Hub, 0 seconds ago)
# Two on topic
#
# SHA1SHA (Hub, 0 seconds ago)
# One on topic
# ------------------------ >8 ------------------------
# Do not modify or remove the line above.
# Everything below it will be ignored.
Requesting a pull to mislav:master from mislav:topic
Write a message for this pull request. The first block
of text is the title and the rest is the description.
Changes:
SHA1SHA (Hub, 0 seconds ago)
Two on topic
SHA1SHA (Hub, 0 seconds ago)
One on topic
"""
......@@ -363,7 +367,7 @@ Feature: hub pull-request
"""
# Dat title
/ This line is commented out.
/ This line is not commented out.
Dem body.
"""
......@@ -371,7 +375,7 @@ Feature: hub pull-request
"""
post('/repos/mislav/coral/pulls') {
assert :title => '# Dat title',
:body => 'Dem body.'
:body => "/ This line is not commented out.\n\nDem body."
status 201
json :html_url => "the://url"
}
......
......@@ -14,6 +14,8 @@ import (
"github.com/github/hub/git"
)
const Scissors = "------------------------ >8 ------------------------"
func NewEditor(filename, topic, message string) (editor *Editor, err error) {
gitDir, err := git.Dir()
if err != nil {
......@@ -44,20 +46,25 @@ func NewEditor(filename, topic, message string) (editor *Editor, err error) {
}
type Editor struct {
Program string
Topic string
File string
Message string
CS string
openEditor func(program, file string) error
Program string
Topic string
File string
Message string
CS string
addedFirstComment bool
openEditor func(program, file string) error
}
func (e *Editor) AddCommentedSection(text string) {
startRegexp := regexp.MustCompilePOSIX("^")
endRegexp := regexp.MustCompilePOSIX(" +$")
commentedText := startRegexp.ReplaceAllString(text, e.CS+" ")
commentedText = endRegexp.ReplaceAllString(commentedText, "")
e.Message = e.Message + "\n" + commentedText
if !e.addedFirstComment {
scissors := e.CS + " " + Scissors + "\n"
scissors += e.CS + " Do not modify or remove the line above.\n"
scissors += e.CS + " Everything below it will be ignored.\n"
e.Message = e.Message + "\n" + scissors
e.addedFirstComment = true
}
e.Message = e.Message + "\n" + text
}
func (e *Editor) DeleteFile() error {
......@@ -75,11 +82,13 @@ func (e *Editor) EditContent() (content string, err error) {
scanner := bufio.NewScanner(reader)
unquotedLines := []string{}
scissorsLine := e.CS + " " + Scissors
for scanner.Scan() {
line := scanner.Text()
if e.CS == "" || !strings.HasPrefix(line, e.CS) {
unquotedLines = append(unquotedLines, line)
if line == scissorsLine {
break
}
unquotedLines = append(unquotedLines, line)
}
if err = scanner.Err(); err != nil {
return
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册