Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/docs/ref/proto.mdx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,15 @@ func (alert *Alert) run(ctx context.Context, params *paramsPR, cmd interfaces.Ac
switch cmd {
// Create a review
case interfaces.ActionCmdOn:

event := "COMMENT"
if alert.reviewCfg.GetAction() == "request_changes" {
event = "REQUEST_CHANGES"
}

review := &github.PullRequestReviewRequest{
CommitID: github.String(params.CommitSha),
Event: github.String("COMMENT"),
Event: github.String(event),
Body: github.String(params.Comment),
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func TestPullRequestCommentAlert(t *testing.T) {
actionType engif.ActionType
cmd engif.ActionCmd
reviewMsg string
cfgAction string
inputMetadata *json.RawMessage
mockSetup func(*mockghclient.MockGitHub)
expectedErr error
Expand All @@ -52,6 +53,7 @@ func TestPullRequestCommentAlert(t *testing.T) {
name: "create a PR comment",
actionType: TestActionTypeValid,
reviewMsg: "This is a constant review message",
cfgAction: "comment",
cmd: engif.ActionCmdOn,
mockSetup: func(mockGitHub *mockghclient.MockGitHub) {
mockGitHub.EXPECT().
Expand All @@ -64,6 +66,7 @@ func TestPullRequestCommentAlert(t *testing.T) {
name: "create a PR comment with eval error details template",
actionType: TestActionTypeValid,
reviewMsg: "{{ .EvalErrorDetails }}",
cfgAction: "comment",
cmd: engif.ActionCmdOn,
mockSetup: func(mockGitHub *mockghclient.MockGitHub) {
mockGitHub.EXPECT().
Expand All @@ -76,6 +79,7 @@ func TestPullRequestCommentAlert(t *testing.T) {
name: "create a PR comment with eval result output template",
actionType: TestActionTypeValid,
reviewMsg: "{{ .EvalResultOutput.ViolationMsg }}",
cfgAction: "comment",
cmd: engif.ActionCmdOn,
mockSetup: func(mockGitHub *mockghclient.MockGitHub) {
mockGitHub.EXPECT().
Expand All @@ -88,6 +92,7 @@ func TestPullRequestCommentAlert(t *testing.T) {
name: "error from provider creating PR comment",
actionType: TestActionTypeValid,
reviewMsg: "This is a constant review message",
cfgAction: "comment",
cmd: engif.ActionCmdOn,
mockSetup: func(mockGitHub *mockghclient.MockGitHub) {
mockGitHub.EXPECT().
Expand All @@ -100,6 +105,7 @@ func TestPullRequestCommentAlert(t *testing.T) {
name: "dismiss PR comment",
actionType: TestActionTypeValid,
reviewMsg: "This is a constant review message",
cfgAction: "comment",
cmd: engif.ActionCmdOff,
inputMetadata: &successfulRunMetadata,
mockSetup: func(mockGitHub *mockghclient.MockGitHub) {
Expand All @@ -109,6 +115,24 @@ func TestPullRequestCommentAlert(t *testing.T) {
},
expectedErr: enginerr.ErrActionTurnedOff,
},
{
name: "create a PR review with request_changes action",
actionType: TestActionTypeValid,
reviewMsg: "Security block: please remove binaries",
cfgAction: "request_changes",
cmd: engif.ActionCmdOn,
mockSetup: func(mockGitHub *mockghclient.MockGitHub) {
mockGitHub.EXPECT().
CreateReview(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
DoAndReturn(func(_ context.Context, _, _ string, _ int, review *github.PullRequestReviewRequest) (*github.PullRequestReview, error) {
if review.GetEvent() != "REQUEST_CHANGES" {
return nil, fmt.Errorf("expected event REQUEST_CHANGES, got %s", review.GetEvent())
}
return &github.PullRequestReview{ID: &reviewID}, nil
})
},
expectedMetadata: json.RawMessage(fmt.Sprintf(`{"review_id":"%s"}`, reviewIDStr)),
},
}

for _, tt := range tests {
Expand All @@ -123,6 +147,7 @@ func TestPullRequestCommentAlert(t *testing.T) {

prCommentCfg := pb.RuleType_Definition_Alert_AlertTypePRComment{
ReviewMessage: tt.reviewMsg,
Action: tt.cfgAction,
}

mockClient := mockghclient.NewMockGitHub(ctrl)
Expand Down
3 changes: 3 additions & 0 deletions pkg/api/openapi/minder/v1/minder.swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 14 additions & 5 deletions pkg/api/protobuf/go/minder/v1/minder.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions proto/minder/v1/minder.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2933,6 +2933,12 @@ message RuleType {
},
(google.api.field_behavior) = REQUIRED
];
string action = 2 [
(buf.validate.field).string = {
in: ["comment", "request_changes"],
},
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE
];
}
optional AlertTypePRComment pull_request_comment = 3;
}
Expand Down
Loading