Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: merge and fail check run messages #899

Merged
merged 2 commits into from
May 22, 2023
Merged
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
2 changes: 1 addition & 1 deletion plugins/aladino/actions/failCheckStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func failCheckStatusCode(e aladino.Env, args []aladino.Value) error {
Status: github.String("completed"),
Conclusion: github.String("failure"),
Output: &github.CheckRunOutput{
Title: github.String("Reviewpad policy failed"),
Title: github.String("Reviewpad failed"),
Summary: github.String(summary.String()),
},
})
Expand Down
32 changes: 22 additions & 10 deletions plugins/aladino/actions/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func Merge() *aladino.BuiltInAction {

func mergeCode(e aladino.Env, args []aladino.Value) error {
t := e.GetTarget().(*target.PullRequestTarget)
targetEntity := e.GetTarget().GetTargetEntity()
log := e.GetLogger().WithField("builtin", "merge")

if t.PullRequest.Status != pbc.PullRequestStatus_OPEN || t.PullRequest.IsDraft {
Expand All @@ -43,28 +42,41 @@ func mergeCode(e aladino.Env, args []aladino.Value) error {

if e.GetCheckRunID() != nil {
e.SetCheckRunConclusion("success")
_, _, 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("success"),
Output: &github.CheckRunOutput{
Title: github.String("Reviewpad about to merge"),
Summary: github.String("Reviewpad is about to merge this pull request."),
},
})
err := updateCheckRunWithSummary(e, "Reviewpad is about to merge this pull request")
if err != nil {
return err
}
}

mergeErr := t.Merge(mergeMethod)
if mergeErr != nil {
if e.GetCheckRunID() != nil {
err := updateCheckRunWithSummary(e, "The merge cannot be completed due to non-compliance with certain GitHub branch protection rules")
if err != nil {
return err
}
}

e.GetLogger().WithError(mergeErr).Warnln("failed to merge pull request")
}

return nil
}

func updateCheckRunWithSummary(e aladino.Env, summary string) error {
targetEntity := e.GetTarget().GetTargetEntity()
_, _, 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("success"),
Output: &github.CheckRunOutput{
Title: github.String("Reviewpad about to merge"),
Summary: github.String(summary),
},
})
return err
}

func parseMergeMethod(args []aladino.Value) (string, error) {
if len(args) == 0 {
return "merge", nil
Expand Down
Loading