forked from orktes/captainhub
/
github.go
63 lines (52 loc) · 1.66 KB
/
github.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import "github.com/orktes/captainhub/Godeps/_workspace/src/github.com/google/go-github/github"
func createPullRequestComment(owner string, repo string, prNumber int, body string) (err error) {
client := getGithubClient()
_, _, err = client.PullRequests.CreateComment(owner, repo, prNumber, &github.PullRequestComment{
Body: &body,
})
return
}
func createStatus(owner string, repo string, sha string, state string, targetURL string, description string, context string) (err error) {
client := getGithubClient()
_, _, err = client.Repositories.CreateStatus(owner, repo, sha, &github.RepoStatus{
State: &state,
TargetURL: &targetURL,
Description: &description,
Context: &context,
})
return
}
func createIssueComment(owner string, repo string, issueNumber int, body string) (err error) {
client := getGithubClient()
_, _, err = client.Issues.CreateComment(owner, repo, issueNumber, &github.IssueComment{
Body: &body,
})
return
}
func getPullRequestDetails(owner string, repo string, prNumber int) (pullRequest *github.PullRequest, err error) {
client := getGithubClient()
pullRequest, _, err = client.PullRequests.Get(owner, repo, prNumber)
return
}
func listPullRequestFiles(owner string, repo string, prNumber int) (allFiles []github.CommitFile, err error) {
client := getGithubClient()
opts := &github.ListOptions{PerPage: 10}
var resp *github.Response
var files []github.CommitFile
for {
files, resp, err = client.PullRequests.ListFiles(
owner,
repo,
prNumber, opts)
if err != nil {
return
}
allFiles = append(allFiles, files...)
if resp.NextPage == 0 {
break
}
opts.Page = resp.NextPage
}
return
}