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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support automatically merging PRs that don't affect target clusters #6

Merged
merged 3 commits into from
May 15, 2024
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
4 changes: 4 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ Configuration keys:
|`dryRunMode`| if true, the bot will just comment the planned promotion on the merged PR|
|`autoApprovePromotionPrs`| if true the bot will auto-approve all promotion PRs, with the assumption the original PR was peer reviewed and is promoted verbatim. Required additional GH token via APPROVER_GITHUB_OAUTH_TOKEN env variable|
|`toggleCommitStatus`| Map of strings, allow (non-repo-admin) users to change the [Github commit status](https://docs.github.com/en/rest/commits/statuses) state(from failure to success and back). This can be used to continue promotion of a change that doesn't pass repo checks. the keys are strings commented in the PRs, values are [Github commit status context](https://docs.github.com/en/rest/commits/statuses?apiVersion=2022-11-28#create-a-commit-status) to be overridden|
|`commentArgocdDiffonPR`| Uses ArgoCD API to calculate expected changes to k8s state and comment the resulting "diff" as comment in the PR. Requires ARGOCD_* environment variables, see below. |
|`autoMergeNoDiffPRs`| if true, Telefonistka will **merge** promotion PRs that are not expected to change the target clusters. Requires `commentArgocdDiffonPR` and possibly `autoApprovePromotionPrs`(depending on repo branch protection rules)|
<!-- markdownlint-enable MD033 -->

Example:
Expand Down Expand Up @@ -159,6 +161,8 @@ promotionPaths:
- "clusters/prod/us-east4/c2"
dryRunMode: true
autoApprovePromotionPrs: true
commentArgocdDiffonPR: true
autoMergeNoDiffPRs: true
toggleCommitStatus:
override-terrafrom-pipeline: "github-action-terraform"
```
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/configuration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Config struct {
ToggleCommitStatus map[string]string `yaml:"toggleCommitStatus"`
WebhookEndpointRegexs []WebhookEndpointRegex `yaml:"webhookEndpointRegexs"`
CommentArgocdDiffonPR bool `yaml:"commentArgocdDiffonPR"`
AutoMergeNoDiffPRs bool `yaml:"autoMergeNoDiffPRs"`
}

func ParseConfigFromYaml(y string) (*Config, error) {
Expand Down
9 changes: 8 additions & 1 deletion internal/pkg/githubapi/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,14 @@ func HandlePREvent(eventPayload *github.PullRequestEvent, ghPrClientDetails GhPr
} else {
ghPrClientDetails.PrLogger.Debugf("PR %v labeled\n%+v", *eventPayload.PullRequest.Number, prLables)
}
// TODO Auto-merge PRs with no changes(optional)
sunchill06 marked this conversation as resolved.
Show resolved Hide resolved
if DoesPrHasLabel(*eventPayload, "promotion") && config.AutoMergeNoDiffPRs {
ghPrClientDetails.PrLogger.Infof("Auto-merging (no diff) PR %d", *eventPayload.PullRequest.Number)
err := MergePr(ghPrClientDetails, eventPayload.PullRequest.Number)
if err != nil {
prHandleError = err

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought but non blocking for this, I see this is following convention below but would be shadowed if errors happens there. Could potentially use errors.Join or refactor to avoid it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errors.Join == mind blown :)
I'll merge as is because I do log the errors so they are not completely lost but yeah, keeping them all is definitely better

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:0 I didn't even know about errors.Join

TechTime on error wrapping would definitely be killer. ErrorWrapping isn't something I've really picked up. I do love being able to use errors.Is for error pathing.

ghPrClientDetails.PrLogger.Errorf("PR auto merge failed: err=%v", err)
}
}
}
}

Expand Down
Loading