Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
2157ad1d
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,发现更多精彩内容 >>
提交
2157ad1d
编写于
8月 20, 2016
作者:
M
Mislav Marohnić
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reimplement `github.PullRequest()` using `simpleApi`
上级
90a3a539
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
35 addition
and
19 deletion
+35
-19
github/client.go
github/client.go
+31
-19
github/http.go
github/http.go
+4
-0
未找到文件。
github/client.go
浏览文件 @
2157ad1d
...
@@ -52,23 +52,19 @@ type Client struct {
...
@@ -52,23 +52,19 @@ type Client struct {
Host
*
Host
Host
*
Host
}
}
func
(
client
*
Client
)
PullRequest
(
project
*
Project
,
id
string
)
(
pr
*
octokit
.
PullRequest
,
err
error
)
{
func
(
client
*
Client
)
PullRequest
(
project
*
Project
,
id
string
)
(
pr
*
PullRequest
,
err
error
)
{
url
,
err
:=
octokit
.
PullRequestsURL
.
Expand
(
octokit
.
M
{
"owner"
:
project
.
Owner
,
"repo"
:
project
.
Name
,
"number"
:
id
}
)
api
,
err
:=
client
.
simpleApi
(
)
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
api
,
err
:=
client
.
api
()
res
,
err
:=
api
.
Get
(
fmt
.
Sprintf
(
"repos/%s/%s/pulls/%s"
,
project
.
Owner
,
project
.
Name
,
id
))
if
err
!=
nil
{
if
err
=
checkStatus
(
200
,
"getting pull request"
,
res
,
err
);
err
!=
nil
{
err
=
FormatError
(
"getting pull request"
,
err
)
return
return
}
}
pr
,
result
:=
api
.
PullRequests
(
client
.
requestURL
(
url
))
.
One
()
pr
=
&
PullRequest
{}
if
result
.
HasError
()
{
err
=
res
.
Unmarshal
(
pr
)
err
=
FormatError
(
"getting pull request"
,
result
.
Err
)
return
}
return
return
}
}
...
@@ -95,9 +91,19 @@ func (client *Client) PullRequestPatch(project *Project, id string) (patch io.Re
...
@@ -95,9 +91,19 @@ func (client *Client) PullRequestPatch(project *Project, id string) (patch io.Re
}
}
type
PullRequest
struct
{
type
PullRequest
struct
{
ApiUrl
string
`json:"url"`
ApiUrl
string
`json:"url"`
Number
int
`json:"number"`
Number
int
`json:"number"`
HtmlUrl
string
`json:"html_url"`
HtmlUrl
string
`json:"html_url"`
Title
string
`json:"title"`
Head
*
PullRequestSpec
`json:"head"`
Base
*
PullRequestSpec
`json:"base"`
}
type
PullRequestSpec
struct
{
Label
string
`json:"label"`
Ref
string
`json:"ref"`
Sha
string
`json:"sha"`
Repo
*
Repository
`json:"repo"`
}
}
func
(
client
*
Client
)
CreatePullRequest
(
project
*
Project
,
params
map
[
string
]
interface
{})
(
pr
*
PullRequest
,
err
error
)
{
func
(
client
*
Client
)
CreatePullRequest
(
project
*
Project
,
params
map
[
string
]
interface
{})
(
pr
*
PullRequest
,
err
error
)
{
...
@@ -391,13 +397,19 @@ func (client *Client) FetchCIStatus(project *Project, sha string) (status *CISta
...
@@ -391,13 +397,19 @@ func (client *Client) FetchCIStatus(project *Project, sha string) (status *CISta
return
return
}
}
type
RepositoryOwner
struct
{
Login
string
`json:"login"`
}
type
Repository
struct
{
type
Repository
struct
{
Name
string
`json:"name"`
Name
string
`json:"name"`
Parent
*
Repository
`json:"parent"`
Parent
*
Repository
`json:"parent"`
Owner
*
RepositoryOwner
`json:"owner"`
Owner
*
User
`json:"owner"`
Private
bool
`json:"private"`
Permissions
*
RepositoryPermissions
`json:"permissions"`
HtmlUrl
string
`json:"html_url"`
}
type
RepositoryPermissions
struct
{
Admin
bool
`json:"admin"`
Push
bool
`json:"push"`
Pull
bool
`json:"pull"`
}
}
func
(
client
*
Client
)
ForkRepository
(
project
*
Project
)
(
repo
*
Repository
,
err
error
)
{
func
(
client
*
Client
)
ForkRepository
(
project
*
Project
)
(
repo
*
Repository
,
err
error
)
{
...
...
github/http.go
浏览文件 @
2157ad1d
...
@@ -18,6 +18,8 @@ import (
...
@@ -18,6 +18,8 @@ import (
"github.com/github/hub/utils"
"github.com/github/hub/utils"
)
)
const
apiPayloadVersion
=
"application/vnd.github.v3+json;charset=utf-8"
type
verboseTransport
struct
{
type
verboseTransport
struct
{
Transport
*
http
.
Transport
Transport
*
http
.
Transport
Verbose
bool
Verbose
bool
...
@@ -213,6 +215,8 @@ func (c *simpleClient) performRequestUrl(method string, url *url.URL, body io.Re
...
@@ -213,6 +215,8 @@ func (c *simpleClient) performRequestUrl(method string, url *url.URL, body io.Re
}
}
req
.
Header
.
Set
(
"Authorization"
,
"token "
+
c
.
accessToken
)
req
.
Header
.
Set
(
"Authorization"
,
"token "
+
c
.
accessToken
)
req
.
Header
.
Set
(
"User-Agent"
,
UserAgent
)
req
.
Header
.
Set
(
"User-Agent"
,
UserAgent
)
req
.
Header
.
Set
(
"Accept"
,
apiPayloadVersion
)
if
configure
!=
nil
{
if
configure
!=
nil
{
configure
(
req
)
configure
(
req
)
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录