Skip to content

Commit 75d7437

Browse files
feat(reporting): add backlog issues report
1 parent 531753f commit 75d7437

File tree

2 files changed

+48
-42
lines changed

2 files changed

+48
-42
lines changed

reporting/output.go

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,69 +19,74 @@ func jsonFormat(data string) string {
1919
return out.String()
2020
}
2121

22-
func createOutputDir() error {
22+
func createOutputFile() (*os.File, error) {
2323
if _, err := os.Stat(opts.outputPath); os.IsNotExist(err) {
2424
err = os.MkdirAll(opts.outputPath, os.ModePerm)
2525
if err != nil {
26-
return err
26+
return nil, err
2727
}
2828
}
29-
return nil
30-
}
31-
32-
func writeChangelog(data string) error {
33-
err := createOutputDir()
29+
outputFile, err := os.Create(opts.outputPath + "report.md")
3430
if err != nil {
35-
return err
31+
return nil, err
3632
}
33+
return outputFile, nil
34+
}
35+
36+
func writeChangelog(data string, outputFile *os.File) error {
3737
if opts.format == "json" {
3838
data = jsonFormat(data)
3939
}
40-
err = os.WriteFile(opts.outputPath+"changelog.json", []byte(data), 0644)
40+
_, err := outputFile.WriteString(data)
4141
if err != nil {
4242
return err
4343
}
4444
return nil
4545
}
4646

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)
47+
func writeBacklog(issues []*github.Issue, outputFile *os.File) error {
48+
var issuesTable [][]string
49+
for _, issue := range issues {
50+
issuesTable = append(issuesTable, []string{issue.GetTitle(), issue.GetURL(), issue.GetUser().GetLogin()})
5451
}
55-
err = os.WriteFile(opts.outputPath+"backlog.json", []byte(data), 0644)
52+
53+
markdownTable, err := markdown.NewTableFormatterBuilder().
54+
Build("Title", "Link to Body", "Assignee").
55+
Format(issuesTable)
5656
if err != nil {
5757
return err
5858
}
59-
return nil
60-
}
59+
result := fmt.Sprintf("# Backlog\n\nThere is **%d new open issues** in gnolang/gno since %s\n\n%s", len(issues), opts.since, markdownTable)
6160

62-
func writeCuration(issues []*github.Issue) error {
63-
err := createOutputDir()
61+
_, err = outputFile.WriteString(result)
6462
if err != nil {
6563
return err
6664
}
65+
return nil
66+
}
6767

68+
func writeCuration(issues []*github.Issue, outputFile *os.File) error {
6869
var issuesTable [][]string
6970
for _, issue := range issues {
70-
issuesTable = append(issuesTable, []string{fmt.Sprintf("%d", *issue.Number), *issue.Title, *issue.HTMLURL})
71+
issuesTable = append(issuesTable, []string{issue.GetTitle(), issue.GetURL(), issue.GetUser().GetLogin()})
7172
}
72-
err = os.WriteFile(opts.outputPath+"curation.json", []byte("data"), 0644)
73+
74+
markdownTable, err := markdown.NewTableFormatterBuilder().
75+
Build("Title", "Link to Body", "Assignee").
76+
Format(issuesTable)
7377
if err != nil {
7478
return err
7579
}
76-
return nil
77-
}
80+
result := fmt.Sprintf("# Curation\n\nThere is **%d new issues** in gnolang/awesome-gno since %s\n\n%s", len(issues), opts.since, markdownTable)
7881

79-
func writeTips(data string) error {
80-
err := createOutputDir()
82+
_, err = outputFile.WriteString(result)
8183
if err != nil {
8284
return err
8385
}
86+
return nil
87+
}
8488

89+
func writeTips(data string, outputFile *os.File) error {
8590
// Format at Markdown format
8691
var table [][]string
8792
var tweets TweetSearch
@@ -92,7 +97,7 @@ func writeTips(data string) error {
9297
authors[user.Id] = user.Username
9398
}
9499
for _, tweet := range tweets.Data {
95-
table = append(table, []string{authors[tweet.AuthorId], strings.Replace(tweet.Text, "\n", "", -1), tweet.CreatedAt})
100+
table = append(table, []string{authors[tweet.AuthorId], strings.Replace(tweet.Text, "\n", " ", -1), tweet.CreatedAt})
96101
}
97102

98103
//Maybe build our own table formatter
@@ -102,9 +107,9 @@ func writeTips(data string) error {
102107
if err != nil {
103108
return err
104109
}
105-
result := fmt.Sprintf("# Tips\n\nThere is **%d new tweet** about gno since %s\n\n%s", tweets.Meta.ResultCount, opts.since, markdownTable)
110+
result := fmt.Sprintf("# Tips\n\nThere is **%d new tweet** about gnotips since %s\n\n%s", tweets.Meta.ResultCount, opts.since, markdownTable)
106111

107-
err = os.WriteFile(opts.outputPath+"report.md", []byte(result), 0644)
112+
_, err = outputFile.WriteString(result)
108113
if err != nil {
109114
return err
110115
}

reporting/reporting.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,20 @@ func runMain(args []string) error {
8484
}
8585
}
8686
githubClient := initGithubClient()
87-
err = fetchChangelog(githubClient, since)
87+
outputFile, err := createOutputFile()
88+
err = fetchChangelog(githubClient, since, outputFile)
8889
if err != nil {
8990
return err
9091
}
91-
err = fetchBacklog(githubClient, since)
92+
err = fetchBacklog(githubClient, since, outputFile)
9293
if err != nil {
9394
return err
9495
}
95-
err = fetchCuration(githubClient, since)
96+
err = fetchCuration(githubClient, since, outputFile)
9697
if err != nil {
9798
return err
9899
}
99-
err = fetchTips()
100+
err = fetchTips(outputFile)
100101
if err != nil {
101102
return err
102103
}
@@ -108,7 +109,7 @@ func runMain(args []string) error {
108109
}
109110

110111
// TODO: Fetch changelog recent contributors, new PR merged, new issues closed ...
111-
func fetchChangelog(client *github.Client, since time.Time) error {
112+
func fetchChangelog(client *github.Client, since time.Time, outputFile *os.File) error {
112113
if !opts.changelog {
113114
return nil
114115
}
@@ -125,43 +126,43 @@ func fetchChangelog(client *github.Client, since time.Time) error {
125126
}
126127

127128
// TODO: Fetch backlog from github issues & PRS ...
128-
func fetchBacklog(client *github.Client, since time.Time) error {
129-
if !opts.backlog {
129+
func fetchBacklog(client *github.Client, since time.Time, outputFile *os.File) error {
130+
if !opts.curation {
130131
return nil
131132
}
132133
issues, err := githubFetchIssues(client, &github.IssueListByRepoOptions{State: "open", Since: since}, "gnolang", "gno")
133134
if err != nil {
134135
return err
135136
}
136-
_, err = json.Marshal(issues)
137+
err = writeBacklog(issues, outputFile)
137138
if err != nil {
138139
return err
139140
}
140141
return nil
141142
}
142143

143144
// TODO: Fetch curation from github commits & issues & PRS in `awesome-gno` repo
144-
func fetchCuration(client *github.Client, since time.Time) error {
145+
func fetchCuration(client *github.Client, since time.Time, outputFile *os.File) error {
145146
if !opts.curation {
146147
return nil
147148
}
148149
issues, err := githubFetchIssues(client, &github.IssueListByRepoOptions{State: "all", Since: since}, "gnolang", "awesome-gno")
149150
if err != nil {
150151
return err
151152
}
152-
_, err = json.Marshal(issues)
153+
err = writeCuration(issues, outputFile)
153154
if err != nil {
154155
return err
155156
}
156157
return nil
157158
}
158159

159-
func fetchTips() error {
160+
func fetchTips(outputFile *os.File) error {
160161
if !opts.tips {
161162
return nil
162163
}
163164
ret := twitterFetchTips()
164-
err := writeTips(ret)
165+
err := writeTips(ret, outputFile)
165166
if err != nil {
166167
return err
167168
}

0 commit comments

Comments
 (0)