Skip to content

Commit cac3df8

Browse files
feat(reporting): add PR/curation filtered by time & emoji
1 parent 4e30c71 commit cac3df8

File tree

3 files changed

+50
-16
lines changed

3 files changed

+50
-16
lines changed

reporting/github.go

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

33
import (
44
"context"
5+
"time"
56

67
"github.com/google/go-github/v50/github"
78
"golang.org/x/oauth2"
@@ -40,3 +41,13 @@ func githubFetchPullRequests(client *github.Client, opts *github.PullRequestList
4041

4142
return pullRequests, nil
4243
}
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+
}

reporting/output.go

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func writeChangelog(issues []*github.Issue, outputFile *os.File) error {
4545
if err != nil {
4646
return err
4747
}
48-
result := fmt.Sprintf("# Changelog\n\nThere is **%d new closed issues** in gnolang/gno since %s\n\n%s", len(issues), opts.since, markdownTable)
48+
result := fmt.Sprintf("# Changelog ⚙️\n\nThere is **%d new closed issues** in gnolang/gno since %s\n\n%s", len(issues), opts.since, markdownTable)
4949

5050
_, err = outputFile.WriteString(result)
5151
if err != nil {
@@ -66,7 +66,7 @@ func writeBacklog(issues []*github.Issue, outputFile *os.File) error {
6666
if err != nil {
6767
return err
6868
}
69-
result := fmt.Sprintf("# Backlog\n\nThere is **%d new open issues** in gnolang/gno since %s\n\n%s", len(issues), opts.since, markdownTable)
69+
result := fmt.Sprintf("# Backlog 💡\n\nThere is **%d new open issues** in gnolang/gno since %s\n\n%s", len(issues), opts.since, markdownTable)
7070

7171
_, err = outputFile.WriteString(result)
7272
if err != nil {
@@ -75,19 +75,33 @@ func writeBacklog(issues []*github.Issue, outputFile *os.File) error {
7575
return nil
7676
}
7777

78-
func writeCuration(issues []*github.Issue, outputFile *os.File) error {
79-
var issuesTable [][]string
78+
func writeCuration(issues []*github.Issue, pullRequests []*github.PullRequest, commits []*github.RepositoryCommit, outputFile *os.File) error {
79+
// Format at Markdown format
80+
var issuesRows [][]string
8081
for _, issue := range issues {
81-
issuesTable = append(issuesTable, []string{issue.GetTitle(), issue.GetURL(), issue.GetUser().GetLogin()})
82+
issuesRows = append(issuesRows, []string{issue.GetTitle(), issue.GetURL(), issue.GetUser().GetLogin()})
83+
}
84+
issuesTable, err := markdown.NewTableFormatterBuilder().
85+
Build("Title", "Link to issue", "Author").
86+
Format(issuesRows)
87+
if err != nil {
88+
return err
8289
}
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)
8391

84-
markdownTable, err := markdown.NewTableFormatterBuilder().
85-
Build("Title", "Link to Body", "Assignee").
86-
Format(issuesTable)
92+
var pullRequestRows [][]string
93+
for _, pr := range pullRequests {
94+
pullRequestRows = append(pullRequestRows, []string{pr.GetTitle(), pr.GetURL(), pr.GetUser().GetLogin()})
95+
}
96+
pullRequestsTable, err := markdown.NewTableFormatterBuilder().
97+
Build("Title", "Link to PR", "Author").
98+
Format(pullRequestRows)
8799
if err != nil {
88100
return err
89101
}
90-
result := fmt.Sprintf("# Curation\n\nThere is **%d new issues** in gnolang/awesome-gno since %s\n\n%s", len(issues), opts.since, markdownTable)
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)
103+
104+
result += fmt.Sprintf("\n\n## New commits\nThere is **%d new commits** in gnolang/awesome-gno since %s\n\n", len(commits), opts.since)
91105

92106
_, err = outputFile.WriteString(result)
93107
if err != nil {
@@ -98,7 +112,7 @@ func writeCuration(issues []*github.Issue, outputFile *os.File) error {
98112

99113
func writeTips(data string, outputFile *os.File) error {
100114
// Format at Markdown format
101-
var table [][]string
115+
var rows [][]string
102116
var tweets TweetSearch
103117
authors := make(map[string]string)
104118

@@ -107,17 +121,17 @@ func writeTips(data string, outputFile *os.File) error {
107121
authors[user.Id] = user.Username
108122
}
109123
for _, tweet := range tweets.Data {
110-
table = append(table, []string{authors[tweet.AuthorId], strings.Replace(tweet.Text, "\n", " ", -1), tweet.CreatedAt})
124+
rows = append(rows, []string{authors[tweet.AuthorId], strings.Replace(tweet.Text, "\n", " ", -1), tweet.CreatedAt})
111125
}
112126

113127
//Maybe build our own table formatter
114-
markdownTable, err := markdown.NewTableFormatterBuilder().
128+
table, err := markdown.NewTableFormatterBuilder().
115129
Build("Author", "Text", "Created at").
116-
Format(table)
130+
Format(rows)
117131
if err != nil {
118132
return err
119133
}
120-
result := fmt.Sprintf("# Tips\n\nThere is **%d new tweet** about gnotips since %s\n\n%s", tweets.Meta.ResultCount, opts.since, markdownTable)
134+
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)
121135

122136
_, err = outputFile.WriteString(result)
123137
if err != nil {

reporting/reporting.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,20 @@ func fetchCuration(client *github.Client, since time.Time, outputFile *os.File)
145145
if !opts.curation {
146146
return nil
147147
}
148-
issues, err := githubFetchIssues(client, &github.IssueListByRepoOptions{State: "all", Since: since}, "gnolang", "awesome-gno")
148+
issues, err := githubFetchIssues(client, &github.IssueListByRepoOptions{State: "open", Since: since}, "gnolang", "awesome-gno")
149149
if err != nil {
150150
return err
151151
}
152-
err = writeCuration(issues, outputFile)
152+
pullRequests, err := githubFetchPullRequests(client, &github.PullRequestListOptions{State: "closed"}, "gnolang", "awesome-gno")
153+
if err != nil {
154+
return err
155+
}
156+
pullRequestsFiltered := filterPullRequestByTime(pullRequests, since)
157+
commits, err := githubFetchCommits(client, &github.CommitsListOptions{Since: since}, "gnolang", "awesome-gno")
158+
if err != nil {
159+
return err
160+
}
161+
err = writeCuration(issues, pullRequestsFiltered, commits, outputFile)
153162
if err != nil {
154163
return err
155164
}

0 commit comments

Comments
 (0)