From 9e182f64137e452cf2f14b49b3dfb8c337cc2416 Mon Sep 17 00:00:00 2001 From: Anish Aggarwal Date: Fri, 23 Apr 2021 15:26:08 +0530 Subject: [PATCH 1/3] removed code for attemptDelete and DeleteAfterMerge functionality --- bulldozer/merge.go | 42 ------------------------------------------ 1 file changed, 42 deletions(-) diff --git a/bulldozer/merge.go b/bulldozer/merge.go index 3d05aa71c..01ff05c39 100644 --- a/bulldozer/merge.go +++ b/bulldozer/merge.go @@ -210,14 +210,6 @@ func MergePR(ctx context.Context, pullCtx pull.Context, merger Merger, mergeConf } time.Sleep(4 * time.Second) } - - if merged { - if mergeConfig.DeleteAfterMerge { - attemptDelete(ctx, pullCtx, head, merger) - } else { - logger.Debug().Msgf("Not deleting refs/heads/%s, delete after merge is not enabled", head) - } - } } // attemptMerge attempts to merge a pull request, logging any errors and @@ -272,40 +264,6 @@ func attemptMerge(ctx context.Context, pullCtx pull.Context, merger Merger, meth return true, false } -// attemptDelete attempts to delete a pull request branch, logging any errors -// and returning true if successful. -func attemptDelete(ctx context.Context, pullCtx pull.Context, head string, merger Merger) bool { - logger := zerolog.Ctx(ctx) - - if strings.ContainsRune(head, ':') { - // skip forks because the app doesn't have permission to do the delete - logger.Debug().Msg("Pull Request is from a fork, not deleting") - return false - } - - ref := fmt.Sprintf("refs/heads/%s", head) - - // check other open PRs to make sure that nothing is trying to merge into the ref we're about to delete - isTargeted, err := pullCtx.IsTargeted(ctx) - if err != nil { - logger.Error().Err(err).Msgf("Unabled to determine if %s is targeted by other pull requests", ref) - return false - } - if isTargeted { - logger.Info().Msgf("Unable to delete %s after merging %q because there are open PRs against it", ref, pullCtx.Locator()) - return false - } - - logger.Info().Msgf("Attempting to delete ref %s", ref) - if err := merger.DeleteHead(ctx, pullCtx); err != nil { - logger.Error().Err(err).Msgf("Failed to delete %s", ref) - return false - } - - logger.Info().Msgf("Successfully deleted %s after merging %q", ref, pullCtx.Locator()) - return true -} - func isValidMergeMethod(input MergeMethod) bool { return input == SquashAndMerge || input == RebaseAndMerge || input == MergeCommit || input == FastForwardOnly } From a2917f3f394acf3787e0032deeda3c0708f802da Mon Sep 17 00:00:00 2001 From: Anish Aggarwal Date: Fri, 23 Apr 2021 16:21:25 +0530 Subject: [PATCH 2/3] removed from examples, tests, readme --- README.md | 3 --- bulldozer/config_fetcher_test.go | 3 --- config/examples/standard.bulldozer.v1.yml | 1 - 3 files changed, 7 deletions(-) diff --git a/README.md b/README.md index f731d338c..1ce594dc7 100644 --- a/README.md +++ b/README.md @@ -145,9 +145,6 @@ merge: required_statuses: - "ci/circleci: ete-tests" - # If true, bulldozer will delete branches after their pull requests merge. - delete_after_merge: true - # If true, bulldozer will merge pull requests with no required checks. This # helps to protect against merging branches which inadvertently do not have # required status checks. diff --git a/bulldozer/config_fetcher_test.go b/bulldozer/config_fetcher_test.go index dbe901a61..135471744 100644 --- a/bulldozer/config_fetcher_test.go +++ b/bulldozer/config_fetcher_test.go @@ -39,7 +39,6 @@ merge: options: squash: body: summarize_commits - delete_after_merge: true update: trigger: @@ -77,7 +76,6 @@ merge: options: squash: body: summarize_commits - delete_after_merge: true update: whitelist: @@ -127,7 +125,6 @@ merge: options: squash: body: summarize_commits - delete_after_merge: true update: trigger: diff --git a/config/examples/standard.bulldozer.v1.yml b/config/examples/standard.bulldozer.v1.yml index 48897e0db..186849de1 100644 --- a/config/examples/standard.bulldozer.v1.yml +++ b/config/examples/standard.bulldozer.v1.yml @@ -11,7 +11,6 @@ merge: options: squash: body: summarize_commits - delete_after_merge: true allow_merge_with_no_checks: false update: From 0a733631b3a3bb0a77664d071ebbdcf7db1cd57b Mon Sep 17 00:00:00 2001 From: Anish Aggarwal Date: Fri, 23 Apr 2021 16:41:52 +0530 Subject: [PATCH 3/3] removed unused head var --- bulldozer/merge.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bulldozer/merge.go b/bulldozer/merge.go index 01ff05c39..47909a3c0 100644 --- a/bulldozer/merge.go +++ b/bulldozer/merge.go @@ -155,7 +155,7 @@ func (m *PushRestrictionMerger) DeleteHead(ctx context.Context, pullCtx pull.Con func MergePR(ctx context.Context, pullCtx pull.Context, merger Merger, mergeConfig MergeConfig) { logger := zerolog.Ctx(ctx) - base, head := pullCtx.Branches() + base, _ := pullCtx.Branches() mergeMethod := mergeConfig.Method if branchMergeMethod, ok := mergeConfig.BranchMethod[base]; ok {