-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
87 lines (74 loc) · 2.28 KB
/
main.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"fmt"
"strings"
"github.com/go-github/github"
"flag"
"os"
)
func GetRepos(client *github.Client) []github.Repository {
opt := &github.RepositoryListByOrgOptions{}
allRepos := []github.Repository{}
fmt.Println("Gathering repos...")
for {
repos, resp, err := client.Repositories.ListByOrg("intelsdi-x", opt)
if err != nil {panic(err)}
allRepos = append(allRepos, repos...)
if resp.NextPage == 0 {
break
}
opt.ListOptions.Page = resp.NextPage
}
return allRepos
}
func GetPull(client *github.Client, repo github.Repository) []github.PullRequest {
pulls := []github.PullRequest{}
opt := &github.PullRequestListOptions{State: "open"}
//fmt.Printf("Gathering open pull requests for %s\n", *repo.Name)
pulls, _, err := client.PullRequests.List("intelsdi-x", *repo.Name, opt)
if err != nil {panic(err)}
return pulls
}
func GetIssues(client *github.Client, repo github.Repository) []github.Issue {
opt := &github.IssueListByRepoOptions{State: "open"}
//fmt.Printf("Gathering open issues for %s\n", *repo.Name)
issues, _, err := client.Issues.ListByRepo("intelsdi-x", *repo.Name, opt)
if err != nil {panic(err)}
return issues
}
func main(){
user := flag.String("user", "", "github user")
passwd := flag.String("passwd", "", "github password")
flag.Parse()
if *user == "" || *passwd == "" {
fmt.Printf("Usge of %s:\n", os.Args[0])
flag.PrintDefaults()
return
}
basic := github.BasicAuthTransport{Username: *user, Password: *passwd}
client := github.NewClient(basic.Client())
f, err := os.Create("gitstats.csv")
if err != nil {panic(err)}
defer f.Close()
repos := GetRepos(client)
fmt.Printf("Found %d snap repos\n", len(repos))
for i, repo := range repos {
fmt.Printf("Done %d%s", int(float32(i+1)/float32(len(repos))*100), "%")
if strings.Contains(*repo.Name, "snap") {
pulls := GetPull(client, repo)
issues := GetIssues(client, repo)
if len(pulls) > 0 || len(issues) > 0 {
for _, pull := range pulls {
f.WriteString(fmt.Sprintf("%s;Pull Request;%d;%s\n", *repo.Name, *pull.Number, *pull.Title))
}
for _, issue := range issues {
f.WriteString(fmt.Sprintf("%s;Issue;%d;%s\n", *repo.Name, *issue.Number, *issue.Title))
}
}
f.Sync()
}
fmt.Printf("\033[0J")
fmt.Printf("\033[%dA\n", 1)
}
fmt.Println("")
}