Skip to content

Commit

Permalink
chore: only comment if it doesn't already exist
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanGoasdoue committed Feb 2, 2024
1 parent 9f14387 commit 5728dcc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pkg/plugins/trigger/pull-request.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,25 @@ func welcomeMsgForDraftPR(spc scmProviderClient, trigger *plugins.Trigger, pr sc
}
}

if err := spc.CreateComment(org, repo, pr.Number, true, comment); err != nil {
comments, err := spc.ListPullRequestComments(org, repo, pr.Number)
if err != nil {
errors = append(errors, err)
}

toComment := true
for _, c := range comments {
if c.Body == comment {
toComment = false
break
}
}

if toComment {
if err := spc.CreateComment(org, repo, pr.Number, true, comment); err != nil {
errors = append(errors, err)
}
}

if len(errors) > 0 {
return errorutil.NewAggregate(errors...)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/plugins/trigger/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ type scmProviderClient interface {
GetPullRequest(org, repo string, number int) (*scm.PullRequest, error)
GetRef(org, repo, ref string) (string, error)
CreateComment(owner, repo string, number int, pr bool, comment string) error
ListPullRequestComments(org, repo string, number int) ([]*scm.Comment, error)
ListIssueComments(owner, repo string, issue int) ([]*scm.Comment, error)
CreateStatus(org, repo, ref string, s *scm.StatusInput) (*scm.Status, error)
GetCombinedStatus(org, repo, ref string) (*scm.CombinedStatus, error)
Expand Down

0 comments on commit 5728dcc

Please sign in to comment.