diff --git a/docs/installation.md b/docs/installation.md index a6b01b94..050eb35d 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -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)| Example: @@ -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" ``` diff --git a/internal/pkg/configuration/config.go b/internal/pkg/configuration/config.go index 531fe379..ea822829 100644 --- a/internal/pkg/configuration/config.go +++ b/internal/pkg/configuration/config.go @@ -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) { diff --git a/internal/pkg/githubapi/github.go b/internal/pkg/githubapi/github.go index 6b61867e..8d91a628 100644 --- a/internal/pkg/githubapi/github.go +++ b/internal/pkg/githubapi/github.go @@ -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) + } + } } }