/
create.go
58 lines (52 loc) · 1.54 KB
/
create.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
package lib
import (
"log"
"github.com/google/go-github/github"
)
// CreateComment will create a comment on the pull request
func CreateComment(token, owner, repository, body string, bid int) {
// create comment on pull request
comment := &github.PullRequestComment{
Body: github.String(body),
}
_, _, err := client.PullRequests.CreateComment(ctx, owner, repository, bid, comment)
if err != nil {
log.Fatal(err)
}
}
// CreateReview will create a review on the pull request
func CreateReview(token, owner, repository, body string, bid int) (bool, error) {
//create review comment on pull request
review := &github.PullRequestReviewRequest{
Body: github.String(body),
Event: github.String("COMMENT"),
}
client.PullRequests.CreateReview(ctx, owner, repository, bid, review)
return true, nil
}
// CreateIssue will create an issue in a repository
func CreateIssue(owner, repository, title, body string) {
// create issue
issue := &github.IssueRequest{
Title: github.String(title),
Body: github.String(body),
}
_, _, err := client.Issues.Create(ctx, owner, repository, issue)
if err != nil {
log.Fatal(err)
}
}
// CreatePullRequest will create a pull request in a repository
func CreatePullRequest(owner, repository, title, body, head, base string) {
// create pull request
pr := &github.NewPullRequest{
Title: github.String(title),
Body: github.String(body),
Head: github.String(head),
Base: github.String(base),
}
_, _, err := client.PullRequests.Create(ctx, owner, repository, pr)
if err != nil {
log.Fatal(err)
}
}