-
Notifications
You must be signed in to change notification settings - Fork 31
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
feat: merge and fail should update check run status #876
Conversation
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.
Thanks for this @zolamk
Can you please share what was the rationale for providing Reviewpad with the check id instead of the check itself?
My understanding was to provide the check itself as an interface that could provide the required methods to update it. The proposed way binds the check to GitHub and disables the ability to easily work for different code hosts.
What is your understanding of this?
The check run id is an integer both in github and gitlabs case, that's why I am passing the id to reviewpad and then the host service could implement a set of calls to work with check runs |
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.
Some checks are failing. Please fix them.
Status: github.String("completed"), | ||
Conclusion: github.String("success"), | ||
Output: &github.CheckRunOutput{ | ||
Title: github.String("Reviewpad about to merge"), |
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 about Reviewpad Merge Notification
?
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.
@fmallet what do you think the title of the check run output should when the merge
built-in is about to merge the pull request
Pull request is not up to date with the base branch. Reviewpad will rebase it. After the rebase, please trigger Reviewpad by running the command |
7199b51
to
93e88e3
Compare
/reviewpad run |
93e88e3
to
f74f055
Compare
/reviewpad summarize |
@marcelosousa an error occurred running your command Errors:
|
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.
The pull request has git conflicts. Please fix them.
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.
Pull request is not rebaseable. Please rebase it manually.
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.
Pull request is not rebaseable. Please rebase it manually.
510a095
to
6035364
Compare
Pull request is not up to date with the base branch. Reviewpad will rebase it. After the rebase, please trigger Reviewpad by running the command |
1 similar comment
Pull request is not up to date with the base branch. Reviewpad will rebase it. After the rebase, please trigger Reviewpad by running the command |
7c8e15b
to
a2ce912
Compare
if e.GetCheckRunID() != nil { | ||
e.SetCheckRunConclusion("failure") | ||
|
||
summary := strings.Builder{} | ||
|
||
for _, msg := range e.GetBuiltInsReportedMessages()[aladino.SEVERITY_FAIL] { | ||
summary.WriteString(fmt.Sprintf("- %s\n", msg)) | ||
} | ||
|
||
_, _, err := e.GetGithubClient().GetClientREST().Checks.UpdateCheckRun(e.GetCtx(), targetEntity.Owner, targetEntity.Repo, *e.GetCheckRunID(), github.UpdateCheckRunOptions{ | ||
Name: "reviewpad", | ||
Status: github.String("completed"), | ||
Conclusion: github.String("failure"), | ||
Output: &github.CheckRunOutput{ | ||
Title: github.String("Reviewpad policy failed"), | ||
Summary: github.String(summary.String()), | ||
}, | ||
}) | ||
return err | ||
} |
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.
/reviewpad explain
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.
This code checks if the current environment has a non-nil CheckRunID. If it does, it sets the check run conclusion to "failure" and constructs a summary of all the reported messages with a severity of "fail." Then, using the available GithubClient, it updates the check run with the required info, such as name, status, conclusion, and output. This section is responsible for updating the check run on the Github platform to reflect the policy failure and its reason.
@@ -23,6 +24,7 @@ func Merge() *aladino.BuiltInAction { | |||
|
|||
func mergeCode(e aladino.Env, args []aladino.Value) error { |
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.
/reviewpad explain
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.
This line defines a function called mergeCode
with two parameters, an aladino.Env
object named e
and a slice of aladino.Value
objects named args
. The function returns an error value.
The mergeCode
function is responsible for performing a merge in the context of a built-in action handler in the Reviewpad application. It fetches the target entity and checks the status of the pull request. If it's not open or is a draft, the function logs a message and returns early with a nil
error. The function then parses the merge method from the provided arguments and checks if there are any failures reported by built-in checks. If all conditions are met, the function updates the check-run with a success status and proceeds to perform the merge using the desired merge method, logging a warning message if the merge fails.
} | ||
|
||
defer config.CleanupPluginConfig() | ||
|
||
aladinoInterpreter, err := aladino.NewInterpreter(ctx, log, dryRun, gitHubClient, codeHostClient, collector, targetEntity, eventDetails.Payload, plugins_aladino.PluginBuiltInsWithConfig(config)) | ||
aladinoInterpreter, err := aladino.NewInterpreter(ctx, log, dryRun, gitHubClient, codeHostClient, collector, targetEntity, eventDetails.Payload, plugins_aladino.PluginBuiltInsWithConfig(config), checkRunId) |
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.
/reviewpad explain
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.
This line creates a new instance of the Aladino interpreter by calling the aladino.NewInterpreter
function and passing in several arguments which include the context, logger, dry-run flag, GitHub client, code host client, collector, target entity, payload from the event details, built-ins from the plugin configuration, and the check run ID. The Aladino interpreter is responsible for executing a given program and reporting the results.
/reviewpad run |
/reviewpad run |
The merge is blocked by the label |
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.
Pull request is ready to be merged. Reviewpad will merge it for you.
Description
In order to support merge policies the
$merge
and$fail
built-ins need to be able to set the status of the check run, this pull request updates reviewpad so that it receives a check run id that the built-ins can use to control the status of the check.🤖 Generated by Copilot at b5f2400
This pull request adds support for GitHub check runs for reviewpad policies. It modifies the
lang/aladino
package and its plugins to handle check run IDs, conclusions, and outputs in the interpreter and the built-in functions. It also updates therunner.go
file and theengine
package to pass and return the check run information. It adjusts the test files and thecli
package to reflect the changes in the function signatures.Closes #874
Code review and merge strategy
Ask: this pull request requires a code review before merge
How
🤖 Generated by Copilot at b5f2400
checkRunId
to theRun
function signature in therunner.go
file and pass it to therunReviewpadFile
andrunReviewpadCommand
functions (link, link)checkRunId
to therunReviewpadFile
function signature in therunner.go
file and pass it to theNewInterpreter
function in thelang/aladino
package (link)checkRunId
to therunReviewpadCommand
function signature in therunner.go
file and pass it to therunReviewpadCommandDryRun
function (link)checkRunId
to therunReviewpadCommandDryRun
function signature in therunner.go
file and pass it to thereviewpad.Run
function in thecli
package (link)checkRunId
to thereviewpad.Run
function signature in thecli
package and pass it to theNewInterpreter
function in theengine
package (link)checkRunId
to theNewInterpreter
function signature in theengine
package and pass it to theNewEvalEnv
function in thelang/aladino
package (link)checkRunId
to theNewEvalEnv
function signature in thelang/aladino
package and assign it to theCheckRunID
field of theBaseEnv
struct (link, link)CheckRunID
andCheckRunConclusion
to theBaseEnv
struct in thelang/aladino
package to store the check run ID and conclusion that correspond to the aladino interpreter's execution (link)GetCheckRunID
,SetCheckRunConclusion
, andGetCheckRunConclusion
to theEnv
interface in thelang/aladino
package to access and modify the check run ID and conclusion (link)GetCheckRunID
,SetCheckRunConclusion
, andGetCheckRunConclusion
methods for theBaseEnv
struct in thelang/aladino
package (link, link)GetCheckRunConclusion
method for theInterpreter
struct in thelang/aladino
package to return the check run conclusion from the aladino environment (link)GetCheckRunConclusion
to theInterpreter
interface in theengine
package to return the conclusion of the check run that corresponds to the interpreter's execution (link)runReviewpadFile
function in therunner.go
file to return the check run conclusion from the aladino interpreter as the third value (link, link, link, link, link, link, link)runReviewpadCommandDryRun
function in therunner.go
file to return an empty string as the third value, which corresponds to the check run conclusion (link, link, link)runReviewpadCommand
function in therunner.go
file to return an empty string as the third value, which corresponds to the check run conclusion (link, link, link)Run
method of theInterpreter
struct in thelang/aladino
package, as the fatal errors are handled by thefail
built-in function (link)failCode
function in theplugins/aladino/actions/fail.go
file to set the check run conclusion to "failure" and update the check run status and output with the fatal messages from the aladino environment, if the check run ID is not nil (link)mergeCode
function in theplugins/aladino/actions/merge.go
file to set the check run conclusion to "success" and update the check run status and output with a success message, if the check run ID is not nil and there are no fatal messages from the aladino environment (link)plugins/aladino/actions/fail.go
andplugins/aladino/actions/merge.go
files for the new logic that updates the check run status and output (link, link)targetEntity
to themergeCode
function in theplugins/aladino/actions/merge.go
file to hold the target entity information for the check run output (link)nil
to theNewInterpreter
function calls in the test functions in thelang/aladino
package, which corresponds to thecheckRunID
parameter that was added to theNewInterpreter
function signature (link, link, link)nil
to theNewEvalEnv
function calls in the test functions in thelang/aladino
package, which corresponds to thecheckRunID
parameter that was added to theNewEvalEnv
function signature (link, link, link, link)nil
to theNewInterpreter
function call in themockEnvWith
function in thelang/aladino
package, which corresponds to thecheckRunID
parameter that was added to theNewInterpreter
function signature (link)nil
to themockAladinoInterpreter
function call in theengine
package, which corresponds to thecheckRunId
parameter that was added to theNewInterpreter
function signature (link)