diff --git a/src/AutoMerge/guidelines.jl b/src/AutoMerge/guidelines.jl index d31cf115..36f95eb7 100644 --- a/src/AutoMerge/guidelines.jl +++ b/src/AutoMerge/guidelines.jl @@ -7,6 +7,19 @@ using HTTP: HTTP # once Julia 1.6 is no longer the LTS. const _AUTOMERGE_REQUIRE_STDLIB_COMPAT = false +const guideline_pr_is_authorized = Guideline(; + info="PR creator is authorized for automerging", + check=data -> meets_pr_is_authorized(data.authorized), +) + +function meets_pr_is_authorized(authorization) + if authorization == :not_authorized + return false, "PR creator is not authorized for merging. [Registrator.jl](https://github.com/JuliaRegistries/Registrator.jl) can be used for creating authorized registration PRs. Alternatively, this PR can be manually merged (especially if all the other guidelines are satisfied)." + else + return true, "" + end +end + const guideline_registry_consistency_tests_pass = Guideline(; info="Registy consistency tests", docs=nothing, @@ -1042,6 +1055,7 @@ function get_automerge_guidelines( (guideline_version_can_be_imported, true), (:update_status, true), (guideline_dependency_confusion, true), + (guideline_pr_is_authorized, true), # this is the non-optional part of name checking (guideline_name_match_check, true), # We always run the `guideline_distance_check` @@ -1084,6 +1098,7 @@ function get_automerge_guidelines( (guideline_version_has_osi_license, check_license), (guideline_src_names_OK, true), (guideline_version_can_be_imported, true), + (guideline_pr_is_authorized, true) ] return guidelines end diff --git a/src/AutoMerge/pull_requests.jl b/src/AutoMerge/pull_requests.jl index 72570f29..d6beaf6b 100644 --- a/src/AutoMerge/pull_requests.jl +++ b/src/AutoMerge/pull_requests.jl @@ -127,6 +127,9 @@ function pull_request_build( return nothing end + # Here we check whether or not the PR author is authorized + # for merging. If not, we will fail a guideline, but + # we will still run all the guidelines. pkg, version = parse_pull_request_title(registration_type, pr) pr_author_login = author_login(pr) authorization = check_authorization( @@ -137,10 +140,6 @@ function pull_request_build( error_exit_if_automerge_not_applicable, ) - if authorization == :not_authorized - return nothing - end - registry_master = clone_repo(registry) if !master_branch_is_default_branch checkout_branch(registry_master, master_branch) diff --git a/src/AutoMerge/types.jl b/src/AutoMerge/types.jl index 6071fc17..d629e673 100644 --- a/src/AutoMerge/types.jl +++ b/src/AutoMerge/types.jl @@ -63,6 +63,7 @@ struct GitHubAutoMergeData auth::GitHub.Authorization # Type of authorization for automerge. This can be either: + # :not_authorized - PR is not authorized for merging # :jll - special jll exceptions are allowed, # :normal - normal automerge rules. authorization::Symbol @@ -112,7 +113,7 @@ function GitHubAutoMergeData(; kwargs...) kwargs = (; pkg_code_path=pkg_code_path, kwargs...) fields = fieldnames(GitHubAutoMergeData) always_assert(Set(keys(kwargs)) == Set(fields)) - always_assert(kwargs[:authorization] ∈ (:normal, :jll)) + always_assert(kwargs[:authorization] ∈ (:not_authorized, :normal, :jll)) return GitHubAutoMergeData(getindex.(Ref(kwargs), fields)...) end diff --git a/test/automerge-unit.jl b/test/automerge-unit.jl index 3ea0c134..6c65c3b6 100644 --- a/test/automerge-unit.jl +++ b/test/automerge-unit.jl @@ -76,6 +76,11 @@ end end @testset "Guidelines for new packages" begin + @testset "meets_pr_is_authorized" begin + @test !AutoMerge.meets_pr_is_authorized(:not_authorized)[1] + @test AutoMerge.meets_pr_is_authorized(:jll)[1] + @test AutoMerge.meets_pr_is_authorized(:normal)[1] + end @testset "Normal capitalization" begin @test AutoMerge.meets_normal_capitalization("Zygote")[1] # Regular name @test AutoMerge.meets_normal_capitalization("Zygote")[1]