Skip to content

Commit

Permalink
Support automatically merging PRs that don't affect target clusters (#6)
Browse files Browse the repository at this point in the history
* Support automaticallyh merging PRs that don't affect target clusters

* Update docs/installation.md

Co-authored-by: Sunil Aggarwal <[email protected]>
  • Loading branch information
Oded-B and sunchill06 authored May 15, 2024
1 parent 7c9c205 commit 7f33a8b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
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)
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
ghPrClientDetails.PrLogger.Errorf("PR auto merge failed: err=%v", err)
}
}
}
}

Expand Down

0 comments on commit 7f33a8b

Please sign in to comment.