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

Remove delete_after_merge functionality #243

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 0 additions & 3 deletions bulldozer/config_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ merge:
options:
squash:
body: summarize_commits
delete_after_merge: true

update:
trigger:
Expand Down Expand Up @@ -77,7 +76,6 @@ merge:
options:
squash:
body: summarize_commits
delete_after_merge: true

update:
whitelist:
Expand Down Expand Up @@ -127,7 +125,6 @@ merge:
options:
squash:
body: summarize_commits
delete_after_merge: true

update:
trigger:
Expand Down
44 changes: 1 addition & 43 deletions bulldozer/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion config/examples/standard.bulldozer.v1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ merge:
options:
squash:
body: summarize_commits
delete_after_merge: true
allow_merge_with_no_checks: false

update:
Expand Down