Skip to content

Commit 9b33704

Browse files
authored
react on comment in pr with digger commands (#1496)
* react on digger comment
1 parent 48c6522 commit 9b33704

File tree

11 files changed

+67
-1
lines changed

11 files changed

+67
-1
lines changed

backend/controllers/github.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
607607
cloneURL := *payload.Repo.CloneURL
608608
issueNumber := *payload.Issue.Number
609609
isDraft := payload.Issue.GetDraft()
610+
commentId := *payload.GetComment().ID
610611

611612
link, err := models.DB.GetGithubAppInstallationLink(installationId)
612613
if err != nil {
@@ -631,6 +632,11 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
631632
return fmt.Errorf("error getting digger config")
632633
}
633634

635+
err = ghService.CreateCommentReaction(commentId, string(dg_github.GithubCommentEyesReaction))
636+
if err != nil {
637+
log.Printf("CreateCommentReaction error: %v", err)
638+
}
639+
634640
if !config.AllowDraftPRs && isDraft {
635641
log.Printf("AllowDraftPRs is enabled, skipping PR: %v", issueNumber)
636642
return nil

cli/pkg/azure/azure.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ func (a *AzureReposService) EditComment(prNumber int, id interface{}, comment st
339339
return err
340340
}
341341

342+
func (a *AzureReposService) CreateCommentReaction(id interface{}, reaction string) error {
343+
// TODO implement me
344+
return nil
345+
}
346+
342347
func (a *AzureReposService) GetBranchName(prNumber int) (string, error) {
343348
//TODO implement me
344349
return "", nil

cli/pkg/bitbucket/bitbucket.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ func (b BitbucketAPI) EditComment(prNumber int, id interface{}, comment string)
157157
return nil
158158
}
159159

160+
func (a BitbucketAPI) CreateCommentReaction(id interface{}, reaction string) error {
161+
// TODO implement me
162+
return nil
163+
}
164+
160165
type Comment struct {
161166
Size int `json:"size"`
162167
Page int `json:"page"`

cli/pkg/digger/digger_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ func (m *MockPRManager) EditComment(prNumber int, id interface{}, comment string
143143
return nil
144144
}
145145

146+
func (m *MockPRManager) CreateCommentReaction(id interface{}, reaction string) error {
147+
m.Commands = append(m.Commands, RunInfo{"EditComment", strconv.Itoa(id.(int)) + " " + reaction, time.Now()})
148+
return nil
149+
}
150+
146151
func (m *MockPRManager) GetBranchName(prNumber int) (string, error) {
147152
m.Commands = append(m.Commands, RunInfo{"GetBranchName", strconv.Itoa(prNumber), time.Now()})
148153
return "", nil

cli/pkg/gitlab/gitlab.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ func (gitlabService GitLabService) EditComment(prNumber int, id interface{}, com
243243
return nil
244244
}
245245

246+
func (gitlabService GitLabService) CreateCommentReaction(id interface{}, reaction string) error {
247+
// TODO implement me
248+
return nil
249+
}
250+
246251
func (gitlabService GitLabService) GetComments(prNumber int) ([]orchestrator.Comment, error) {
247252
//TODO implement me
248253
return nil, nil

cli/pkg/reporting/reporting_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ func (t MockCiService) EditComment(prNumber int, commentId interface{}, comment
9393
return nil
9494
}
9595

96-
func (t MockCiService) GetBranchName(prNumber int) (string, error) {
96+
func (svc MockCiService) CreateCommentReaction(id interface{}, reaction string) error {
97+
// TODO implement me
98+
return nil
99+
}
100+
101+
func (svc MockCiService) GetBranchName(prNumber int) (string, error) {
97102
return "", nil
98103
}
99104

cli/pkg/utils/mocks.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ func (t MockPullRequestManager) EditComment(prNumber int, commentId interface{},
127127
return nil
128128
}
129129

130+
func (t *MockPullRequestManager) CreateCommentReaction(id interface{}, reaction string) error {
131+
return nil
132+
}
133+
130134
func (t MockPullRequestManager) GetBranchName(prNumber int) (string, error) {
131135
return "", nil
132136
}

cli/pkg/utils/pullrequestmanager_mock.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ func (mockGithubPullrequestManager *MockGithubPullrequestManager) EditComment(pr
104104
return nil
105105
}
106106

107+
func (mockGithubPullrequestManager *MockGithubPullrequestManager) CreateCommentReaction(id interface{}, reaction string) error {
108+
mockGithubPullrequestManager.commands = append(mockGithubPullrequestManager.commands, "CreateCommentReaction")
109+
return nil
110+
}
111+
107112
func (mockGithubPullrequestManager *MockGithubPullrequestManager) GetBranchName(prNumber int) (string, error) {
108113
mockGithubPullrequestManager.commands = append(mockGithubPullrequestManager.commands, "GetBranchName")
109114
return "", nil

libs/orchestrator/ci.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type PullRequestService interface {
66
ListIssues() ([]*Issue, error)
77
PublishIssue(title string, body string) (int64, error)
88
EditComment(prNumber int, id interface{}, comment string) error
9+
CreateCommentReaction(id interface{}, reaction string) error
910
GetComments(prNumber int) ([]Comment, error)
1011
GetApprovals(prNumber int) ([]string, error)
1112
// SetStatus set status of specified pull/merge request, status could be: "pending", "failure", "success"

libs/orchestrator/github/github.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,26 @@ func (svc GithubService) EditComment(prNumber int, id interface{}, comment strin
172172
return err
173173
}
174174

175+
type GithubCommentReaction string
176+
177+
const GithubCommentPlusOneReaction GithubCommentReaction = "+1"
178+
const GithubCommentMinusOneReaction GithubCommentReaction = "-1"
179+
const GithubCommentLaughReaction GithubCommentReaction = "laugh"
180+
const GithubCommentConfusedReaction GithubCommentReaction = "confused"
181+
const GithubCommentHeartReaction GithubCommentReaction = "heart"
182+
const GithubCommentHoorayReaction GithubCommentReaction = "hooray"
183+
const GithubCommentRocketReaction GithubCommentReaction = "rocket"
184+
const GithubCommentEyesReaction GithubCommentReaction = "eyes"
185+
186+
func (svc GithubService) CreateCommentReaction(id interface{}, reaction string) error {
187+
_, _, err := svc.Client.Reactions.CreateIssueCommentReaction(context.Background(), svc.Owner, svc.RepoName, id.(int64), reaction)
188+
if err != nil {
189+
log.Printf("could not addd reaction to comment: %v", err)
190+
return fmt.Errorf("could not addd reaction to comment: %v", err)
191+
}
192+
return nil
193+
}
194+
175195
func (svc GithubService) SetStatus(prNumber int, status string, statusContext string) error {
176196
pr, _, err := svc.Client.PullRequests.Get(context.Background(), svc.Owner, svc.RepoName, prNumber)
177197
if err != nil {

libs/orchestrator/github/mocks.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ func (t MockCiService) EditComment(prNumber int, commentId interface{}, comment
9393
return nil
9494
}
9595

96+
func (t MockCiService) CreateCommentReaction(id interface{}, reaction string) error {
97+
// TODO implement me
98+
return nil
99+
}
100+
96101
func (t MockCiService) GetBranchName(prNumber int) (string, error) {
97102
return "", nil
98103
}

0 commit comments

Comments
 (0)