Skip to content

Commit 81a8714

Browse files
authored
Merge pull request #7 from Mikatech/tech-reports
2 parents 0d580db + 99bbba9 commit 81a8714

File tree

8 files changed

+603
-0
lines changed

8 files changed

+603
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
reporting/reporting
2+
reporting/output

reporting/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Reporting :detective:
2+
3+
This directory contains the code for the reporting system.\
4+
For launching the reporting script, you will need a github & twitter token.
5+
6+
You can find these tokens in the following links:
7+
- twitter: https://developer.twitter.com/en/docs/authentication/oauth-2-0
8+
- github: https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token
9+
10+
## Usage
11+
12+
```bash
13+
USAGE
14+
reporting [flags]
15+
16+
FLAGS
17+
-backlog=true generate backlog
18+
-changelog=true generate changelog
19+
-curation=true generate curation
20+
-format markdown output format
21+
-github-token ... github token
22+
-help=false show help
23+
-output-path ./output/ output directory path
24+
-since ... since date RFC 3339 (ex: 2003-01-19T00:00:00.000Z)
25+
-tips=true generate tips
26+
-twitter-token ... twitter token
27+
```
28+
29+
------------
30+
31+
## Example output
32+

reporting/github.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"time"
6+
7+
"github.com/google/go-github/v50/github"
8+
"golang.org/x/oauth2"
9+
)
10+
11+
func initGithubClient() *github.Client {
12+
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: opts.githubToken})
13+
tc := oauth2.NewClient(context.Background(), ts)
14+
client := github.NewClient(tc)
15+
return client
16+
}
17+
18+
func githubFetchIssues(client *github.Client, opts *github.IssueListByRepoOptions, owner string, repository string) ([]*github.Issue, error) {
19+
issues, _, err := client.Issues.ListByRepo(context.Background(), owner, repository, opts)
20+
if err != nil {
21+
return nil, err
22+
}
23+
24+
return issues, nil
25+
}
26+
27+
func githubFetchCommits(client *github.Client, opts *github.CommitsListOptions, owner string, repository string) ([]*github.RepositoryCommit, error) {
28+
commits, _, err := client.Repositories.ListCommits(context.Background(), owner, repository, opts)
29+
if err != nil {
30+
return nil, err
31+
}
32+
33+
return commits, nil
34+
}
35+
36+
func githubFetchPullRequests(client *github.Client, opts *github.PullRequestListOptions, owner string, repository string) ([]*github.PullRequest, error) {
37+
pullRequests, _, err := client.PullRequests.List(context.Background(), owner, repository, opts)
38+
if err != nil {
39+
return nil, err
40+
}
41+
42+
return pullRequests, nil
43+
}
44+
45+
func filterPullRequestByTime(pullRequests []*github.PullRequest, since time.Time) []*github.PullRequest {
46+
var filtered []*github.PullRequest
47+
for _, pullRequest := range pullRequests {
48+
if pullRequest.UpdatedAt.After(since) {
49+
filtered = append(filtered, pullRequest)
50+
}
51+
}
52+
return filtered
53+
}
54+
55+
func filterIssueNotPR(issues []*github.Issue) []*github.Issue {
56+
var filtered []*github.Issue
57+
for _, issue := range issues {
58+
if issue.PullRequestLinks == nil {
59+
filtered = append(filtered, issue)
60+
}
61+
}
62+
return filtered
63+
}

reporting/go.mod

Lines changed: 19 additions & 0 deletions
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

Lines changed: 42 additions & 0 deletions
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

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"github.com/fbiville/markdown-table-formatter/pkg/markdown"
7+
"github.com/google/go-github/v50/github"
8+
"os"
9+
"strings"
10+
)
11+
12+
const awesomeGnoEmbedURL = "**[gnolang/awesome-Gno](https://github.com/gnolang/awesome-gno)**"
13+
const gnoEmbedURL = "**[gnolang/gno](https://github.com/gnolang/gno)**"
14+
15+
func createOutputFile() (*os.File, error) {
16+
if _, err := os.Stat(opts.outputPath); os.IsNotExist(err) {
17+
err = os.MkdirAll(opts.outputPath, os.ModePerm)
18+
if err != nil {
19+
return nil, err
20+
}
21+
}
22+
outputFile, err := os.Create(opts.outputPath + "report.md")
23+
if err != nil {
24+
return nil, err
25+
}
26+
return outputFile, nil
27+
}
28+
29+
// TODO: Refacto table creation ~Don't repeat yourself
30+
func writeChangelog(issues []*github.Issue, pullRequests []*github.PullRequest, commits []*github.RepositoryCommit, outputFile *os.File) error {
31+
var issuesTable [][]string
32+
for _, issue := range issues {
33+
issuesTable = append(issuesTable, []string{issue.GetTitle(), issue.GetURL(), issue.GetUser().GetLogin()})
34+
}
35+
36+
markdownTable, err := markdown.NewTableFormatterBuilder().
37+
Build("Title", "Link to Body", "Assignee").
38+
Format(issuesTable)
39+
if err != nil {
40+
return err
41+
}
42+
result := fmt.Sprintf("# Changelog ⚙️\n\nThere is **%d new closed issues** in %s since %s\n\n%s", len(issues), gnoEmbedURL, opts.since, markdownTable)
43+
44+
var pullRequestRows [][]string
45+
for _, pr := range pullRequests {
46+
pullRequestRows = append(pullRequestRows, []string{pr.GetTitle(), pr.GetURL(), pr.GetUser().GetLogin()})
47+
}
48+
pullRequestsTable, err := markdown.NewTableFormatterBuilder().
49+
Build("Title", "Link to PR", "Author").
50+
Format(pullRequestRows)
51+
if err != nil {
52+
return err
53+
}
54+
result += fmt.Sprintf("\n\n## New PR\nThere is **%d new closed PR** in %s since %s\n\n%s", len(pullRequests), gnoEmbedURL, opts.since, pullRequestsTable)
55+
56+
result += fmt.Sprintf("\n\n## New commits\nThere is **%d new commits** in %s since %s\n\n", len(commits), gnoEmbedURL, opts.since)
57+
58+
_, err = outputFile.WriteString(result)
59+
if err != nil {
60+
return err
61+
}
62+
return nil
63+
}
64+
65+
// TODO: Refacto table creation ~Don't repeat yourself
66+
func writeBacklog(issues []*github.Issue, pullRequests []*github.PullRequest, outputFile *os.File) error {
67+
var issuesTable [][]string
68+
for _, issue := range issues {
69+
issuesTable = append(issuesTable, []string{issue.GetTitle(), issue.GetURL(), issue.GetUser().GetLogin()})
70+
}
71+
72+
markdownTable, err := markdown.NewTableFormatterBuilder().
73+
Build("Title", "Link to Body", "Assignee").
74+
Format(issuesTable)
75+
if err != nil {
76+
return err
77+
}
78+
result := fmt.Sprintf("# Backlog 💡\n\nThere is **%d new open issues** in %s since %s\n\n%s", len(issues), gnoEmbedURL, opts.since, markdownTable)
79+
80+
var pullRequestRows [][]string
81+
for _, pr := range pullRequests {
82+
pullRequestRows = append(pullRequestRows, []string{pr.GetTitle(), pr.GetURL(), pr.GetUser().GetLogin()})
83+
}
84+
pullRequestsTable, err := markdown.NewTableFormatterBuilder().
85+
Build("Title", "Link to PR", "Author").
86+
Format(pullRequestRows)
87+
if err != nil {
88+
return err
89+
}
90+
result += fmt.Sprintf("\n\n## New PR\nThere is **%d new open PR** in %s since %s\n\n%s", len(pullRequests), gnoEmbedURL, opts.since, pullRequestsTable)
91+
92+
_, err = outputFile.WriteString(result)
93+
if err != nil {
94+
return err
95+
}
96+
return nil
97+
}
98+
99+
// TODO: Refacto table creation ~Don't repeat yourself
100+
func writeCuration(issues []*github.Issue, pullRequests []*github.PullRequest, commits []*github.RepositoryCommit, outputFile *os.File) error {
101+
// Format at Markdown format
102+
var issuesRows [][]string
103+
for _, issue := range issues {
104+
issuesRows = append(issuesRows, []string{issue.GetTitle(), issue.GetURL(), issue.GetUser().GetLogin()})
105+
}
106+
issuesTable, err := markdown.NewTableFormatterBuilder().
107+
Build("Title", "Link to issue", "Author").
108+
Format(issuesRows)
109+
if err != nil {
110+
return err
111+
}
112+
result := fmt.Sprintf("# Curation 📚\n\n## New issues\nThere is **%d updated issues** in %s since %s\n\n%s", len(issues), awesomeGnoEmbedURL, opts.since, issuesTable)
113+
114+
var pullRequestRows [][]string
115+
for _, pr := range pullRequests {
116+
pullRequestRows = append(pullRequestRows, []string{pr.GetTitle(), pr.GetURL(), pr.GetUser().GetLogin()})
117+
}
118+
pullRequestsTable, err := markdown.NewTableFormatterBuilder().
119+
Build("Title", "Link to PR", "Author").
120+
Format(pullRequestRows)
121+
if err != nil {
122+
return err
123+
}
124+
result += fmt.Sprintf("\n\n## New PR\nThere is **%d updated PR** in %s since %s\n\n%s", len(pullRequests), awesomeGnoEmbedURL, opts.since, pullRequestsTable)
125+
126+
result += fmt.Sprintf("\n\n## New commits\nThere is **%d new commits** in %s since %s\n\n", len(commits), awesomeGnoEmbedURL, opts.since)
127+
128+
_, err = outputFile.WriteString(result)
129+
if err != nil {
130+
return err
131+
}
132+
return nil
133+
}
134+
135+
// TODO: Refacto table creation ~Don't repeat yourself
136+
func writeTips(data string, outputFile *os.File) error {
137+
// Format at Markdown format
138+
var rows [][]string
139+
var tweets TweetSearch
140+
authors := make(map[string]string)
141+
142+
_ = json.Unmarshal([]byte(data), &tweets)
143+
for _, user := range tweets.Includes.Users {
144+
authors[user.Id] = user.Username
145+
}
146+
for _, tweet := range tweets.Data {
147+
rows = append(rows, []string{authors[tweet.AuthorId], strings.Replace(tweet.Text, "\n", " ", -1), tweet.CreatedAt})
148+
}
149+
150+
//Maybe build our own table formatter
151+
table, err := markdown.NewTableFormatterBuilder().
152+
Build("Author", "Text", "Created at").
153+
Format(rows)
154+
if err != nil {
155+
return err
156+
}
157+
result := fmt.Sprintf("# Tips 🐦\n\n## New Tweets with #gnotips\nThere is **%d new tweet** about gnotips since %s\n\n%s", tweets.Meta.ResultCount, opts.since, table)
158+
159+
_, err = outputFile.WriteString(result)
160+
if err != nil {
161+
return err
162+
}
163+
return nil
164+
}

0 commit comments

Comments
 (0)