Skip to content

Commit 2a13ff8

Browse files
AutoMerge: Respect the Override AutoMerge: name similarity is okay label (#536)
* respect `Override AutoMerge: name similarity is okay` labels * update docs & example workflow * only trigger on the correct label * add kwargs to docs * Apply suggestions from code review Co-authored-by: Dilum Aluthge <[email protected]> * Update example_github_workflow_files/automerge.yml Co-authored-by: Dilum Aluthge <[email protected]> --------- Co-authored-by: Dilum Aluthge <[email protected]>
1 parent a3ceb69 commit 2a13ff8

File tree

5 files changed

+44
-4
lines changed

5 files changed

+44
-4
lines changed

docs/src/guidelines.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function guidelines_to_markdown_output(guidelines_function::Function)
2222
check_license = true,
2323
this_is_jll_package = false,
2424
this_pr_can_use_special_jll_exceptions = false,
25+
use_distance_check = false,
2526
)
2627
filter!(x -> x[1] != :update_status, guidelines)
2728
filter!(x -> !(x[1].docs isa Nothing), guidelines)
@@ -50,6 +51,7 @@ function guidelines_to_markdown_output(guidelines_function::Function)
5051
check_license = true,
5152
this_is_jll_package = false,
5253
this_pr_can_use_special_jll_exceptions = false,
54+
use_distance_check = false,
5355
)
5456
filter!(x -> x[1] != :update_status, guidelines)
5557
filter!(x -> !(x[1].docs isa Nothing), guidelines)

example_github_workflow_files/automerge.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@ on:
44
schedule:
55
- cron: '05,17,29,41,53 * * * *'
66
pull_request:
7+
# opened = run when the PR is first opened
8+
# labeled = run when labels are applied, so that the "Override AutoMerge: name similarity is okay label is respected.
9+
# synchronize = run when a commit is pushed to the PR
10+
types: [opened, labeled, synchronize]
711
workflow_dispatch:
812

913
jobs:
1014
AutoMerge:
15+
# Run if the we are not triggered by a label OR we are triggered by a label, and that
16+
# label is one that affects the execution of the workflow
17+
# Note: since the label contains a colon, we need to use a workaround like https://github.com/actions/runner/issues/1019#issuecomment-810482716
18+
# for the syntax to parse correctly.
19+
if: "${{ github.event.action != 'labeled' || (github.event.action == 'labeled' && github.event.label.name == 'Override AutoMerge: name similarity is okay') }}"
1120
runs-on: ${{ matrix.os }}
1221
strategy:
1322
matrix:

src/AutoMerge/guidelines.jl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ To prevent confusion between similarly named packages, the names of new packages
265265
[VisualStringDistances.jl](https://github.com/ericphanson/VisualStringDistances.jl)
266266
between the package name and any existing package must exceeds a certain
267267
a hand-chosen threshold (currently 2.5).
268+
269+
These checks can be overridden by applying a label `Override AutoMerge: name similarity is okay` to the PR. This will turn off the check as long as the label is applied to the PR.
268270
""",
269271
check=data -> meets_distance_check(data.pkg, data.registry_master),
270272
)
@@ -373,6 +375,24 @@ function meets_distance_check(
373375
return (false, message)
374376
end
375377

378+
# Used in `pull_request_build` to determine if we should
379+
# perform the distance check or not.
380+
# We expect to be passed the `labels` field of a PullRequest:
381+
# <https://github.com/JuliaWeb/GitHub.jl/blob/d24bd6798609ae356db308d65577e99aad0cf432/src/issues/pull_requests.jl#L33>
382+
function perform_distance_check(labels)
383+
# No labels? Do the check
384+
isnothing(labels) && return true
385+
for label in labels
386+
if label.name === "Override AutoMerge: name similarity is okay"
387+
# found the override! Skip the check
388+
@debug "Found label; skipping distance check" label.name
389+
return false
390+
end
391+
end
392+
# Did not find the override. Perform the check.
393+
return true
394+
end
395+
376396
const guideline_normal_capitalization = Guideline(;
377397
info="Normal capitalization",
378398
docs=string(
@@ -956,6 +976,7 @@ function get_automerge_guidelines(
956976
check_license::Bool,
957977
this_is_jll_package::Bool,
958978
this_pr_can_use_special_jll_exceptions::Bool,
979+
use_distance_check::Bool
959980
)
960981
guidelines = [
961982
(guideline_registry_consistency_tests_pass, true),
@@ -987,7 +1008,7 @@ function get_automerge_guidelines(
9871008
# prints the list of similar package names in
9881009
# the automerge comment. To make the comment easy
9891010
# to read, we want this list to be at the end.
990-
(guideline_distance_check, true),
1011+
(guideline_distance_check, use_distance_check),
9911012
]
9921013
return guidelines
9931014
end
@@ -997,6 +1018,7 @@ function get_automerge_guidelines(
9971018
check_license::Bool,
9981019
this_is_jll_package::Bool,
9991020
this_pr_can_use_special_jll_exceptions::Bool,
1021+
use_distance_check::Bool # unused for new versions
10001022
)
10011023
guidelines = [
10021024
(guideline_registry_consistency_tests_pass, true),

src/AutoMerge/pull_requests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ function pull_request_build(data::GitHubAutoMergeData; check_license)::Nothing
195195
check_license=check_license,
196196
this_is_jll_package=this_is_jll_package,
197197
this_pr_can_use_special_jll_exceptions=this_pr_can_use_special_jll_exceptions,
198+
use_distance_check=perform_distance_check(data.pr.labels)
198199
)
199200
checked_guidelines = Guideline[]
200201

test/automerge-unit.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ end
123123
"ReallyLooooongNameCD", ["ReallyLooooongNameAB"]
124124
)[1]
125125
end
126+
@testset "perform_distance_check" begin
127+
@test AutoMerge.perform_distance_check(nothing)
128+
@test AutoMerge.perform_distance_check([GitHub.Label(; name="hi")])
129+
@test !AutoMerge.perform_distance_check([GitHub.Label(; name="Override AutoMerge: name similarity is okay")])
130+
@test !AutoMerge.perform_distance_check([GitHub.Label(; name="hi"), GitHub.Label(; name="Override AutoMerge: name similarity is okay")])
131+
end
126132
@testset "`get_all_non_jll_package_names`" begin
127133
registry_path = joinpath(DEPOT_PATH[1], "registries", "General")
128134
packages = AutoMerge.get_all_non_jll_package_names(registry_path)
@@ -617,7 +623,7 @@ end
617623
@test result[1]
618624
result = has_osi_license_in_depot("VisualStringDistances")
619625
@test result[1]
620-
626+
621627
# Now, what happens if there's also a non-OSI license in another file?
622628
pkg_path = pkgdir_from_depot(tmp_depot, "UnbalancedOptimalTransport")
623629
open(joinpath(pkg_path, "LICENSE2"); write=true) do io
@@ -627,12 +633,12 @@ end
627633
end
628634
result = has_osi_license_in_depot("UnbalancedOptimalTransport")
629635
@test result[1]
630-
636+
631637
# What if we also remove the original license, leaving only the CC0 license?
632638
rm(joinpath(pkg_path, "LICENSE"))
633639
result = has_osi_license_in_depot("UnbalancedOptimalTransport")
634640
@test !result[1]
635-
641+
636642
# What about no license at all?
637643
pkg_path = pkgdir_from_depot(tmp_depot, "VisualStringDistances")
638644
rm(joinpath(pkg_path, "LICENSE"))

0 commit comments

Comments
 (0)