Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
a5aa2c63
H
hub
项目概览
github
/
hub
10 个月 前同步成功
通知
3
Star
22523
Fork
2406
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a5aa2c63
编写于
4月 28, 2013
作者:
J
Jingwen Owen Ou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add commit logs to PR message
上级
761d0eb4
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
83 addition
and
4 deletion
+83
-4
exec_cmd.go
exec_cmd.go
+29
-0
exec_cmd_test.go
exec_cmd_test.go
+13
-0
git.go
git.go
+17
-0
git_test.go
git_test.go
+2
-0
pull_request.go
pull_request.go
+22
-4
未找到文件。
exec_cmd.go
0 → 100644
浏览文件 @
a5aa2c63
package
main
import
(
"os/exec"
)
type
ExecCmd
struct
{
Name
string
Args
[]
string
}
func
(
cmd
*
ExecCmd
)
WithArg
(
arg
string
)
*
ExecCmd
{
cmd
.
Args
=
append
(
cmd
.
Args
,
arg
)
return
cmd
}
func
(
cmd
*
ExecCmd
)
Exec
()
(
out
string
,
err
error
)
{
output
,
err
:=
exec
.
Command
(
cmd
.
Name
,
cmd
.
Args
...
)
.
Output
()
if
err
!=
nil
{
return
""
,
err
}
return
string
(
output
),
nil
}
func
NewExecCmd
(
name
string
)
*
ExecCmd
{
return
&
ExecCmd
{
name
,
make
([]
string
,
0
)}
}
exec_cmd_test.go
0 → 100644
浏览文件 @
a5aa2c63
package
main
import
(
"github.com/bmizerany/assert"
"testing"
)
func
TestWithArg
(
t
*
testing
.
T
)
{
execCmd
:=
NewExecCmd
(
"git"
)
execCmd
.
WithArg
(
"log"
)
.
WithArg
(
"--no-color"
)
assert
.
Equal
(
t
,
"git"
,
execCmd
.
Name
)
assert
.
Equal
(
t
,
2
,
len
(
execCmd
.
Args
))
}
git.go
浏览文件 @
a5aa2c63
...
...
@@ -2,6 +2,7 @@ package main
import
(
"bytes"
"fmt"
"log"
"os/exec"
"path/filepath"
...
...
@@ -41,6 +42,22 @@ func (g *Git) CurrentBranch() string {
return
execGitCmd
(
"symbolic-ref -q --short HEAD"
)[
0
]
}
func
(
g
*
Git
)
CommitLogs
(
sha1
,
sha2
string
)
string
{
execCmd
:=
NewExecCmd
(
"git"
)
execCmd
.
WithArg
(
"log"
)
.
WithArg
(
"--no-color"
)
execCmd
.
WithArg
(
"--format=%h (%aN, %ar)%n%w(78,3,3)%s%n%+b"
)
execCmd
.
WithArg
(
"--cherry"
)
shaRange
:=
fmt
.
Sprintf
(
"%s...%s"
,
sha1
,
sha2
)
execCmd
.
WithArg
(
shaRange
)
outputs
,
err
:=
execCmd
.
Exec
()
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
return
outputs
}
// FIXME: only care about origin push remote now
func
(
g
*
Git
)
Remote
()
string
{
r
:=
regexp
.
MustCompile
(
"origin
\t
(.+)
\\
(push
\\
)"
)
...
...
git_test.go
浏览文件 @
a5aa2c63
...
...
@@ -13,4 +13,6 @@ func TestGitMethods(t *testing.T) {
assert
.
Equal
(
t
,
"jingweno"
,
git
.
Owner
())
assert
.
Equal
(
t
,
"gh"
,
git
.
Repo
())
assert
.
Equal
(
t
,
"pull_request"
,
git
.
CurrentBranch
())
logs
:=
git
.
CommitLogs
(
"master"
,
"HEAD"
)
assert
.
Equal
(
t
,
19
,
len
(
logs
))
}
pull_request.go
浏览文件 @
a5aa2c63
...
...
@@ -2,6 +2,7 @@ package main
import
(
"bufio"
"fmt"
"io/ioutil"
"log"
"os"
...
...
@@ -43,7 +44,7 @@ func init() {
func
pullRequest
(
cmd
*
Command
,
args
[]
string
)
{
messageFile
:=
filepath
.
Join
(
git
.
Dir
(),
"PULLREQ_EDITMSG"
)
writePullRequestChanges
(
messageFile
)
writePullRequestChanges
(
messageFile
,
flagPullRequestBase
,
flagPullRequestHead
)
editCmd
:=
buildEditCommand
(
messageFile
)
err
:=
execCmd
(
editCmd
)
...
...
@@ -66,9 +67,26 @@ func pullRequest(cmd *Command, args []string) {
}
}
func
writePullRequestChanges
(
messageFile
string
)
{
message
:=
[]
byte
(
"
\n
#
\n
# Changes:
\n
#"
)
err
:=
ioutil
.
WriteFile
(
messageFile
,
message
,
0644
)
func
writePullRequestChanges
(
messageFile
,
base
,
head
string
)
{
message
:=
`
# Requesting a pull to %s from %s
#
# Write a message for this pull reuqest. The first block
# of the text is the title and the rest is description.
#
# Changes:
#
%s
`
startRegexp
:=
regexp
.
MustCompilePOSIX
(
"^"
)
endRegexp
:=
regexp
.
MustCompilePOSIX
(
" +$"
)
commitLogs
:=
git
.
CommitLogs
(
"master"
,
"pull_request"
)
commitLogs
=
startRegexp
.
ReplaceAllString
(
commitLogs
,
"# "
)
commitLogs
=
endRegexp
.
ReplaceAllString
(
commitLogs
,
""
)
message
=
fmt
.
Sprintf
(
message
,
base
,
head
,
commitLogs
)
err
:=
ioutil
.
WriteFile
(
messageFile
,
[]
byte
(
message
),
0644
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录