Skip to content

Commit 6600605

Browse files
feat(reporting): add reporting PR/issues in backlog & changelog
1 parent cac3df8 commit 6600605

File tree

2 files changed

+57
-22
lines changed

2 files changed

+57
-22
lines changed

reporting/output.go

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"bytes"
54
"encoding/json"
65
"fmt"
76
"github.com/fbiville/markdown-table-formatter/pkg/markdown"
@@ -10,15 +9,6 @@ import (
109
"strings"
1110
)
1211

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-
2212
func createOutputFile() (*os.File, error) {
2313
if _, err := os.Stat(opts.outputPath); os.IsNotExist(err) {
2414
err = os.MkdirAll(opts.outputPath, os.ModePerm)
@@ -33,7 +23,8 @@ func createOutputFile() (*os.File, error) {
3323
return outputFile, nil
3424
}
3525

36-
func writeChangelog(issues []*github.Issue, outputFile *os.File) error {
26+
// TODO: Refacto table creation ~Don't repeat yourself
27+
func writeChangelog(issues []*github.Issue, pullRequests []*github.PullRequest, commits []*github.RepositoryCommit, outputFile *os.File) error {
3728
var issuesTable [][]string
3829
for _, issue := range issues {
3930
issuesTable = append(issuesTable, []string{issue.GetTitle(), issue.GetURL(), issue.GetUser().GetLogin()})
@@ -47,14 +38,29 @@ func writeChangelog(issues []*github.Issue, outputFile *os.File) error {
4738
}
4839
result := fmt.Sprintf("# Changelog ⚙️\n\nThere is **%d new closed issues** in gnolang/gno since %s\n\n%s", len(issues), opts.since, markdownTable)
4940

41+
var pullRequestRows [][]string
42+
for _, pr := range pullRequests {
43+
pullRequestRows = append(pullRequestRows, []string{pr.GetTitle(), pr.GetURL(), pr.GetUser().GetLogin()})
44+
}
45+
pullRequestsTable, err := markdown.NewTableFormatterBuilder().
46+
Build("Title", "Link to PR", "Author").
47+
Format(pullRequestRows)
48+
if err != nil {
49+
return err
50+
}
51+
result += fmt.Sprintf("\n\n## New PR\nThere is **%d new closed PR** in gnolang/awesome-gno since %s\n\n%s", len(pullRequests), opts.since, pullRequestsTable)
52+
53+
result += fmt.Sprintf("\n\n## New commits\nThere is **%d new commits** in gnolang/awesome-gno since %s\n\n", len(commits), opts.since)
54+
5055
_, err = outputFile.WriteString(result)
5156
if err != nil {
5257
return err
5358
}
5459
return nil
5560
}
5661

57-
func writeBacklog(issues []*github.Issue, outputFile *os.File) error {
62+
// TODO: Refacto table creation ~Don't repeat yourself
63+
func writeBacklog(issues []*github.Issue, pullRequests []*github.PullRequest, outputFile *os.File) error {
5864
var issuesTable [][]string
5965
for _, issue := range issues {
6066
issuesTable = append(issuesTable, []string{issue.GetTitle(), issue.GetURL(), issue.GetUser().GetLogin()})
@@ -68,13 +74,26 @@ func writeBacklog(issues []*github.Issue, outputFile *os.File) error {
6874
}
6975
result := fmt.Sprintf("# Backlog 💡\n\nThere is **%d new open issues** in gnolang/gno since %s\n\n%s", len(issues), opts.since, markdownTable)
7076

77+
var pullRequestRows [][]string
78+
for _, pr := range pullRequests {
79+
pullRequestRows = append(pullRequestRows, []string{pr.GetTitle(), pr.GetURL(), pr.GetUser().GetLogin()})
80+
}
81+
pullRequestsTable, err := markdown.NewTableFormatterBuilder().
82+
Build("Title", "Link to PR", "Author").
83+
Format(pullRequestRows)
84+
if err != nil {
85+
return err
86+
}
87+
result += fmt.Sprintf("\n\n## New PR\nThere is **%d new open PR** in gnolang/gno since %s\n\n%s", len(pullRequests), opts.since, pullRequestsTable)
88+
7189
_, err = outputFile.WriteString(result)
7290
if err != nil {
7391
return err
7492
}
7593
return nil
7694
}
7795

96+
// TODO: Refacto table creation ~Don't repeat yourself
7897
func writeCuration(issues []*github.Issue, pullRequests []*github.PullRequest, commits []*github.RepositoryCommit, outputFile *os.File) error {
7998
// Format at Markdown format
8099
var issuesRows [][]string
@@ -87,7 +106,7 @@ func writeCuration(issues []*github.Issue, pullRequests []*github.PullRequest, c
87106
if err != nil {
88107
return err
89108
}
90-
result := fmt.Sprintf("# Curation 📚\n\n## New issues\nThere is **%d new issues** in gnolang/awesome-gno since %s\n\n%s", len(issues), opts.since, issuesTable)
109+
result := fmt.Sprintf("# Curation 📚\n\n## New issues\nThere is **%d updated issues** in gnolang/awesome-gno since %s\n\n%s", len(issues), opts.since, issuesTable)
91110

92111
var pullRequestRows [][]string
93112
for _, pr := range pullRequests {
@@ -99,7 +118,7 @@ func writeCuration(issues []*github.Issue, pullRequests []*github.PullRequest, c
99118
if err != nil {
100119
return err
101120
}
102-
result += fmt.Sprintf("\n\n## New PR\nThere is **%d new PR** in gnolang/awesome-gno since %s\n\n%s", len(pullRequests), opts.since, pullRequestsTable)
121+
result += fmt.Sprintf("\n\n## New PR\nThere is **%d updated PR** in gnolang/awesome-gno since %s\n\n%s", len(pullRequests), opts.since, pullRequestsTable)
103122

104123
result += fmt.Sprintf("\n\n## New commits\nThere is **%d new commits** in gnolang/awesome-gno since %s\n\n", len(commits), opts.since)
105124

@@ -110,6 +129,7 @@ func writeCuration(issues []*github.Issue, pullRequests []*github.PullRequest, c
110129
return nil
111130
}
112131

132+
// TODO: Refacto table creation ~Don't repeat yourself
113133
func writeTips(data string, outputFile *os.File) error {
114134
// Format at Markdown format
115135
var rows [][]string

reporting/reporting.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func runMain(args []string) error {
5252
globalFlags.BoolVar(&opts.backlog, "backlog", opts.backlog, "generate backlog")
5353
globalFlags.BoolVar(&opts.curation, "curation", opts.curation, "generate curation")
5454
globalFlags.BoolVar(&opts.tips, "tips", opts.tips, "generate tips")
55-
globalFlags.StringVar(&opts.since, "since", opts.since, "since date RFC 3339 (ex: 2003-01-19T00:00:00Z)")
55+
globalFlags.StringVar(&opts.since, "since", opts.since, "since date RFC 3339 (ex: 2003-01-19T00:00:00.000Z)")
5656
globalFlags.StringVar(&opts.twitterToken, "twitter-token", opts.twitterToken, "twitter token")
5757
globalFlags.StringVar(&opts.githubToken, "github-token", opts.githubToken, "github token")
5858
globalFlags.BoolVar(&opts.help, "help", false, "show help")
@@ -117,39 +117,54 @@ func fetchChangelog(client *github.Client, since time.Time, outputFile *os.File)
117117
if err != nil {
118118
return err
119119
}
120-
err = writeChangelog(issues, outputFile)
120+
pullRequests, err := githubFetchPullRequests(client, &github.PullRequestListOptions{State: "closed"}, "gnolang", "gno")
121+
if err != nil {
122+
return err
123+
}
124+
pullRequestsFiltered := filterPullRequestByTime(pullRequests, since)
125+
commits, err := githubFetchCommits(client, &github.CommitsListOptions{Since: since}, "gnolang", "gno")
126+
if err != nil {
127+
return err
128+
}
129+
err = writeChangelog(issues, pullRequestsFiltered, commits, outputFile)
121130
if err != nil {
122131
return err
123132
}
124133
return nil
125134
}
126135

127-
// TODO: Fetch backlog from github issues & PRS ...
128136
func fetchBacklog(client *github.Client, since time.Time, outputFile *os.File) error {
129-
if !opts.curation {
137+
if !opts.backlog {
130138
return nil
131139
}
132140
issues, err := githubFetchIssues(client, &github.IssueListByRepoOptions{State: "open", Since: since}, "gnolang", "gno")
133141
if err != nil {
134142
return err
135143
}
136-
err = writeBacklog(issues, outputFile)
144+
pullRequests, err := githubFetchPullRequests(client, &github.PullRequestListOptions{State: "open"}, "gnolang", "gno")
145+
if err != nil {
146+
return err
147+
}
148+
pullRequestsFiltered := filterPullRequestByTime(pullRequests, since)
149+
if err != nil {
150+
return err
151+
}
152+
err = writeBacklog(issues, pullRequestsFiltered, outputFile)
137153
if err != nil {
138154
return err
139155
}
140156
return nil
141157
}
142158

143-
// TODO: Fetch curation from github commits & issues & PRS in `awesome-gno` repo
144159
func fetchCuration(client *github.Client, since time.Time, outputFile *os.File) error {
145160
if !opts.curation {
146161
return nil
147162
}
148-
issues, err := githubFetchIssues(client, &github.IssueListByRepoOptions{State: "open", Since: since}, "gnolang", "awesome-gno")
163+
issues, err := githubFetchIssues(client, &github.IssueListByRepoOptions{State: "all", Since: since}, "gnolang", "awesome-gno")
149164
if err != nil {
150165
return err
151166
}
152-
pullRequests, err := githubFetchPullRequests(client, &github.PullRequestListOptions{State: "closed"}, "gnolang", "awesome-gno")
167+
pullRequests, err := githubFetchPullRequests(client, &github.PullRequestListOptions{State: "all"}, "gnolang", "awesome-gno")
153168
if err != nil {
154169
return err
155170
}

0 commit comments

Comments
 (0)