Skip to content

Commit fb48261

Browse files
feat(reporting): add format markdown curation issues
1 parent 531753f commit fb48261

File tree

2 files changed

+36
-40
lines changed

2 files changed

+36
-40
lines changed

reporting/output.go

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,69 +19,64 @@ 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-
}
47+
func writeBacklog(data string, outputFile *os.File) error {
5248
if opts.format == "json" {
5349
data = jsonFormat(data)
5450
}
55-
err = os.WriteFile(opts.outputPath+"backlog.json", []byte(data), 0644)
51+
_, err := outputFile.WriteString(data)
5652
if err != nil {
5753
return err
5854
}
5955
return nil
6056
}
6157

62-
func writeCuration(issues []*github.Issue) error {
63-
err := createOutputDir()
64-
if err != nil {
65-
return err
66-
}
67-
58+
func writeCuration(issues []*github.Issue, outputFile *os.File) error {
6859
var issuesTable [][]string
6960
for _, issue := range issues {
70-
issuesTable = append(issuesTable, []string{fmt.Sprintf("%d", *issue.Number), *issue.Title, *issue.HTMLURL})
61+
issuesTable = append(issuesTable, []string{issue.GetTitle(), issue.GetURL(), issue.GetUser().GetLogin()})
7162
}
72-
err = os.WriteFile(opts.outputPath+"curation.json", []byte("data"), 0644)
63+
64+
markdownTable, err := markdown.NewTableFormatterBuilder().
65+
Build("Title", "Link to Body", "Assignee").
66+
Format(issuesTable)
7367
if err != nil {
7468
return err
7569
}
76-
return nil
77-
}
70+
result := fmt.Sprintf("# Curation\n\nThere is **%d new issues** in gno/awesome-gno since %s\n\n%s", len(issues), opts.since, markdownTable)
7871

79-
func writeTips(data string) error {
80-
err := createOutputDir()
72+
_, err = outputFile.WriteString(result)
8173
if err != nil {
8274
return err
8375
}
76+
return nil
77+
}
8478

79+
func writeTips(data string, outputFile *os.File) error {
8580
// Format at Markdown format
8681
var table [][]string
8782
var tweets TweetSearch
@@ -92,7 +87,7 @@ func writeTips(data string) error {
9287
authors[user.Id] = user.Username
9388
}
9489
for _, tweet := range tweets.Data {
95-
table = append(table, []string{authors[tweet.AuthorId], strings.Replace(tweet.Text, "\n", "", -1), tweet.CreatedAt})
90+
table = append(table, []string{authors[tweet.AuthorId], strings.Replace(tweet.Text, "\n", " ", -1), tweet.CreatedAt})
9691
}
9792

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

107-
err = os.WriteFile(opts.outputPath+"report.md", []byte(result), 0644)
102+
_, err = outputFile.WriteString(result)
108103
if err != nil {
109104
return err
110105
}

reporting/reporting.go

Lines changed: 11 additions & 10 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,7 +126,7 @@ 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+
func fetchBacklog(client *github.Client, since time.Time, outputFile *os.File) error {
129130
if !opts.backlog {
130131
return nil
131132
}
@@ -141,27 +142,27 @@ func fetchBacklog(client *github.Client, since time.Time) error {
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)