Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
9da12f4a
H
hub
项目概览
github
/
hub
大约 1 年 前同步成功
通知
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,发现更多精彩内容 >>
提交
9da12f4a
编写于
12月 02, 2013
作者:
J
Jingwen Owen Ou
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'default_msg_in_pr'
上级
412af064
9a4b7861
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
78 addition
and
23 deletion
+78
-23
commands/pull_request.go
commands/pull_request.go
+36
-18
git/git.go
git/git.go
+23
-1
git/git_test.go
git/git_test.go
+19
-4
未找到文件。
commands/pull_request.go
浏览文件 @
9da12f4a
...
@@ -126,30 +126,48 @@ func writePullRequestTitleAndBody(repo *github.Repo) (title, body string, err er
...
@@ -126,30 +126,48 @@ func writePullRequestTitleAndBody(repo *github.Repo) (title, body string, err er
}
}
func
writePullRequestChanges
(
repo
*
github
.
Repo
,
messageFile
string
)
error
{
func
writePullRequestChanges
(
repo
*
github
.
Repo
,
messageFile
string
)
error
{
message
:=
`
commits
,
err
:=
git
.
RefList
(
repo
.
Base
,
repo
.
Head
)
# Requesting a pull to %s from %s
if
err
!=
nil
{
#
return
err
# Write a message for this pull request. The first block
}
# of the text is the title and the rest is description.%s
`
var
defaultMsg
,
commitSummary
string
if
len
(
commits
)
==
1
{
defaultMsg
,
err
=
git
.
Show
(
commits
[
0
])
if
err
!=
nil
{
return
err
}
defaultMsg
=
fmt
.
Sprintf
(
"%s
\n
"
,
defaultMsg
)
}
else
if
len
(
commits
)
>
1
{
commitLogs
,
err
:=
git
.
Log
(
repo
.
Base
,
repo
.
Head
)
if
err
!=
nil
{
return
err
}
if
len
(
commitLogs
)
>
0
{
startRegexp
:=
regexp
.
MustCompilePOSIX
(
"^"
)
startRegexp
:=
regexp
.
MustCompilePOSIX
(
"^"
)
endRegexp
:=
regexp
.
MustCompilePOSIX
(
" +$"
)
endRegexp
:=
regexp
.
MustCompilePOSIX
(
" +$"
)
commitLogs
,
_
:=
git
.
Log
(
repo
.
Base
,
repo
.
Head
)
var
changesMsg
string
if
len
(
commitLogs
)
>
0
{
commitLogs
=
strings
.
TrimSpace
(
commitLogs
)
commitLogs
=
strings
.
TrimSpace
(
commitLogs
)
commitLogs
=
startRegexp
.
ReplaceAllString
(
commitLogs
,
"# "
)
commitLogs
=
startRegexp
.
ReplaceAllString
(
commitLogs
,
"# "
)
commitLogs
=
endRegexp
.
ReplaceAllString
(
commitLogs
,
""
)
commitLogs
=
endRegexp
.
ReplaceAllString
(
commitLogs
,
""
)
changesMsg
=
`
commitSummary
=
`
#
#
# Changes:
# Changes:
#
#
%s`
%s`
changesMsg
=
fmt
.
Sprintf
(
changesMsg
,
commitLogs
)
commitSummary
=
fmt
.
Sprintf
(
commitSummary
,
commitLogs
)
}
}
}
message
=
fmt
.
Sprintf
(
message
,
repo
.
FullBase
(),
repo
.
FullHead
(),
changesMsg
)
message
:=
`%s
# Requesting a pull to %s from %s
#
# Write a message for this pull request. The first block
# of the text is the title and the rest is description.%s
`
message
=
fmt
.
Sprintf
(
message
,
defaultMsg
,
repo
.
FullBase
(),
repo
.
FullHead
(),
commitSummary
)
return
ioutil
.
WriteFile
(
messageFile
,
[]
byte
(
message
),
0644
)
return
ioutil
.
WriteFile
(
messageFile
,
[]
byte
(
message
),
0644
)
}
}
...
...
git/git.go
浏览文件 @
9da12f4a
...
@@ -68,6 +68,25 @@ func Ref(ref string) (string, error) {
...
@@ -68,6 +68,25 @@ func Ref(ref string) (string, error) {
return
output
[
0
],
nil
return
output
[
0
],
nil
}
}
func
RefList
(
a
,
b
string
)
([]
string
,
error
)
{
ref
:=
fmt
.
Sprintf
(
"%s...%s"
,
a
,
b
)
output
,
err
:=
execGitCmd
(
"rev-list"
,
"--cherry-pick"
,
"--right-only"
,
"--no-merges"
,
ref
)
if
err
!=
nil
{
return
nil
,
errors
.
New
(
"Can't load rev-list for %s"
+
ref
)
}
return
output
,
nil
}
func
Show
(
sha
string
)
(
string
,
error
)
{
output
,
err
:=
execGitCmd
(
"show"
,
"-s"
,
"--format=%w(78,0,0)%s%+b"
,
sha
)
if
err
!=
nil
{
return
""
,
errors
.
New
(
"Can't show commit for %s"
+
sha
)
}
return
output
[
0
],
nil
}
func
Log
(
sha1
,
sha2
string
)
(
string
,
error
)
{
func
Log
(
sha1
,
sha2
string
)
(
string
,
error
)
{
execCmd
:=
cmd
.
New
(
"git"
)
execCmd
:=
cmd
.
New
(
"git"
)
execCmd
.
WithArg
(
"log"
)
.
WithArg
(
"--no-color"
)
execCmd
.
WithArg
(
"log"
)
.
WithArg
(
"--no-color"
)
...
@@ -111,8 +130,11 @@ func execGitCmd(input ...string) (outputs []string, err error) {
...
@@ -111,8 +130,11 @@ func execGitCmd(input ...string) (outputs []string, err error) {
out
,
err
:=
cmd
.
ExecOutput
()
out
,
err
:=
cmd
.
ExecOutput
()
for
_
,
line
:=
range
strings
.
Split
(
out
,
"
\n
"
)
{
for
_
,
line
:=
range
strings
.
Split
(
out
,
"
\n
"
)
{
line
=
strings
.
TrimSpace
(
line
)
if
line
!=
""
{
outputs
=
append
(
outputs
,
string
(
line
))
outputs
=
append
(
outputs
,
string
(
line
))
}
}
}
return
outputs
,
err
return
outputs
,
err
}
}
git/git_test.go
浏览文件 @
9da12f4a
...
@@ -35,12 +35,27 @@ func TestGitHead(t *testing.T) {
...
@@ -35,12 +35,27 @@ func TestGitHead(t *testing.T) {
}
}
func
TestGitLog
(
t
*
testing
.
T
)
{
func
TestGitLog
(
t
*
testing
.
T
)
{
logs
,
_
:=
Log
(
"master"
,
"HEAD"
)
log
,
err
:=
Log
(
"e357a98a1a580b09d4f1d9bf613a6a51e131ef6e"
,
"49e984e2fe86f68c386aeb133b390d39e4264ec1"
)
assert
.
T
(
t
,
len
(
logs
)
>=
0
)
assert
.
Equal
(
t
,
nil
,
err
)
assert
.
NotEqual
(
t
,
""
,
log
)
}
}
func
TestGitRef
(
t
*
testing
.
T
)
{
func
TestGitRef
(
t
*
testing
.
T
)
{
gitRef
,
err
:=
Ref
(
"master"
)
gitRef
,
err
:=
Ref
(
"1c1077c052d32a83aa13a8afaa4a9630d2f28ef6"
)
assert
.
Equal
(
t
,
nil
,
err
)
assert
.
Equal
(
t
,
"1c1077c052d32a83aa13a8afaa4a9630d2f28ef6"
,
gitRef
)
}
func
TestGitRefList
(
t
*
testing
.
T
)
{
refList
,
err
:=
RefList
(
"e357a98a1a580b09d4f1d9bf613a6a51e131ef6e"
,
"49e984e2fe86f68c386aeb133b390d39e4264ec1"
)
assert
.
Equal
(
t
,
nil
,
err
)
assert
.
Equal
(
t
,
1
,
len
(
refList
))
assert
.
Equal
(
t
,
"49e984e2fe86f68c386aeb133b390d39e4264ec1"
,
refList
[
0
])
}
func
TestGitShow
(
t
*
testing
.
T
)
{
output
,
err
:=
Show
(
"ce20e63ad00751bfed5d08072b11cf1b43af1995"
)
assert
.
Equal
(
t
,
nil
,
err
)
assert
.
Equal
(
t
,
nil
,
err
)
assert
.
NotEqual
(
t
,
""
,
gitRef
)
assert
.
Equal
(
t
,
"Add Git.RefList"
,
output
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录