提交 2157ad1d 编写于 作者: M Mislav Marohnić

Reimplement `github.PullRequest()` using `simpleApi`

上级 90a3a539
......@@ -52,23 +52,19 @@ type Client struct {
Host *Host
}
func (client *Client) PullRequest(project *Project, id string) (pr *octokit.PullRequest, err error) {
url, err := octokit.PullRequestsURL.Expand(octokit.M{"owner": project.Owner, "repo": project.Name, "number": id})
func (client *Client) PullRequest(project *Project, id string) (pr *PullRequest, err error) {
api, err := client.simpleApi()
if err != nil {
return
}
api, err := client.api()
if err != nil {
err = FormatError("getting pull request", err)
res, err := api.Get(fmt.Sprintf("repos/%s/%s/pulls/%s", project.Owner, project.Name, id))
if err = checkStatus(200, "getting pull request", res, err); err != nil {
return
}
pr, result := api.PullRequests(client.requestURL(url)).One()
if result.HasError() {
err = FormatError("getting pull request", result.Err)
return
}
pr = &PullRequest{}
err = res.Unmarshal(pr)
return
}
......@@ -95,9 +91,19 @@ func (client *Client) PullRequestPatch(project *Project, id string) (patch io.Re
}
type PullRequest struct {
ApiUrl string `json:"url"`
Number int `json:"number"`
HtmlUrl string `json:"html_url"`
ApiUrl string `json:"url"`
Number int `json:"number"`
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) {
......@@ -391,13 +397,19 @@ func (client *Client) FetchCIStatus(project *Project, sha string) (status *CISta
return
}
type RepositoryOwner struct {
Login string `json:"login"`
}
type Repository struct {
Name string `json:"name"`
Parent *Repository `json:"parent"`
Owner *RepositoryOwner `json:"owner"`
Name string `json:"name"`
Parent *Repository `json:"parent"`
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) {
......
......@@ -18,6 +18,8 @@ import (
"github.com/github/hub/utils"
)
const apiPayloadVersion = "application/vnd.github.v3+json;charset=utf-8"
type verboseTransport struct {
Transport *http.Transport
Verbose bool
......@@ -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("User-Agent", UserAgent)
req.Header.Set("Accept", apiPayloadVersion)
if configure != nil {
configure(req)
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册