-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unified PR machinery for actions like pull request comment #5223
base: main
Are you sure you want to change the base?
Conversation
type minderTemplateData struct { | ||
MagicComment string | ||
Body string | ||
} |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.ParseInt
Incorrect conversion of a signed 64-bit integer from
strconv.ParseInt
|
||
ic, err := c.CreateIssueComment(ctx, owner, repoName, | ||
// TODO: overflow | ||
int(prNumber), body) |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.ParseInt
Incorrect conversion of a signed 64-bit integer from
strconv.ParseInt
|
||
func (c *GitHub) createReview( | ||
ctx context.Context, comment provifv1.PullRequestCommentInfo, mci magicCommentInfo, | ||
owner, repoName string, prNumber int64, commitSha string, |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.ParseInt
Incorrect conversion of a signed 64-bit integer from
strconv.ParseInt
// TODO: overflow | ||
r, err := c.CreateReview(ctx, owner, repoName, int(prNumber), review) | ||
if err != nil { | ||
return mci, fmt.Errorf("could not create review: %w", err) |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types High
strconv.ParseInt
Incorrect conversion of a signed 64-bit integer from
strconv.ParseInt
This allows for providers to comment on pull requests Signed-off-by: Juan Antonio Osorio <[email protected]>
This shared space will allow actions to gather structures or results that will allow it to aggregate and flush. In more solid terms, we'd be able to aggregate PR comments, iterate them, and issue just one big comment. Signed-off-by: Juan Antonio Osorio <[email protected]>
Signed-off-by: Juan Antonio Osorio <[email protected]>
Signed-off-by: Juan Antonio Osorio <[email protected]>
Signed-off-by: Juan Antonio Osorio <[email protected]>
Signed-off-by: Juan Antonio Osorio <[email protected]>
Signed-off-by: Juan Antonio Osorio <[email protected]>
fb5d46d
to
96be386
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First few comments while I keep reviewing the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: given this is Go, I'm not really fond of this approach and would rather replace this with templates which are, for better or worse, more idiomatic. No need to change this now, I'm just sharing a thought.
sac.ShareAndRegister("pull_request_comment", | ||
newAlertFlusher(params.props, params.props.GetProperty(properties.PullRequestCommitSHA).GetString(), alert.commenter), | ||
&provifv1.PullRequestCommentInfo{ | ||
Header: params.Title, | ||
Commit: params.props.GetProperty(properties.PullRequestCommitSHA).GetString(), | ||
Body: params.Comment, | ||
// TODO: Determine the priority from the rule type severity | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: ShareAndRegister
adds an alertFlusher
to its internal list kept under "pull_request_comment"
in this case, which is the only key used.
Why does that need to be a map? What other uses can it have?
// Ensure predictable ordering | ||
// TODO: This should be sorted by severity | ||
slices.Sort(alerts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: how is stable ordering guaranteed between two runs?
I assume the main ordering key is actually fp.Header
, and if two alerts have the same header then sorting goes further into the string to sort by whatever comes next.
If my reasoning is correct, this might warrant a longer comment explaining how we expect this comment to be "stable".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: was this code ported from other source files? Are there any tests somewhere else?
// SPDX-FileCopyrightText: Copyright 2023 The Minder Authors | ||
// SPDX-License-Identifier: Apache-2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// SPDX-FileCopyrightText: Copyright 2023 The Minder Authors | |
// SPDX-License-Identifier: Apache-2.0 | |
// SPDX-FileCopyrightText: Copyright 2025 The Minder Authors | |
// SPDX-License-Identifier: Apache-2.0 |
// SPDX-FileCopyrightText: Copyright 2023 The Minder Authors | ||
// SPDX-License-Identifier: Apache-2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// SPDX-FileCopyrightText: Copyright 2023 The Minder Authors | |
// SPDX-License-Identifier: Apache-2.0 | |
// SPDX-FileCopyrightText: Copyright 2025 The Minder Authors | |
// SPDX-License-Identifier: Apache-2.0 |
// SPDX-FileCopyrightText: Copyright 2024 The Minder Authors | ||
// SPDX-License-Identifier: Apache-2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// SPDX-FileCopyrightText: Copyright 2024 The Minder Authors | |
// SPDX-License-Identifier: Apache-2.0 | |
// SPDX-FileCopyrightText: Copyright 2025 The Minder Authors | |
// SPDX-License-Identifier: Apache-2.0 |
} | ||
|
||
return nil, fmt.Errorf("unknown alert type: %s", alertCfg.GetType()) | ||
} | ||
|
||
func defaultName(ruletype *pb.RuleType) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you rely on this to be unique now or at some point? Asking because I think we don't conflict on display_name
clashes but name only.
logger.Info().Str("review_id", params.Metadata.ReviewID).Msg("PR comment dismissed") | ||
// Success - return ErrActionTurnedOff to indicate the action was successful | ||
return nil, fmt.Errorf("%s : %w", alert.Class(), enginerr.ErrActionTurnedOff) | ||
return json.RawMessage(`{}`), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would this do in the case where there was a previous evaluation where one or more rules failed and Minder made a comment, but now it's all good?
case interfaces.ActionCmdDoNothing: | ||
// Return the previous alert status. | ||
// If the previous status didn't change (still a failure, for instance) we |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you share what's the use case you have mind for this?
} | ||
|
||
// This was a successful result, so we don't need to alert | ||
if !params.shouldAlert { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to check for this here? My understanding is the shouldAlert
flag is used to tell what the alert command should be.
Summary
This adds all the needed machinery and implementation to create a unified actions result. This is specially useful for aggregating results from different alerts such as pull_request_comment.
I tried doing it in separate PRs... see #5188 & #5182 but this proved challenging. So now it's all here.
Change Type
Mark the type of change your PR introduces:
Testing
Outline how the changes were tested, including steps to reproduce and any relevant configurations.
Attach screenshots if helpful.
Review Checklist: