Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
32e57d23
H
hub
项目概览
github
/
hub
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
32e57d23
编写于
11月 06, 2013
作者:
J
Jingwen Owen Ou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change pull request API to use octokit
上级
9ae43f29
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
50 addition
and
29 deletion
+50
-29
commands/checkout.go
commands/checkout.go
+2
-2
commands/merge.go
commands/merge.go
+2
-2
commands/merge_test.go
commands/merge_test.go
+5
-5
commands/utils.go
commands/utils.go
+3
-3
github/github.go
github/github.go
+38
-17
未找到文件。
commands/checkout.go
浏览文件 @
32e57d23
...
...
@@ -3,7 +3,7 @@ package commands
import
(
"fmt"
"github.com/jingweno/gh/utils"
"github.com/
jingweno/octoka
t"
"github.com/
octokit/go-octoki
t"
)
var
cmdCheckout
=
&
Command
{
...
...
@@ -46,7 +46,7 @@ func transformCheckoutArgs(args *Args) error {
return
nil
}
func
buildArgsFromPullRequest
(
args
*
Args
,
pullRequest
*
octok
a
t
.
PullRequest
)
error
{
func
buildArgsFromPullRequest
(
args
*
Args
,
pullRequest
*
octok
i
t
.
PullRequest
)
error
{
user
,
branch
:=
parseUserBranchFromPR
(
pullRequest
)
args
.
RemoveParam
(
0
)
// Remove the pull request URL
...
...
commands/merge.go
浏览文件 @
32e57d23
...
...
@@ -3,7 +3,7 @@ package commands
import
(
"fmt"
"github.com/jingweno/gh/utils"
"github.com/
jingweno/octoka
t"
"github.com/
octokit/go-octoki
t"
)
var
cmdMerge
=
&
Command
{
...
...
@@ -45,7 +45,7 @@ func transformMergeArgs(args *Args) error {
return
nil
}
func
fetchAndMerge
(
args
*
Args
,
pullRequest
*
octok
a
t
.
PullRequest
)
error
{
func
fetchAndMerge
(
args
*
Args
,
pullRequest
*
octok
i
t
.
PullRequest
)
error
{
user
,
branch
:=
parseUserBranchFromPR
(
pullRequest
)
url
,
err
:=
convertToGitURL
(
pullRequest
.
HTMLURL
,
user
,
pullRequest
.
Head
.
Repo
.
Private
)
if
err
!=
nil
{
...
...
commands/merge_test.go
浏览文件 @
32e57d23
...
...
@@ -2,7 +2,7 @@ package commands
import
(
"github.com/bmizerany/assert"
"github.com/
jingweno/octoka
t"
"github.com/
octokit/go-octoki
t"
"testing"
)
...
...
@@ -14,15 +14,15 @@ func TestFetchAndMerge(t *testing.T) {
args
:=
NewArgs
([]
string
{
"merge"
,
url
})
userLogin
:=
"jingweno"
user
:=
octok
a
t
.
User
{
Login
:
userLogin
}
user
:=
octok
i
t
.
User
{
Login
:
userLogin
}
repoPrivate
:=
true
repo
:=
octok
a
t
.
Repository
{
Private
:
repoPrivate
}
repo
:=
octok
i
t
.
Repository
{
Private
:
repoPrivate
}
headRef
:=
"new-feature"
head
:=
octok
a
t
.
Commit
{
Ref
:
headRef
,
Repo
:
repo
,
Label
:
"jingweno:new-feature"
}
head
:=
octok
i
t
.
Commit
{
Ref
:
headRef
,
Repo
:
repo
,
Label
:
"jingweno:new-feature"
}
pullRequest
:=
octok
a
t
.
PullRequest
{
Number
:
number
,
Title
:
title
,
HTMLURL
:
url
,
User
:
user
,
Head
:
head
}
pullRequest
:=
octok
i
t
.
PullRequest
{
Number
:
number
,
Title
:
title
,
HTMLURL
:
url
,
User
:
user
,
Head
:
head
}
err
:=
fetchAndMerge
(
args
,
&
pullRequest
)
assert
.
Equal
(
t
,
nil
,
err
)
...
...
commands/utils.go
浏览文件 @
32e57d23
...
...
@@ -5,7 +5,7 @@ import (
"github.com/jingweno/gh/git"
"github.com/jingweno/gh/github"
"github.com/jingweno/gh/utils"
"github.com/
jingweno/octoka
t"
"github.com/
octokit/go-octoki
t"
"os"
"regexp"
"strings"
...
...
@@ -41,7 +41,7 @@ func parsePullRequestId(rawurl string) (id string) {
return
}
func
fetchPullRequest
(
id
string
)
(
*
octok
a
t
.
PullRequest
,
error
)
{
func
fetchPullRequest
(
id
string
)
(
*
octok
i
t
.
PullRequest
,
error
)
{
gh
:=
github
.
New
()
pullRequest
,
err
:=
gh
.
PullRequest
(
id
)
if
err
!=
nil
{
...
...
@@ -65,7 +65,7 @@ func convertToGitURL(pullRequestURL, user string, isSSH bool) (string, error) {
return
url
.
GitURL
(
""
,
user
,
isSSH
),
nil
}
func
parseUserBranchFromPR
(
pullRequest
*
octok
a
t
.
PullRequest
)
(
user
string
,
branch
string
)
{
func
parseUserBranchFromPR
(
pullRequest
*
octok
i
t
.
PullRequest
)
(
user
string
,
branch
string
)
{
userBranch
:=
strings
.
SplitN
(
pullRequest
.
Head
.
Label
,
":"
,
2
)
user
=
userBranch
[
0
]
if
len
(
userBranch
)
>
1
{
...
...
github/github.go
浏览文件 @
32e57d23
...
...
@@ -16,34 +16,55 @@ type GitHub struct {
Config
*
Config
}
func
(
gh
*
GitHub
)
PullRequest
(
id
string
)
(
*
octokat
.
PullRequest
,
error
)
{
client
:=
gh
.
client
()
func
(
gh
*
GitHub
)
PullRequest
(
id
string
)
(
pr
*
octokit
.
PullRequest
,
err
error
)
{
client
:=
gh
.
octokit
()
prService
,
err
:=
client
.
PullRequests
(
&
octokit
.
PullRequestsURL
,
octokit
.
M
{
"owner"
:
gh
.
Project
.
Owner
,
"repo"
:
gh
.
Project
.
Name
,
"number"
:
id
})
if
err
!=
nil
{
return
}
return
client
.
PullRequest
(
gh
.
repo
(),
id
,
nil
)
pr
,
result
:=
prService
.
Get
()
if
result
.
HasError
()
{
err
=
result
.
Err
}
return
}
func
(
gh
*
GitHub
)
CreatePullRequest
(
base
,
head
,
title
,
body
string
)
(
string
,
error
)
{
client
:=
gh
.
client
()
params
:=
octokat
.
PullRequestParams
{
Base
:
base
,
Head
:
head
,
Title
:
title
,
Body
:
body
}
options
:=
octokat
.
Options
{
Params
:
params
}
pullRequest
,
err
:=
client
.
CreatePullRequest
(
gh
.
repo
(),
&
options
)
func
(
gh
*
GitHub
)
CreatePullRequest
(
base
,
head
,
title
,
body
string
)
(
url
string
,
err
error
)
{
client
:=
gh
.
octokit
()
prService
,
err
:=
client
.
PullRequests
(
&
octokit
.
PullRequestsURL
,
octokit
.
M
{
"owner"
:
gh
.
Project
.
Owner
,
"repo"
:
gh
.
Project
.
Name
})
if
err
!=
nil
{
return
""
,
err
return
}
params
:=
octokit
.
PullRequestParams
{
Base
:
base
,
Head
:
head
,
Title
:
title
,
Body
:
body
}
pr
,
result
:=
prService
.
Create
(
params
)
if
result
.
HasError
()
{
err
=
result
.
Err
}
return
pullRequest
.
HTMLURL
,
nil
url
=
pr
.
HTMLURL
return
}
func
(
gh
*
GitHub
)
CreatePullRequestForIssue
(
base
,
head
,
issue
string
)
(
string
,
error
)
{
client
:=
gh
.
client
()
params
:=
octokat
.
PullRequestForIssueParams
{
Base
:
base
,
Head
:
head
,
Issue
:
issue
}
options
:=
octokat
.
Options
{
Params
:
params
}
pullRequest
,
err
:=
client
.
CreatePullRequest
(
gh
.
repo
(),
&
options
)
func
(
gh
*
GitHub
)
CreatePullRequestForIssue
(
base
,
head
,
issue
string
)
(
url
string
,
err
error
)
{
client
:=
gh
.
octokit
()
prService
,
err
:=
client
.
PullRequests
(
&
octokit
.
PullRequestsURL
,
octokit
.
M
{
"owner"
:
gh
.
Project
.
Owner
,
"repo"
:
gh
.
Project
.
Name
})
if
err
!=
nil
{
return
""
,
err
return
}
return
pullRequest
.
HTMLURL
,
nil
params
:=
octokit
.
PullRequestForIssueParams
{
Base
:
base
,
Head
:
head
,
Issue
:
issue
}
pr
,
result
:=
prService
.
Create
(
params
)
if
result
.
HasError
()
{
err
=
result
.
Err
}
url
=
pr
.
HTMLURL
return
}
func
(
gh
*
GitHub
)
Repository
(
project
Project
)
(
repo
*
octokit
.
Repository
,
err
error
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录