-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.go
More file actions
43 lines (34 loc) · 908 Bytes
/
github.go
File metadata and controls
43 lines (34 loc) · 908 Bytes
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
package main
import (
"strconv"
"strings"
"github.com/google/go-github/github"
"github.com/supu-io/payload"
"golang.org/x/oauth2"
)
func doMove(p payload.Payload, client *github.Client) error {
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: *p.Config.Github.Token},
)
tc := oauth2.NewClient(oauth2.NoContext, ts)
if client == nil {
client = github.NewClient(tc)
}
org, repo, number := getIssueDetails(*p.Issue.ID)
for _, status := range *p.Status {
_, err := client.Issues.RemoveLabelForIssue(org, repo, number, status)
if err != nil {
println(err.Error())
}
}
status := p.Transition.To
client.Issues.AddLabelsToIssue(org, repo, number, []string{*status})
return nil
}
func getIssueDetails(id string) (string, string, int) {
parts := strings.Split(id, "/")
org := parts[0]
repo := parts[1]
number, _ := strconv.Atoi(parts[2])
return org, repo, number
}