Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
0c8302da
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,发现更多精彩内容 >>
提交
0c8302da
编写于
12月 07, 2013
作者:
J
Jingwen Owen Ou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix more cucumber failure due to `-f`
上级
6473f4d6
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
88 addition
and
12 deletion
+88
-12
commands/pull_request.go
commands/pull_request.go
+27
-12
github/branch.go
github/branch.go
+5
-0
github/branch_test.go
github/branch_test.go
+8
-0
github/project.go
github/project.go
+26
-0
github/project_test.go
github/project_test.go
+22
-0
未找到文件。
commands/pull_request.go
浏览文件 @
0c8302da
...
@@ -35,14 +35,23 @@ of title you can paste a full URL to an issue on GitHub.
...
@@ -35,14 +35,23 @@ of title you can paste a full URL to an issue on GitHub.
`
,
`
,
}
}
var
flagPullRequestBase
,
flagPullRequestHead
,
flagPullRequestIssue
,
flagPullRequestMessage
,
flagPullRequestFile
string
var
(
flagPullRequestBase
,
flagPullRequestHead
,
flagPullRequestIssue
,
flagPullRequestMessage
,
flagPullRequestFile
string
flagPullRequestForce
bool
)
func
init
()
{
func
init
()
{
cmdPullRequest
.
Flag
.
StringVar
(
&
flagPullRequestBase
,
"b"
,
""
,
"BASE"
)
cmdPullRequest
.
Flag
.
StringVar
(
&
flagPullRequestBase
,
"b"
,
""
,
"BASE"
)
cmdPullRequest
.
Flag
.
StringVar
(
&
flagPullRequestHead
,
"h"
,
""
,
"HEAD"
)
cmdPullRequest
.
Flag
.
StringVar
(
&
flagPullRequestHead
,
"h"
,
""
,
"HEAD"
)
cmdPullRequest
.
Flag
.
StringVar
(
&
flagPullRequestIssue
,
"i"
,
""
,
"ISSUE"
)
cmdPullRequest
.
Flag
.
StringVar
(
&
flagPullRequestIssue
,
"i"
,
""
,
"ISSUE"
)
cmdPullRequest
.
Flag
.
StringVar
(
&
flagPullRequestMessage
,
"m"
,
""
,
"MESSAGE"
)
cmdPullRequest
.
Flag
.
StringVar
(
&
flagPullRequestMessage
,
"m"
,
""
,
"MESSAGE"
)
cmdPullRequest
.
Flag
.
BoolVar
(
&
flagPullRequestForce
,
"f"
,
false
,
"FORCE"
)
cmdPullRequest
.
Flag
.
StringVar
(
&
flagPullRequestFile
,
"F"
,
""
,
"FILE"
)
cmdPullRequest
.
Flag
.
StringVar
(
&
flagPullRequestFile
,
"F"
,
""
,
"FILE"
)
cmdPullRequest
.
Flag
.
StringVar
(
&
flagPullRequestFile
,
"file"
,
""
,
"FILE"
)
}
}
/*
/*
...
@@ -79,14 +88,15 @@ func pullRequest(cmd *Command, args *Args) {
...
@@ -79,14 +88,15 @@ func pullRequest(cmd *Command, args *Args) {
gh
.
Project
=
baseProject
gh
.
Project
=
baseProject
var
(
var
(
base
,
head
string
base
,
head
string
explicitOwner
bool
force
,
explicitOwner
bool
)
)
force
=
flagPullRequestForce
if
flagPullRequestBase
!=
""
{
if
flagPullRequestBase
!=
""
{
if
strings
.
Contains
(
flagPullRequestBase
,
":"
)
{
if
strings
.
Contains
(
flagPullRequestBase
,
":"
)
{
split
:=
strings
.
SplitN
(
flagPullRequestBase
,
":"
,
2
)
split
:=
strings
.
SplitN
(
flagPullRequestBase
,
":"
,
2
)
base
=
split
[
1
]
base
=
split
[
1
]
baseProject
.
Owner
=
split
[
0
]
baseProject
=
github
.
NewProjectFromString
(
split
[
0
])
}
else
{
}
else
{
base
=
flagPullRequestBase
base
=
flagPullRequestBase
}
}
...
@@ -96,7 +106,7 @@ func pullRequest(cmd *Command, args *Args) {
...
@@ -96,7 +106,7 @@ func pullRequest(cmd *Command, args *Args) {
if
strings
.
Contains
(
flagPullRequestHead
,
":"
)
{
if
strings
.
Contains
(
flagPullRequestHead
,
":"
)
{
split
:=
strings
.
SplitN
(
flagPullRequestHead
,
":"
,
2
)
split
:=
strings
.
SplitN
(
flagPullRequestHead
,
":"
,
2
)
head
=
split
[
1
]
head
=
split
[
1
]
headProject
.
Owner
=
split
[
0
]
headProject
=
github
.
NewProjectFromString
(
split
[
0
])
explicitOwner
=
true
explicitOwner
=
true
}
else
{
}
else
{
head
=
flagPullRequestHead
head
=
flagPullRequestHead
...
@@ -144,7 +154,7 @@ func pullRequest(cmd *Command, args *Args) {
...
@@ -144,7 +154,7 @@ func pullRequest(cmd *Command, args *Args) {
// when no tracking, assume remote branch is published under active user's fork
// when no tracking, assume remote branch is published under active user's fork
if
tberr
!=
nil
&&
!
explicitOwner
&&
gh
.
Config
.
User
!=
headProject
.
Owner
{
if
tberr
!=
nil
&&
!
explicitOwner
&&
gh
.
Config
.
User
!=
headProject
.
Owner
{
headProject
=
github
.
NewProjectFrom
NameAndOwner
(
headProject
.
Name
,
""
)
headProject
=
github
.
NewProjectFrom
String
(
headProject
.
Name
)
}
}
var
title
,
body
string
var
title
,
body
string
...
@@ -169,8 +179,15 @@ func pullRequest(cmd *Command, args *Args) {
...
@@ -169,8 +179,15 @@ func pullRequest(cmd *Command, args *Args) {
fullBase
:=
fmt
.
Sprintf
(
"%s:%s"
,
baseProject
.
Owner
,
base
)
fullBase
:=
fmt
.
Sprintf
(
"%s:%s"
,
baseProject
.
Owner
,
base
)
fullHead
:=
fmt
.
Sprintf
(
"%s:%s"
,
headProject
.
Owner
,
head
)
fullHead
:=
fmt
.
Sprintf
(
"%s:%s"
,
headProject
.
Owner
,
head
)
commits
,
_
:=
git
.
RefList
(
base
,
head
)
if
!
force
&&
tberr
==
nil
&&
len
(
commits
)
>
0
{
err
=
fmt
.
Errorf
(
"Aborted: %d commits are not yet pushed to %s"
,
len
(
commits
),
trackedBranch
.
LongName
())
err
=
fmt
.
Errorf
(
"%s
\n
(use `-f` to force submit a pull request anyway)"
,
err
)
utils
.
Check
(
err
)
}
if
title
==
""
&&
flagPullRequestIssue
==
""
{
if
title
==
""
&&
flagPullRequestIssue
==
""
{
t
,
b
,
err
:=
writePullRequestTitleAndBody
(
base
,
head
,
fullBase
,
fullHead
)
t
,
b
,
err
:=
writePullRequestTitleAndBody
(
base
,
head
,
fullBase
,
fullHead
,
commits
)
utils
.
Check
(
err
)
utils
.
Check
(
err
)
title
=
t
title
=
t
body
=
b
body
=
b
...
@@ -201,14 +218,14 @@ func pullRequest(cmd *Command, args *Args) {
...
@@ -201,14 +218,14 @@ func pullRequest(cmd *Command, args *Args) {
args
.
Replace
(
"echo"
,
""
,
pullRequestURL
)
args
.
Replace
(
"echo"
,
""
,
pullRequestURL
)
}
}
func
writePullRequestTitleAndBody
(
base
,
head
,
fullBase
,
fullHead
string
)
(
title
,
body
string
,
err
error
)
{
func
writePullRequestTitleAndBody
(
base
,
head
,
fullBase
,
fullHead
string
,
commits
[]
string
)
(
title
,
body
string
,
err
error
)
{
messageFile
,
err
:=
git
.
PullReqMsgFile
()
messageFile
,
err
:=
git
.
PullReqMsgFile
()
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
defer
os
.
Remove
(
messageFile
)
defer
os
.
Remove
(
messageFile
)
err
=
writePullRequestChanges
(
base
,
head
,
fullBase
,
fullHead
,
messageFile
)
err
=
writePullRequestChanges
(
base
,
head
,
fullBase
,
fullHead
,
commits
,
messageFile
)
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
...
@@ -232,9 +249,7 @@ func writePullRequestTitleAndBody(base, head, fullBase, fullHead string) (title,
...
@@ -232,9 +249,7 @@ func writePullRequestTitleAndBody(base, head, fullBase, fullHead string) (title,
return
return
}
}
func
writePullRequestChanges
(
base
,
head
,
fullBase
,
fullHead
string
,
messageFile
string
)
error
{
func
writePullRequestChanges
(
base
,
head
,
fullBase
,
fullHead
string
,
commits
[]
string
,
messageFile
string
)
error
{
commits
,
_
:=
git
.
RefList
(
base
,
head
)
var
defaultMsg
,
commitSummary
string
var
defaultMsg
,
commitSummary
string
if
len
(
commits
)
==
1
{
if
len
(
commits
)
==
1
{
defaultMsg
,
err
:=
git
.
Show
(
commits
[
0
])
defaultMsg
,
err
:=
git
.
Show
(
commits
[
0
])
...
...
github/branch.go
浏览文件 @
0c8302da
...
@@ -14,6 +14,11 @@ func (b Branch) ShortName() string {
...
@@ -14,6 +14,11 @@ func (b Branch) ShortName() string {
return
reg
.
ReplaceAllString
(
string
(
b
),
""
)
return
reg
.
ReplaceAllString
(
string
(
b
),
""
)
}
}
func
(
b
Branch
)
LongName
()
string
{
reg
:=
regexp
.
MustCompile
(
"refs/(remotes/)?"
)
return
reg
.
ReplaceAllString
(
string
(
b
),
""
)
}
func
(
b
Branch
)
Upstream
()
(
u
Branch
,
err
error
)
{
func
(
b
Branch
)
Upstream
()
(
u
Branch
,
err
error
)
{
name
,
err
:=
git
.
SymbolicFullName
(
fmt
.
Sprintf
(
"%s@{upstream}"
,
b
.
ShortName
()))
name
,
err
:=
git
.
SymbolicFullName
(
fmt
.
Sprintf
(
"%s@{upstream}"
,
b
.
ShortName
()))
if
err
!=
nil
{
if
err
!=
nil
{
...
...
github/branch_test.go
浏览文件 @
0c8302da
...
@@ -10,6 +10,14 @@ func TestBranch_ShortName(t *testing.T) {
...
@@ -10,6 +10,14 @@ func TestBranch_ShortName(t *testing.T) {
assert
.
Equal
(
t
,
"master"
,
b
.
ShortName
())
assert
.
Equal
(
t
,
"master"
,
b
.
ShortName
())
}
}
func
TestBranch_LongName
(
t
*
testing
.
T
)
{
b
:=
Branch
(
"refs/heads/master"
)
assert
.
Equal
(
t
,
"heads/master"
,
b
.
LongName
())
b
=
Branch
(
"refs/remotes/origin/master"
)
assert
.
Equal
(
t
,
"origin/master"
,
b
.
LongName
())
}
func
TestBranch_RemoveName
(
t
*
testing
.
T
)
{
func
TestBranch_RemoveName
(
t
*
testing
.
T
)
{
b
:=
Branch
(
"refs/remotes/origin/master"
)
b
:=
Branch
(
"refs/remotes/origin/master"
)
assert
.
Equal
(
t
,
"origin"
,
b
.
RemoteName
())
assert
.
Equal
(
t
,
"origin"
,
b
.
RemoteName
())
...
...
github/project.go
浏览文件 @
0c8302da
...
@@ -95,6 +95,32 @@ func NewProjectFromURL(url *url.URL) (*Project, error) {
...
@@ -95,6 +95,32 @@ func NewProjectFromURL(url *url.URL) (*Project, error) {
return
&
Project
{
Name
:
name
,
Owner
:
parts
[
1
]},
nil
return
&
Project
{
Name
:
name
,
Owner
:
parts
[
1
]},
nil
}
}
// NewProjectFromURL creates a new Project from a string
//
// If the string is in the format of OWNER/NAME, it's split and used as the owner and name of the Project.
// Otherwise the string is used as the name of the Project and the current user is used as the owner.
// If the string is empty, the current dir name is used as the name of the Project.
func
NewProjectFromString
(
nameAndOwner
string
)
*
Project
{
var
name
,
owner
string
if
strings
.
Contains
(
nameAndOwner
,
"/"
)
{
result
:=
strings
.
SplitN
(
nameAndOwner
,
"/"
,
2
)
owner
=
result
[
0
]
name
=
result
[
1
]
}
else
{
name
=
nameAndOwner
}
if
owner
==
""
{
owner
=
CurrentConfig
()
.
FetchUser
()
}
if
name
==
""
{
name
,
_
=
utils
.
DirName
()
}
return
&
Project
{
Name
:
name
,
Owner
:
owner
}
}
func
NewProjectFromNameAndOwner
(
name
,
owner
string
)
*
Project
{
func
NewProjectFromNameAndOwner
(
name
,
owner
string
)
*
Project
{
if
strings
.
Contains
(
owner
,
"/"
)
{
if
strings
.
Contains
(
owner
,
"/"
)
{
result
:=
strings
.
SplitN
(
owner
,
"/"
,
2
)
result
:=
strings
.
SplitN
(
owner
,
"/"
,
2
)
...
...
github/project_test.go
浏览文件 @
0c8302da
...
@@ -30,6 +30,28 @@ func TestNewProjectOwnerAndName(t *testing.T) {
...
@@ -30,6 +30,28 @@ func TestNewProjectOwnerAndName(t *testing.T) {
assert
.
Equal
(
t
,
"gh/foo"
,
project
.
Name
)
assert
.
Equal
(
t
,
"gh/foo"
,
project
.
Name
)
}
}
func
TestNewProjectFromString
(
t
*
testing
.
T
)
{
DefaultConfigFile
=
"./test_support/clone_gh"
config
:=
Config
{
User
:
"jingweno"
,
Token
:
"123"
}
SaveConfig
(
&
config
)
defer
os
.
RemoveAll
(
filepath
.
Dir
(
DefaultConfigFile
))
project
:=
NewProjectFromString
(
"jingweno/gh"
)
assert
.
Equal
(
t
,
"jingweno"
,
project
.
Owner
)
assert
.
Equal
(
t
,
"gh"
,
project
.
Name
)
project
=
NewProjectFromString
(
"gh"
)
assert
.
Equal
(
t
,
"jingweno"
,
project
.
Owner
)
assert
.
Equal
(
t
,
"gh"
,
project
.
Name
)
project
=
NewProjectFromString
(
"jingweno/gh/foo"
)
assert
.
Equal
(
t
,
"jingweno"
,
project
.
Owner
)
assert
.
Equal
(
t
,
"gh/foo"
,
project
.
Name
)
}
func
TestWebURL
(
t
*
testing
.
T
)
{
func
TestWebURL
(
t
*
testing
.
T
)
{
project
:=
Project
{
"foo"
,
"bar"
}
project
:=
Project
{
"foo"
,
"bar"
}
url
:=
project
.
WebURL
(
""
,
""
,
"baz"
)
url
:=
project
.
WebURL
(
""
,
""
,
"baz"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录