Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
b3468238
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,发现更多精彩内容 >>
提交
b3468238
编写于
2月 23, 2014
作者:
J
Jingwen Owen Ou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Warn existence of URL
上级
146516d3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
63 addition
and
14 deletion
+63
-14
commands/pull_request.go
commands/pull_request.go
+11
-8
github/client.go
github/client.go
+23
-1
github/client_test.go
github/client_test.go
+29
-5
未找到文件。
commands/pull_request.go
浏览文件 @
b3468238
...
...
@@ -9,6 +9,7 @@ import (
"github.com/github/hub/git"
"github.com/github/hub/github"
"github.com/github/hub/utils"
"github.com/octokit/go-octokit/octokit"
)
var
cmdPullRequest
=
&
Command
{
...
...
@@ -163,17 +164,19 @@ func pullRequest(cmd *Command, args *Args) {
args
.
Before
(
fmt
.
Sprintf
(
"Would request a pull request to %s from %s"
,
fullBase
,
fullHead
),
""
)
pullRequestURL
=
"PULL_REQUEST_URL"
}
else
{
var
(
pr
*
octokit
.
PullRequest
err
error
)
if
title
!=
""
{
pr
,
err
:
=
client
.
CreatePullRequest
(
baseProject
,
base
,
fullHead
,
title
,
body
)
utils
.
Check
(
err
)
p
ullRequestURL
=
pr
.
HTMLURL
pr
,
err
=
client
.
CreatePullRequest
(
baseProject
,
base
,
fullHead
,
title
,
body
)
}
else
if
flagPullRequestIssue
!=
""
{
p
r
,
err
=
client
.
CreatePullRequestForIssue
(
baseProject
,
base
,
fullHead
,
flagPullRequestIssue
)
}
if
flagPullRequestIssue
!=
""
{
pr
,
err
:=
client
.
CreatePullRequestForIssue
(
baseProject
,
base
,
fullHead
,
flagPullRequestIssue
)
utils
.
Check
(
err
)
pullRequestURL
=
pr
.
HTMLURL
}
utils
.
Check
(
err
)
pullRequestURL
=
pr
.
HTMLURL
}
args
.
Replace
(
"echo"
,
""
,
pullRequestURL
)
...
...
github/client.go
浏览文件 @
b3468238
...
...
@@ -63,6 +63,10 @@ func (client *Client) CreatePullRequest(project *Project, base, head, title, bod
pr
,
result
:=
client
.
octokit
()
.
PullRequests
(
client
.
requestURL
(
url
))
.
Create
(
params
)
if
result
.
HasError
()
{
err
=
formatError
(
"creating pull request"
,
result
)
if
e
:=
warnExistenceOfRepo
(
project
,
result
);
e
!=
nil
{
err
=
fmt
.
Errorf
(
"%s
\n
%s"
,
err
,
e
)
}
return
}
...
...
@@ -79,6 +83,10 @@ func (client *Client) CreatePullRequestForIssue(project *Project, base, head, is
pr
,
result
:=
client
.
octokit
()
.
PullRequests
(
client
.
requestURL
(
url
))
.
Create
(
params
)
if
result
.
HasError
()
{
err
=
formatError
(
"creating pull request"
,
result
)
if
e
:=
warnExistenceOfRepo
(
project
,
result
);
e
!=
nil
{
err
=
fmt
.
Errorf
(
"%s
\n
%s"
,
err
,
e
)
}
return
}
...
...
@@ -380,7 +388,7 @@ func formatError(action string, result *octokit.Result) error {
statusCode
:=
e
.
Response
.
StatusCode
var
reason
string
if
s
:=
strings
.
SplitN
(
e
.
Response
.
Status
,
" "
,
2
);
len
(
s
)
>=
2
{
reason
=
s
[
1
]
reason
=
s
trings
.
TrimSpace
(
s
[
1
])
}
errStr
:=
fmt
.
Sprintf
(
"Error %s: %s (HTTP %d)"
,
action
,
reason
,
statusCode
)
...
...
@@ -407,3 +415,17 @@ func formatError(action string, result *octokit.Result) error {
return
result
.
Err
}
func
warnExistenceOfRepo
(
project
*
Project
,
result
*
octokit
.
Result
)
(
err
error
)
{
if
e
,
ok
:=
result
.
Err
.
(
*
octokit
.
ResponseError
);
ok
&&
e
.
Response
.
StatusCode
==
404
{
var
url
string
if
s
:=
strings
.
SplitN
(
project
.
WebURL
(
""
,
""
,
""
),
"://"
,
2
);
len
(
s
)
>=
2
{
url
=
s
[
1
]
}
if
url
!=
""
{
err
=
fmt
.
Errorf
(
"Are you sure that %s exists?"
,
url
)
}
}
return
}
github/client_test.go
浏览文件 @
b3468238
...
...
@@ -22,21 +22,45 @@ func TestClient_ApiEndpoint(t *testing.T) {
func
TestClient_formatError
(
t
*
testing
.
T
)
{
result
:=
&
octokit
.
Result
{
Response
:
&
octokit
.
Response
{
Response
:
&
http
.
Response
{
StatusCode
:
401
,
Status
:
"401 Not Found"
},
Err
:
&
octokit
.
ResponseError
{
Response
:
&
http
.
Response
{
StatusCode
:
401
,
Status
:
"401 Not Found"
,
},
},
}
err
:=
formatError
(
"action"
,
result
)
assert
.
Equal
(
t
,
"Error action: Not Found (HTTP 401)"
,
fmt
.
Sprintf
(
"%s"
,
err
))
result
=
&
octokit
.
Result
{
Response
:
&
octokit
.
Response
{
Response
:
&
http
.
Response
{
StatusCode
:
422
,
Status
:
"422 Unprocessable Entity"
},
},
Err
:
&
octokit
.
ResponseError
{
Response
:
&
http
.
Response
{
StatusCode
:
422
,
Status
:
"422 Unprocessable Entity"
,
},
Message
:
"error message"
,
},
}
err
=
formatError
(
"action"
,
result
)
assert
.
Equal
(
t
,
"Error action: Unprocessable Entity (HTTP 422)
\n
error message"
,
fmt
.
Sprintf
(
"%s"
,
err
))
}
func
TestClient_warnExistenceOfRepo
(
t
*
testing
.
T
)
{
project
:=
&
Project
{
Name
:
"hub"
,
Owner
:
"github"
,
Host
:
"github.com"
,
}
result
:=
&
octokit
.
Result
{
Err
:
&
octokit
.
ResponseError
{
Response
:
&
http
.
Response
{
StatusCode
:
404
,
Status
:
"404 Not Found"
,
},
Message
:
"error message"
,
},
}
err
:=
warnExistenceOfRepo
(
project
,
result
)
assert
.
Equal
(
t
,
"Are you sure that github.com/github/hub exists?"
,
fmt
.
Sprintf
(
"%s"
,
err
))
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录