Skip to content

Commit 531753f

Browse files
feat(reporting): init
Co-authored-by: Ismael FALL <[email protected]>
1 parent da33167 commit 531753f

File tree

7 files changed

+471
-0
lines changed

7 files changed

+471
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
reporting/reporting
2+
reporting/output

reporting/github.go

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package main
2+
3+
import (
4+
"context"
5+
6+
"github.com/google/go-github/v50/github"
7+
"golang.org/x/oauth2"
8+
)
9+
10+
func initGithubClient() *github.Client {
11+
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: opts.githubToken})
12+
tc := oauth2.NewClient(context.Background(), ts)
13+
client := github.NewClient(tc)
14+
return client
15+
}
16+
17+
func githubFetchIssues(client *github.Client, opts *github.IssueListByRepoOptions, owner string, repository string) ([]*github.Issue, error) {
18+
issues, _, err := client.Issues.ListByRepo(context.Background(), owner, repository, opts)
19+
if err != nil {
20+
return nil, err
21+
}
22+
23+
return issues, nil
24+
}
25+
26+
func githubFetchCommits(client *github.Client, opts *github.CommitsListOptions, owner string, repository string) ([]*github.RepositoryCommit, error) {
27+
commits, _, err := client.Repositories.ListCommits(context.Background(), owner, repository, opts)
28+
if err != nil {
29+
return nil, err
30+
}
31+
32+
return commits, nil
33+
}
34+
35+
func githubFetchPullRequests(client *github.Client, opts *github.PullRequestListOptions, owner string, repository string) ([]*github.PullRequest, error) {
36+
pullRequests, _, err := client.PullRequests.List(context.Background(), owner, repository, opts)
37+
if err != nil {
38+
return nil, err
39+
}
40+
41+
return pullRequests, nil
42+
}

reporting/go.mod

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module github.com/gnolang/gno/misc/reporting
2+
3+
go 1.19
4+
5+
require (
6+
github.com/google/go-github/v50 v50.0.0
7+
github.com/peterbourgon/ff/v3 v3.3.0
8+
golang.org/x/oauth2 v0.4.0
9+
)
10+
11+
require (
12+
github.com/fbiville/markdown-table-formatter v0.3.0 // indirect
13+
github.com/golang/protobuf v1.5.2 // indirect
14+
github.com/google/go-querystring v1.1.0 // indirect
15+
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
16+
golang.org/x/net v0.5.0 // indirect
17+
google.golang.org/appengine v1.6.7 // indirect
18+
google.golang.org/protobuf v1.28.0 // indirect
19+
)

reporting/go.sum

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
github.com/fbiville/markdown-table-formatter v0.3.0 h1:PIm1UNgJrFs8q1htGTw+wnnNYvwXQMMMIKNZop2SSho=
2+
github.com/fbiville/markdown-table-formatter v0.3.0/go.mod h1:q89TDtSEVDdTaufgSbfHpNVdPU/bmfvqNkrC5HagmLY=
3+
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
4+
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
5+
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
6+
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
7+
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
8+
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
9+
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
10+
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
11+
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
12+
github.com/google/go-github/v30 v30.1.0 h1:VLDx+UolQICEOKu2m4uAoMti1SxuEBAl7RSEG16L+Oo=
13+
github.com/google/go-github/v30 v30.1.0/go.mod h1:n8jBpHl45a/rlBUtRJMOG4GhNADUQFEufcolZ95JfU8=
14+
github.com/google/go-github/v50 v50.0.0 h1:gdO1AeuSZZK4iYWwVbjni7zg8PIQhp7QfmPunr016Jk=
15+
github.com/google/go-github/v50 v50.0.0/go.mod h1:Ev4Tre8QoKiolvbpOSG3FIi4Mlon3S2Nt9W5JYqKiwA=
16+
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
17+
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
18+
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
19+
github.com/peterbourgon/ff/v3 v3.3.0 h1:PaKe7GW8orVFh8Unb5jNHS+JZBwWUMa2se0HM6/BI24=
20+
github.com/peterbourgon/ff/v3 v3.3.0/go.mod h1:zjJVUhx+twciwfDl0zBcFzl4dW8axCRyXE/eKY9RztQ=
21+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
22+
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
23+
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
24+
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
25+
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
26+
golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw=
27+
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
28+
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
29+
golang.org/x/oauth2 v0.4.0 h1:NF0gk8LVPg1Ml7SSbGyySuoxdsXitj7TvgvuRxIMc/M=
30+
golang.org/x/oauth2 v0.4.0/go.mod h1:RznEsdpjGAINPTOF0UH/t+xJ75L18YO3Ho6Pyn+uRec=
31+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
32+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
33+
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
34+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
35+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
36+
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
37+
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
38+
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
39+
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
40+
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
41+
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
42+
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=

reporting/output.go

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package main
2+
3+
import (
4+
"bytes"
5+
"encoding/json"
6+
"fmt"
7+
"github.com/fbiville/markdown-table-formatter/pkg/markdown"
8+
"github.com/google/go-github/v50/github"
9+
"os"
10+
"strings"
11+
)
12+
13+
func jsonFormat(data string) string {
14+
var out bytes.Buffer
15+
err := json.Indent(&out, []byte(data), "", "\t")
16+
if err != nil {
17+
return data
18+
}
19+
return out.String()
20+
}
21+
22+
func createOutputDir() error {
23+
if _, err := os.Stat(opts.outputPath); os.IsNotExist(err) {
24+
err = os.MkdirAll(opts.outputPath, os.ModePerm)
25+
if err != nil {
26+
return err
27+
}
28+
}
29+
return nil
30+
}
31+
32+
func writeChangelog(data string) error {
33+
err := createOutputDir()
34+
if err != nil {
35+
return err
36+
}
37+
if opts.format == "json" {
38+
data = jsonFormat(data)
39+
}
40+
err = os.WriteFile(opts.outputPath+"changelog.json", []byte(data), 0644)
41+
if err != nil {
42+
return err
43+
}
44+
return nil
45+
}
46+
47+
func writeBacklog(data string) error {
48+
err := createOutputDir()
49+
if err != nil {
50+
return err
51+
}
52+
if opts.format == "json" {
53+
data = jsonFormat(data)
54+
}
55+
err = os.WriteFile(opts.outputPath+"backlog.json", []byte(data), 0644)
56+
if err != nil {
57+
return err
58+
}
59+
return nil
60+
}
61+
62+
func writeCuration(issues []*github.Issue) error {
63+
err := createOutputDir()
64+
if err != nil {
65+
return err
66+
}
67+
68+
var issuesTable [][]string
69+
for _, issue := range issues {
70+
issuesTable = append(issuesTable, []string{fmt.Sprintf("%d", *issue.Number), *issue.Title, *issue.HTMLURL})
71+
}
72+
err = os.WriteFile(opts.outputPath+"curation.json", []byte("data"), 0644)
73+
if err != nil {
74+
return err
75+
}
76+
return nil
77+
}
78+
79+
func writeTips(data string) error {
80+
err := createOutputDir()
81+
if err != nil {
82+
return err
83+
}
84+
85+
// Format at Markdown format
86+
var table [][]string
87+
var tweets TweetSearch
88+
authors := make(map[string]string)
89+
90+
_ = json.Unmarshal([]byte(data), &tweets)
91+
for _, user := range tweets.Includes.Users {
92+
authors[user.Id] = user.Username
93+
}
94+
for _, tweet := range tweets.Data {
95+
table = append(table, []string{authors[tweet.AuthorId], strings.Replace(tweet.Text, "\n", "", -1), tweet.CreatedAt})
96+
}
97+
98+
//Maybe build our own table formatter
99+
markdownTable, err := markdown.NewTableFormatterBuilder().
100+
Build("Author", "Text", "Created at").
101+
Format(table)
102+
if err != nil {
103+
return err
104+
}
105+
result := fmt.Sprintf("# Tips\n\nThere is **%d new tweet** about gno since %s\n\n%s", tweets.Meta.ResultCount, opts.since, markdownTable)
106+
107+
err = os.WriteFile(opts.outputPath+"report.md", []byte(result), 0644)
108+
if err != nil {
109+
return err
110+
}
111+
return nil
112+
}

0 commit comments

Comments
 (0)