-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.go
49 lines (41 loc) · 1.02 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
package main
import (
"context"
"fmt"
"log"
"strings"
"sync"
"github.com/google/go-github/github"
)
//GetGithubIssues gets all open GitHub issues and PR's for a given user and repo and returns the total
func GetGithubIssues(user string, repo string, wg *sync.WaitGroup) {
client := github.NewClient(nil)
opt := new(github.IssueListByRepoOptions)
var allIssues []*github.Issue
for {
issues, resp, err := client.Issues.ListByRepo(context.Background(), user, repo, opt)
if err != nil && strings.Contains(err.Error(), "404") {
log.Fatal("No GitHub repo found")
} else if err != nil {
log.Fatal(err)
}
allIssues = append(allIssues, issues...)
if resp.NextPage == 0 {
break
}
opt.Page = resp.NextPage
}
//Filter out PR's because they're also included
var list []github.Issue
var pr int
for _, issue := range allIssues {
if !issue.IsPullRequest() {
list = append(list, *issue)
} else {
pr++
}
}
fmt.Printf("%v issues open\n", len(list))
fmt.Printf("%v pull requests open\n", pr)
wg.Done()
}