-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
82 lines (78 loc) · 1.66 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
package main
import (
"bytes"
"context"
"fmt"
"os"
"path/filepath"
"sort"
"time"
tea "github.com/charmbracelet/bubbletea"
)
func main() {
timeStr := time.Now().Format("2006-01-02")
wd, _ := os.Getwd()
f, err := tea.LogToFile(filepath.Join(wd, fmt.Sprintf("org-stats-%s.log", timeStr)), "org-stats")
if err != nil {
panic(err)
}
defer f.Close()
result, err := os.Create(fmt.Sprintf("org-stats-%s.result", timeStr))
if err != nil {
panic(err)
}
defer result.Close()
readme, err := os.Create("readme.md")
if err != nil {
panic(err)
}
defer readme.Close()
ctx := context.Background()
token := os.Getenv("GITHUB_PAT_TOKEN")
org := os.Getenv("GITHUB_ORG")
client, err := newClient(ctx, token)
if err != nil {
panic(err)
}
statsList, err := Gather(
context.Background(),
client,
org,
[]string{},
[]string{},
false,
)
if err != nil {
panic(err)
}
type out struct {
title string
time time.Time
str string
}
outList := make([]out, 0)
for t, stats := range statsList {
var b bytes.Buffer
_ = Write(&b, *stats, stats.top, false)
outList = append(outList, out{
title: stats.title,
time: t,
str: b.String(),
})
}
sort.Slice(outList, func(i, j int) bool {
return outList[i].time.After(outList[j].time)
})
readme.WriteString(fmt.Sprintf("# Rank of Orgnization contributor\n\n"))
for _, v := range outList {
readme.WriteString(fmt.Sprintf("## %s\n\n", v.title))
readme.WriteString(fmt.Sprintf("%s", v.str))
}
for _, v := range outList {
if v.time.Before(time.Now().AddDate(0, 0, -10)) {
continue
}
result.WriteString(fmt.Sprintf("## %s\n\n", v.title))
result.WriteString(fmt.Sprintf("%s", v.str))
}
}