Skip to content

Commit

Permalink
Merge pull request openshift#609 from markmc/tools-all-comments
Browse files Browse the repository at this point in the history
tools: include standard comments in PR activity count
  • Loading branch information
openshift-merge-robot authored Jan 27, 2021
2 parents 3c258f7 + d25f8e9 commit f954bfe
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 21 deletions.
8 changes: 8 additions & 0 deletions tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ go run ./report/main.go

There are command line options to control the range of time
scanned. Use the `-h` option to see the help.

You need to create a `~/.config/ocp-enhancements/config.yml`
containing a [personal access token](https://github.com/settings/tokens):

```yaml
github:
token: "deadbeefdeadbeefdeadbeefdeadbeef"
```
91 changes: 70 additions & 21 deletions tools/stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,26 @@ type GithubClientSource func() *github.Client
// PullRequestDetails includes the PullRequest and some supplementary
// data
type PullRequestDetails struct {
Pull *github.PullRequest
Reviews []*github.PullRequestReview
RecentReviewCount int
Comments []*github.PullRequestComment
RecentCommentCount int
Pull *github.PullRequest

// These are groups of comments, submited with a review action
Reviews []*github.PullRequestReview
RecentReviewCount int

// These are "review comments", associated with a diff
PullRequestComments []*github.PullRequestComment
RecentPRCommentCount int

// PRs are also issues, so these are the standard comments
IssueComments []*github.IssueComment
RecentIssueCommentCount int

RecentActivityCount int
AllActivityCount int
State string
LGTM bool
Prioritized bool

State string
LGTM bool
Prioritized bool
}

// New creates a new Stats implementation
Expand Down Expand Up @@ -120,7 +130,34 @@ func (s *Stats) IteratePullRequests() error {
return nil
}

func (s *Stats) getComments(pr *github.PullRequest) ([]*github.PullRequestComment, error) {
func (s *Stats) getIssueComments(pr *github.PullRequest) ([]*github.IssueComment, error) {
c := s.clientSource()
ctx := context.Background()
opts := &github.IssueListCommentsOptions{
Since: &s.earliestDate,
ListOptions: github.ListOptions{
PerPage: pageSize,
},
}
results := []*github.IssueComment{}

for {
comments, response, err := c.Issues.ListComments(
ctx, s.org, s.repo, *pr.Number, opts)
if err != nil {
return nil, err
}
results = append(results, comments...)
if response.NextPage == 0 {
break
}
opts.Page = response.NextPage
}

return results, nil
}

func (s *Stats) getPRComments(pr *github.PullRequest) ([]*github.PullRequestComment, error) {
c := s.clientSource()
ctx := context.Background()
opts := &github.PullRequestListCommentsOptions{
Expand Down Expand Up @@ -185,10 +222,16 @@ func (s *Stats) makeDetails(pr *github.PullRequest) (*PullRequestDetails, error)
fmt.Sprintf("could not determine merged status of %s", *pr.HTMLURL))
}

comments, err := s.getComments(pr)
issueComments, err := s.getIssueComments(pr)
if err != nil {
return nil, errors.Wrap(err,
fmt.Sprintf("could not fetch issue comments on %s", *pr.HTMLURL))
}

prComments, err := s.getPRComments(pr)
if err != nil {
return nil, errors.Wrap(err,
fmt.Sprintf("could not fetch comments on %s", *pr.HTMLURL))
fmt.Sprintf("could not fetch PR comments on %s", *pr.HTMLURL))
}

reviews, err := s.getReviews(pr)
Expand All @@ -209,12 +252,13 @@ func (s *Stats) makeDetails(pr *github.PullRequest) (*PullRequestDetails, error)
}

details := &PullRequestDetails{
Pull: pr,
State: *pr.State,
Comments: comments,
Reviews: reviews,
LGTM: lgtm,
Prioritized: prioritized,
Pull: pr,
State: *pr.State,
IssueComments: issueComments,
PullRequestComments: prComments,
Reviews: reviews,
LGTM: lgtm,
Prioritized: prioritized,
}
if isMerged {
details.State = "merged"
Expand All @@ -224,13 +268,18 @@ func (s *Stats) makeDetails(pr *github.PullRequest) (*PullRequestDetails, error)
details.RecentReviewCount++
}
}
for _, c := range comments {
for _, c := range issueComments {
if c.CreatedAt.After(s.earliestDate) {
details.RecentIssueCommentCount++
}
}
for _, c := range prComments {
if c.CreatedAt.After(s.earliestDate) {
details.RecentCommentCount++
details.RecentPRCommentCount++
}
}
details.RecentActivityCount = details.RecentCommentCount + details.RecentReviewCount
details.AllActivityCount = len(details.Comments) + len(details.Reviews)
details.RecentActivityCount = details.RecentIssueCommentCount + details.RecentPRCommentCount + details.RecentReviewCount
details.AllActivityCount = len(details.IssueComments) + len(details.PullRequestComments) + len(details.Reviews)
return details, nil
}

Expand Down

0 comments on commit f954bfe

Please sign in to comment.