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

Only close old PRs if they have the same target branch as the current run #88

Merged
merged 2 commits into from
Jan 9, 2023
Merged
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
1 change: 1 addition & 0 deletions bors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ delete_merged_branches = true
status = [
"test (1, ubuntu-latest, x64)",
"test (nightly, ubuntu-latest, x64)",
"Documentation",
]
timeout_sec = 3600
20 changes: 14 additions & 6 deletions src/bump-stdlibs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ function bump_stdlibs(julia_repo::AbstractString, config::Config)
cd("FORK") do
run(`git fetch --all --prune`)
for (i, stdlib) in enumerate(filtered_stdlib_list)
prefix = "BumpStdlibs/$(stdlib.name)-"
delete_branches_with_prefix_on_origin_older_than(
prefix,
predicate = generate_predicate_branch_matches_stdlib_and_target_branch(;
stdlib,
target_branch = config.julia_repo_target_branch,
)
delete_branches_with_predicate_on_origin_older_than(
predicate,
config.close_old_pull_requests_older_than;
exclude = state.all_pr_branches,
)
Expand Down Expand Up @@ -119,16 +122,20 @@ function _bump_single_stdlib(stdlib::StdlibInfo, config::Config, state::State)
cd(joinpath(temp_dir, "FORK")) do
run(`git checkout $(config.julia_repo_target_branch)`)
assert_current_branch_is(config.julia_repo_target_branch)
pr_title_without_emoji = "Bump the $(stdlib.name) stdlib from $(stdlib_current_commit_in_upstream_short) to $(stdlib_latest_commit_short)"
pr_title_without_emoji = "[$(config.julia_repo_target_branch)] Bump the $(stdlib.name) stdlib from $(stdlib_current_commit_in_upstream_short) to $(stdlib_latest_commit_short)"
pr_title = "🤖 $(pr_title_without_emoji)"
commit_message = pr_title
pr_branch_suffix_stripped = strip(pr_branch_suffix)
if isempty(pr_branch_suffix_stripped)
pr_branch_suffix_with_hyphen = ""
else
if !occursin(r"^[\d]*?$", pr_branch_suffix_stripped)
msg = "Suffix must only be numerical: $(pr_branch_suffix_stripped)"
throw(ErrorException(msg))
end
pr_branch_suffix_with_hyphen = "-$(pr_branch_suffix_stripped)"
end
pr_branch = "BumpStdlibs/$(stdlib.name)-$(stdlib_latest_commit_short)$(pr_branch_suffix_with_hyphen)"
pr_branch = "BumpStdlibs$(pr_branch_suffix_with_hyphen)/$(stdlib.name)-$(stdlib_latest_commit_short)-$(config.julia_repo_target_branch)"
push!(state.all_pr_branches, pr_branch)
git_url_markdown = _git_url_to_formatted_markdown(stdlib.git_url)
bumpstdlibs_sender = strip(get(ENV, "BUMPSTDLIBS_SENDER", ""))
Expand All @@ -138,7 +145,8 @@ function _bump_single_stdlib(stdlib::StdlibInfo, config::Config, state::State)
pr_body_lines = String[
"Stdlib: $(stdlib.name)",
"URL: $(git_url_markdown)",
"Branch: $(stdlib.branch)",
"Stdlib branch: $(stdlib.branch)",
"Julia branch: $(config.julia_repo_target_branch)",
"Old commit: $(stdlib_current_commit_in_upstream_short)",
"New commit: $(stdlib_latest_commit_short)",
"Julia version: $(julia_version)",
Expand Down
50 changes: 46 additions & 4 deletions src/git.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,53 @@ function delete_branch_on_origin(branch_name)
return nothing
end

function delete_branches_with_prefix_on_origin_older_than(prefix::AbstractString,
older_than::Dates.AbstractTime;
exclude = String[])
function parse_branch_name(original_str::AbstractString)
str = strip(original_str)
let
r = r"^BumpStdlibs\/([A-Za-z0-9]*?)-([a-z0-9]*?)-(.*?)$" # without suffix
m = match(r, str)
if m !== nothing
stdlib = m[1]
commit = m[2]
target_branch = m[3]
return (; stdlib, commit, target_branch)
end
end
let
r = r"^BumpStdlibs-[\d]*?\/([A-Za-z0-9]*?)-([a-z0-9]*?)-(.*?)$" # with suffix
m = match(r, str)
if m !== nothing
stdlib = m[1]
commit = m[2]
target_branch = m[3]
return (; stdlib, commit, target_branch)
end
end
return nothing
end

function branch_matches_stdlib_and_target_branch(; branch_name, stdlib, target_branch)
info = parse_branch_name(branch_name)
if info === nothing
return false
end
return ((stdlib == info.stdlib ) && (target_branch == info.target_branch))
end

function generate_predicate_branch_matches_stdlib_and_target_branch(; stdlib, target_branch)
predicate = branch_name -> branch_matches_stdlib_and_target_branch(;
branch_name,
stdlib,
target_branch,
)
return predicate
end

function delete_branches_with_predicate_on_origin_older_than(predicate::Function,
older_than::Dates.AbstractTime;
exclude = String[])
for branch_name in get_origin_branches()
if startswith(branch_name, prefix)
if predicate(branch_name)
commit = strip(read(`git rev-parse origin/$(branch_name)`, String))
age = get_age_of_commit(commit)
if !(branch_name in exclude)
Expand Down
2 changes: 1 addition & 1 deletion test/integration-tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:close_old_pull_requests => true,
:close_old_pull_requests_older_than => Dates.Minute(5),
:julia_repo_target_branch => "master",
:pr_branch_suffix => Random.randstring(4),
:pr_branch_suffix => Random.randstring('0':'9', 4),
:push_if_no_changes => true,
:stdlibs_to_include => "Pkg",
)
Expand Down