Skip to content
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
15 changes: 15 additions & 0 deletions src/AutoMerge/guidelines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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
7 changes: 3 additions & 4 deletions src/AutoMerge/pull_requests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/AutoMerge/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions test/automerge-unit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down