forked from dionomusuko/gh-release-with-wf-dispatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.go
37 lines (32 loc) · 876 Bytes
/
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
package main
import (
"context"
"log"
"github.com/google/go-github/github"
"golang.org/x/oauth2"
)
type ghClient struct {
client *github.Client
}
func newGHClient(token string) *ghClient {
ctx := context.Background()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
)
tc := oauth2.NewClient(ctx, ts)
client := github.NewClient(tc)
return &ghClient{
client: client,
}
}
func (g *ghClient) newPullRequest(ctx context.Context, newTag, baseBranch, repo, owner, branchName string) {
pr := &github.NewPullRequest{
Title: github.String("chore: release-" + newTag),
Head: github.String(owner + ":" + branchName),
Base: github.String(baseBranch),
Body: github.String("Release " + newTag),
}
if _, _, err := g.client.PullRequests.Create(ctx, owner, repo, pr); err != nil {
log.Fatalf("faield to create pull request: %v", err)
}
}