/
github.go
51 lines (42 loc) · 1.13 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
package git
import (
"context"
"fmt"
"github.com/google/go-github/github"
)
type GithubPR struct {
RepoURL string
Username string
Password string
}
func NewGithubPR(repoURL, username, password string) *GithubPR {
return &GithubPR{
RepoURL: repoURL,
Username: username,
Password: password,
}
}
// CreatePR creates a pull request for the specified branch
func (pr *GithubPR) CreatePR(tag, branch string) error {
tp := github.BasicAuthTransport{
Username: pr.Username,
Password: pr.Password,
}
client := github.NewClient(tp.Client())
newPR := &github.NewPullRequest{
Title: github.String(fmt.Sprintf("Release Candidate: %s", tag)),
Head: github.String(branch),
Base: github.String("master"),
Body: github.String(fmt.Sprintf("If you want to deploy version %s, please merge this PR", tag)),
MaintainerCanModify: github.Bool(true),
}
repoURL, err := parseRepoURL(pr.RepoURL)
if err != nil {
return err
}
_, _, err = client.PullRequests.Create(context.Background(), repoURL.Owner, repoURL.RepoName, newPR)
if err != nil {
return err
}
return nil
}