Skip to content

Commit 9f8bc1a

Browse files
authored
Merge pull request #759 from kdeckard/feature/bitbucket-pr-comments-notifications
PR Review Comments Notifications: Fine tuning
2 parents 5aec34c + 7a9202f commit 9f8bc1a

4 files changed

Lines changed: 29 additions & 13 deletions

File tree

bot/config/default.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ var DefaultConfig = Config{
2929
BuildStatusSuccess: false,
3030
BuildStatusFailed: false,
3131
PullRequestStatusMergeable: false,
32-
NewReviewComments: false,
32+
NewReviewComments: NewReviewComments{
33+
Enabled: false,
34+
Repos: nil,
35+
},
3336
},
3437
Reactions: PullRequestReactions{
3538
InReview: "eyes",

bot/config/pull_request.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,20 @@ type PullRequest struct {
1717
// Notifications can be defined in the config.yaml to enable notifications for pull request builds.
1818
// the defaults are defined in default.go
1919
type Notifications struct {
20-
BuildStatusInProgress bool `mapstructure:"build_status_in_progress"`
21-
BuildStatusSuccess bool `mapstructure:"build_status_success"`
22-
BuildStatusFailed bool `mapstructure:"build_status_failed"`
23-
PullRequestStatusMergeable bool `mapstructure:"pr_status_mergeable"`
24-
NewReviewComments bool `mapstructure:"new_review_comments"`
20+
BuildStatusInProgress bool `mapstructure:"build_status_in_progress"`
21+
BuildStatusSuccess bool `mapstructure:"build_status_success"`
22+
BuildStatusFailed bool `mapstructure:"build_status_failed"`
23+
PullRequestStatusMergeable bool `mapstructure:"pr_status_mergeable"`
24+
NewReviewComments NewReviewComments `mapstructure:"new_review_comments"`
25+
}
26+
27+
type NewReviewComments struct {
28+
Enabled bool `mapstructure:"enabled"`
29+
Repos []string `mapstructure:"repos"`
30+
}
31+
32+
func (c NewReviewComments) IsEnabled() bool {
33+
return c.Enabled
2534
}
2635

2736
// PullRequestReactions can be defined in the config.yaml to have custom reactions for pull requests.

command/pullrequest/bitbucket.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,14 @@ func (c *bitbucketFetcher) getPullRequest(match matcher.Result, config *config.P
8282

8383
var latestCommentTimestamp int64
8484

85-
if config.Notifications.NewReviewComments {
86-
latestCommentTimestamp, err = c.getLatestReviewCommentTimestamp(&rawPullRequest)
87-
if err != nil {
88-
return pr, errors.Wrap(err, "error while loading review comments from Bitbucket")
85+
if config.Notifications.NewReviewComments.IsEnabled() {
86+
newCommentsEnabledForRepo := slices.Contains(config.Notifications.NewReviewComments.Repos, repo)
87+
88+
if newCommentsEnabledForRepo {
89+
latestCommentTimestamp, err = c.getLatestReviewCommentTimestamp(&rawPullRequest)
90+
if err != nil {
91+
return pr, errors.Wrap(err, "error while loading review comments from Bitbucket")
92+
}
8993
}
9094
}
9195

command/pullrequest/pull_request.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,15 +378,15 @@ func (c command) GetHelp() []bot.Help {
378378
}
379379

380380
func (c *command) notifyNewReviewComments(prw *pullRequestWatch) {
381-
if !c.cfg.Notifications.NewReviewComments {
381+
if !c.cfg.Notifications.NewReviewComments.IsEnabled() || prw.DidNotifyMergeable {
382382
return
383383
}
384384

385-
if prw.PullRequest.LatestReviewCommentsTimestamp <= prw.SavedLatestReviewCommentTimestamp || prw.PullRequest.LatestReviewCommentsTimestamp == 0 {
385+
if prw.PullRequest.LatestReviewCommentsTimestamp == 0 || prw.PullRequest.LatestReviewCommentsTimestamp <= prw.SavedLatestReviewCommentTimestamp {
386386
return
387387
}
388388

389389
prw.SavedLatestReviewCommentTimestamp = prw.PullRequest.LatestReviewCommentsTimestamp
390390

391-
c.sendPrivateMessage(prw.Author, "PR '%s' \nNew review comments were added: %s", prw.PullRequest.Name, getPRLinkMessage(prw))
391+
c.sendPrivateMessage(prw.PullRequest.Author, "PR *'%s'* \nNew review comments were added: %s", prw.PullRequest.Name, getPRLinkMessage(prw))
392392
}

0 commit comments

Comments
 (0)