Skip to content

Commit 7f33a8b

Browse files
Oded-Bsunchill06
andauthored
Support automatically merging PRs that don't affect target clusters (#6)
* Support automaticallyh merging PRs that don't affect target clusters * Update docs/installation.md Co-authored-by: Sunil Aggarwal <[email protected]>
1 parent 7c9c205 commit 7f33a8b

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

docs/installation.md

+4
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ Configuration keys:
117117
|`dryRunMode`| if true, the bot will just comment the planned promotion on the merged PR|
118118
|`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|
119119
|`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|
120+
|`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. |
121+
|`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)|
120122
<!-- markdownlint-enable MD033 -->
121123

122124
Example:
@@ -159,6 +161,8 @@ promotionPaths:
159161
- "clusters/prod/us-east4/c2"
160162
dryRunMode: true
161163
autoApprovePromotionPrs: true
164+
commentArgocdDiffonPR: true
165+
autoMergeNoDiffPRs: true
162166
toggleCommitStatus:
163167
override-terrafrom-pipeline: "github-action-terraform"
164168
```

internal/pkg/configuration/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type Config struct {
4141
ToggleCommitStatus map[string]string `yaml:"toggleCommitStatus"`
4242
WebhookEndpointRegexs []WebhookEndpointRegex `yaml:"webhookEndpointRegexs"`
4343
CommentArgocdDiffonPR bool `yaml:"commentArgocdDiffonPR"`
44+
AutoMergeNoDiffPRs bool `yaml:"autoMergeNoDiffPRs"`
4445
}
4546

4647
func ParseConfigFromYaml(y string) (*Config, error) {

internal/pkg/githubapi/github.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,14 @@ func HandlePREvent(eventPayload *github.PullRequestEvent, ghPrClientDetails GhPr
124124
} else {
125125
ghPrClientDetails.PrLogger.Debugf("PR %v labeled\n%+v", *eventPayload.PullRequest.Number, prLables)
126126
}
127-
// TODO Auto-merge PRs with no changes(optional)
127+
if DoesPrHasLabel(*eventPayload, "promotion") && config.AutoMergeNoDiffPRs {
128+
ghPrClientDetails.PrLogger.Infof("Auto-merging (no diff) PR %d", *eventPayload.PullRequest.Number)
129+
err := MergePr(ghPrClientDetails, eventPayload.PullRequest.Number)
130+
if err != nil {
131+
prHandleError = err
132+
ghPrClientDetails.PrLogger.Errorf("PR auto merge failed: err=%v", err)
133+
}
134+
}
128135
}
129136
}
130137

0 commit comments

Comments
 (0)