-
Notifications
You must be signed in to change notification settings - Fork 19
/
check.go
68 lines (56 loc) · 1.35 KB
/
check.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
package main
import (
"fmt"
"os"
"github.com/pkg/errors"
)
func check() error {
fmt.Println("Checking results.")
var users []string
rows, err := db.Query("SELECT username FROM users ORDER BY username")
if err != nil {
return errors.Wrap(err, "could not query list of users")
}
for rows.Next() {
var user string
if err := rows.Scan(&user); err != nil {
return errors.Wrap(err, "could not scan user")
}
users = append(users, user)
}
if err := rows.Err(); err != nil {
return errors.Wrap(err, "could not iterate over user result")
}
prs, err := fetchPRs(users, os.Getenv("PAT"))
if err != nil {
return errors.Wrap(err, "could not fetch PRs")
}
prsByUser := make(map[string][]PR)
for _, p := range prs {
prsByUser[p.User] = append(prsByUser[p.User], p)
}
var succesful, unsuccessful int
fmt.Printf(" %20s %8s %8s\n", "Username", "Valid", "Invalid")
for i, u := range users {
prs := prsByUser[u]
var valid, invalid int
for _, p := range prs {
if p.Valid {
valid++
} else {
invalid++
}
}
var result string
if valid >= hacktoberfestOptions.RequiredPullRequestCount {
succesful++
result = "✔"
} else {
unsuccessful++
result = "✘"
}
fmt.Printf("%02d %20s %8d %8d %s\n", i, u, valid, invalid, result)
}
fmt.Printf("Succesful: %d\nUnsuccessful: %d\n", succesful, unsuccessful)
return nil
}