From 487e6bfa248df4721f9bc441af0ebd3057ac7b8b Mon Sep 17 00:00:00 2001 From: Eric Hanson <5846501+ericphanson@users.noreply.github.com> Date: Sat, 9 Dec 2023 01:46:32 +0100 Subject: [PATCH 1/6] respect `Override AutoMerge: name similarity is okay` labels --- src/AutoMerge/guidelines.jl | 22 +++++++++++++++++++++- src/AutoMerge/pull_requests.jl | 1 + test/automerge-unit.jl | 12 +++++++++--- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/AutoMerge/guidelines.jl b/src/AutoMerge/guidelines.jl index eda343bb..9a673531 100644 --- a/src/AutoMerge/guidelines.jl +++ b/src/AutoMerge/guidelines.jl @@ -373,6 +373,24 @@ function meets_distance_check( return (false, message) end +# Used in `pull_request_build` to determine if we should +# perform the distance check or not. +# We expect to be passed the `labels` field of a PullRequest: +# +function perform_distance_check(labels) + # No labels? Do the check + isnothing(labels) && return true + for label in labels + if label.name === "Override AutoMerge: name similarity is okay" + # found the override! Skip the check + @debug "Found label; skipping distance check" label.name + return false + end + end + # Did not find the override. Perform the check. + return true +end + const guideline_normal_capitalization = Guideline(; info="Normal capitalization", docs=string( @@ -956,6 +974,7 @@ function get_automerge_guidelines( check_license::Bool, this_is_jll_package::Bool, this_pr_can_use_special_jll_exceptions::Bool, + use_distance_check::Bool ) guidelines = [ (guideline_registry_consistency_tests_pass, true), @@ -987,7 +1006,7 @@ function get_automerge_guidelines( # prints the list of similar package names in # the automerge comment. To make the comment easy # to read, we want this list to be at the end. - (guideline_distance_check, true), + (guideline_distance_check, use_distance_check), ] return guidelines end @@ -997,6 +1016,7 @@ function get_automerge_guidelines( check_license::Bool, this_is_jll_package::Bool, this_pr_can_use_special_jll_exceptions::Bool, + use_distance_check::Bool # unused for new versions ) guidelines = [ (guideline_registry_consistency_tests_pass, true), diff --git a/src/AutoMerge/pull_requests.jl b/src/AutoMerge/pull_requests.jl index a1e32dcb..54e8553b 100644 --- a/src/AutoMerge/pull_requests.jl +++ b/src/AutoMerge/pull_requests.jl @@ -195,6 +195,7 @@ function pull_request_build(data::GitHubAutoMergeData; check_license)::Nothing check_license=check_license, this_is_jll_package=this_is_jll_package, this_pr_can_use_special_jll_exceptions=this_pr_can_use_special_jll_exceptions, + use_distance_check=perform_distance_check(data.pr.labels) ) checked_guidelines = Guideline[] diff --git a/test/automerge-unit.jl b/test/automerge-unit.jl index 6d844e47..19dab411 100644 --- a/test/automerge-unit.jl +++ b/test/automerge-unit.jl @@ -123,6 +123,12 @@ end "ReallyLooooongNameCD", ["ReallyLooooongNameAB"] )[1] end + @testset "perform_distance_check" begin + @test AutoMerge.perform_distance_check(nothing) + @test AutoMerge.perform_distance_check([GitHub.Label(; name="hi")]) + @test !AutoMerge.perform_distance_check([GitHub.Label(; name="Override AutoMerge: name similarity is okay")]) + @test !AutoMerge.perform_distance_check([GitHub.Label(; name="hi"), GitHub.Label(; name="Override AutoMerge: name similarity is okay")]) + end @testset "`get_all_non_jll_package_names`" begin registry_path = joinpath(DEPOT_PATH[1], "registries", "General") packages = AutoMerge.get_all_non_jll_package_names(registry_path) @@ -617,7 +623,7 @@ end @test result[1] result = has_osi_license_in_depot("VisualStringDistances") @test result[1] - + # Now, what happens if there's also a non-OSI license in another file? pkg_path = pkgdir_from_depot(tmp_depot, "UnbalancedOptimalTransport") open(joinpath(pkg_path, "LICENSE2"); write=true) do io @@ -627,12 +633,12 @@ end end result = has_osi_license_in_depot("UnbalancedOptimalTransport") @test result[1] - + # What if we also remove the original license, leaving only the CC0 license? rm(joinpath(pkg_path, "LICENSE")) result = has_osi_license_in_depot("UnbalancedOptimalTransport") @test !result[1] - + # What about no license at all? pkg_path = pkgdir_from_depot(tmp_depot, "VisualStringDistances") rm(joinpath(pkg_path, "LICENSE")) From 58e3a6ad3bbdee98915519bacbd81993c5cb28c0 Mon Sep 17 00:00:00 2001 From: Eric Hanson <5846501+ericphanson@users.noreply.github.com> Date: Sat, 9 Dec 2023 01:51:25 +0100 Subject: [PATCH 2/6] update docs & example workflow --- example_github_workflow_files/automerge.yml | 2 ++ src/AutoMerge/guidelines.jl | 2 ++ 2 files changed, 4 insertions(+) diff --git a/example_github_workflow_files/automerge.yml b/example_github_workflow_files/automerge.yml index e36cc4ff..96287846 100644 --- a/example_github_workflow_files/automerge.yml +++ b/example_github_workflow_files/automerge.yml @@ -4,6 +4,8 @@ on: schedule: - cron: '05,17,29,41,53 * * * *' pull_request: + # Here we run when labels are applied, so that the "Override AutoMerge: name similarity is okay label is respected. + types: [labeled, synchronize] workflow_dispatch: jobs: diff --git a/src/AutoMerge/guidelines.jl b/src/AutoMerge/guidelines.jl index 9a673531..78a3ad61 100644 --- a/src/AutoMerge/guidelines.jl +++ b/src/AutoMerge/guidelines.jl @@ -265,6 +265,8 @@ To prevent confusion between similarly named packages, the names of new packages [VisualStringDistances.jl](https://github.com/ericphanson/VisualStringDistances.jl) between the package name and any existing package must exceeds a certain a hand-chosen threshold (currently 2.5). + +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. """, check=data -> meets_distance_check(data.pkg, data.registry_master), ) From 811b8ae041c689866eb064e0e50435fb581197fa Mon Sep 17 00:00:00 2001 From: Eric Hanson <5846501+ericphanson@users.noreply.github.com> Date: Sat, 9 Dec 2023 01:58:22 +0100 Subject: [PATCH 3/6] only trigger on the correct label --- example_github_workflow_files/automerge.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/example_github_workflow_files/automerge.yml b/example_github_workflow_files/automerge.yml index 96287846..b0b8893d 100644 --- a/example_github_workflow_files/automerge.yml +++ b/example_github_workflow_files/automerge.yml @@ -10,6 +10,11 @@ on: jobs: AutoMerge: + # Run if the we are not triggered by a label OR we are triggered by a label, and that + # label is one that affects the execution of the workflow + # Note: since the label contains a colon, we need to use a workaround like https://github.com/actions/runner/issues/1019#issuecomment-810482716 + # for the syntax to parse correctly. + if: "${{ github.event.action != 'labeled' || (github.event.action == 'labeled' && github.event.label.name == 'Override AutoMerge: name similarity is okay') }}" runs-on: ${{ matrix.os }} strategy: matrix: From feb2a61be951a8205be6ef3409178008a81943fc Mon Sep 17 00:00:00 2001 From: Eric Hanson <5846501+ericphanson@users.noreply.github.com> Date: Sat, 9 Dec 2023 02:08:55 +0100 Subject: [PATCH 4/6] add kwargs to docs --- docs/src/guidelines.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/src/guidelines.md b/docs/src/guidelines.md index dd7f8bd5..745dd925 100644 --- a/docs/src/guidelines.md +++ b/docs/src/guidelines.md @@ -22,6 +22,7 @@ function guidelines_to_markdown_output(guidelines_function::Function) check_license = true, this_is_jll_package = false, this_pr_can_use_special_jll_exceptions = false, + use_distance_check = false, ) filter!(x -> x[1] != :update_status, guidelines) filter!(x -> !(x[1].docs isa Nothing), guidelines) @@ -50,6 +51,7 @@ function guidelines_to_markdown_output(guidelines_function::Function) check_license = true, this_is_jll_package = false, this_pr_can_use_special_jll_exceptions = false, + use_distance_check = false, ) filter!(x -> x[1] != :update_status, guidelines) filter!(x -> !(x[1].docs isa Nothing), guidelines) From caf85a1a5f3f4e403b094e306213058ba95328c1 Mon Sep 17 00:00:00 2001 From: Eric Hanson <5846501+ericphanson@users.noreply.github.com> Date: Mon, 29 Jan 2024 00:59:14 +0100 Subject: [PATCH 5/6] Apply suggestions from code review Co-authored-by: Dilum Aluthge --- example_github_workflow_files/automerge.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/example_github_workflow_files/automerge.yml b/example_github_workflow_files/automerge.yml index b0b8893d..03dc8195 100644 --- a/example_github_workflow_files/automerge.yml +++ b/example_github_workflow_files/automerge.yml @@ -4,8 +4,9 @@ on: schedule: - cron: '05,17,29,41,53 * * * *' pull_request: - # Here we run when labels are applied, so that the "Override AutoMerge: name similarity is okay label is respected. - types: [labeled, synchronize] + # labeled = run when labels are applied, so that the "Override AutoMerge: name similarity is okay label is respected. + # synchronize = run when a commit is pushed to the PR + types: [opened, labeled, synchronize] workflow_dispatch: jobs: @@ -14,7 +15,7 @@ jobs: # label is one that affects the execution of the workflow # Note: since the label contains a colon, we need to use a workaround like https://github.com/actions/runner/issues/1019#issuecomment-810482716 # for the syntax to parse correctly. - if: "${{ github.event.action != 'labeled' || (github.event.action == 'labeled' && github.event.label.name == 'Override AutoMerge: name similarity is okay') }}" + if: "${{ github.event.action != 'labeled' || (github.event.action == 'labeled' && github.event.label.name == 'Override AutoMerge: name similarity is okay') }}" runs-on: ${{ matrix.os }} strategy: matrix: From 2700fca76232c2de7b7526683b59411a70e15b94 Mon Sep 17 00:00:00 2001 From: Eric Hanson <5846501+ericphanson@users.noreply.github.com> Date: Mon, 29 Jan 2024 01:20:52 +0100 Subject: [PATCH 6/6] Update example_github_workflow_files/automerge.yml Co-authored-by: Dilum Aluthge --- example_github_workflow_files/automerge.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/example_github_workflow_files/automerge.yml b/example_github_workflow_files/automerge.yml index 03dc8195..96ce146d 100644 --- a/example_github_workflow_files/automerge.yml +++ b/example_github_workflow_files/automerge.yml @@ -4,6 +4,7 @@ on: schedule: - cron: '05,17,29,41,53 * * * *' pull_request: + # opened = run when the PR is first opened # labeled = run when labels are applied, so that the "Override AutoMerge: name similarity is okay label is respected. # synchronize = run when a commit is pushed to the PR types: [opened, labeled, synchronize]