Skip to content

Commit

Permalink
Merge #440
Browse files Browse the repository at this point in the history
440: Revise the commit regex. r=ericphanson a=GunnarFarneback

This revises the commit regex to match
```
r"Commit: ([0-9a-f]+)"
```
but no longer requires that it is a markdown item on a line of its own.

The rationale is GunnarFarneback/LocalRegistry.jl#49, which makes use of "git push options" to create a pull request (only effective on GitLab). This provides a very low complexity pull request creation mechanism but has the limitation that it cannot pass newlines.

In terms of robustness and input sanitation this change makes no difference to Registrator generated pull requests.In fact it's rather stricter since the code in total only allows the commit hash to be exactly 40 hexadecimal digits.

Co-authored-by: Gunnar Farnebäck <gunnar.farneback@inify.com>
  • Loading branch information
bors[bot] and Gunnar Farnebäck authored Aug 15, 2022
2 parents 05634ea + b65e934 commit 18bf671
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "RegistryCI"
uuid = "0c95cc5f-2f7e-43fe-82dd-79dbcba86b32"
authors = ["Dilum Aluthge <dilum@aluthge.com>", "Fredrik Ekre <ekrefredrik@gmail.com>", "contributors"]
version = "7.6.0"
version = "7.7.0"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/regexes.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const row_3 = table_row(;
regex = RegistryCI.AutoMerge.commit_regex,
pr_field = "PR body",
pr_type = "All",
example = "* Commit: mycommithash123",
example = "* Commit: 012345678901234567890123456789abcdef0000",
)
const rows = [
Expand Down
6 changes: 4 additions & 2 deletions src/AutoMerge/pull_requests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const new_package_title_regex = r"^New package: (\w*?) v(\S*?)$"

const new_version_title_regex = r"^New version: (\w*?) v(\S*?)$"

const commit_regex = r"(?:^|\n|\r\n)(?:\-|\*) Commit: (\w*?)(?:$|\n|\r\n)"
const commit_regex = r"Commit: ([0-9a-f]+)"

function is_new_package(pull_request::GitHub.PullRequest)
return occursin(new_package_title_regex, title(pull_request))
Expand Down Expand Up @@ -57,7 +57,9 @@ end
function commit_from_pull_request_body(pull_request::GitHub.PullRequest)
pr_body = body(pull_request)
m = match(commit_regex, pr_body)
return convert(String, m.captures[1])::String
commit = convert(String, m.captures[1])::String
always_assert(length(commit) == 40)
return commit
end

function parse_pull_request_title(::NewPackage, pull_request::GitHub.PullRequest)
Expand Down
26 changes: 12 additions & 14 deletions test/automerge-unit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -295,25 +295,23 @@ end
end
end
@testset "commit_regex" begin
@test occursin(
AutoMerge.commit_regex, "- Foo\n- Commit: mycommithash123\n- Bar"
)
@test occursin(AutoMerge.commit_regex, "- Commit: mycommithash123\n- Bar")
@test occursin(AutoMerge.commit_regex, "- Foo\n- Commit: mycommithash123")
@test occursin(AutoMerge.commit_regex, "- Commit: mycommithash123")
@test occursin(
AutoMerge.commit_regex, "* Foo\n* Commit: mycommithash123\n* Bar"
)
@test occursin(AutoMerge.commit_regex, "* Commit: mycommithash123\n* Bar")
@test occursin(AutoMerge.commit_regex, "* Foo\n* Commit: mycommithash123")
@test occursin(AutoMerge.commit_regex, "* Commit: mycommithash123")
commit_hash = "012345678901234567890123456789abcdef0000"
@test occursin(AutoMerge.commit_regex, "- Foo\n- Commit: $(commit_hash)\n- Bar")
@test occursin(AutoMerge.commit_regex, "- Commit: $(commit_hash)\n- Bar")
@test occursin(AutoMerge.commit_regex, "- Foo\n- Commit: $(commit_hash)")
@test occursin(AutoMerge.commit_regex, "- Commit: $(commit_hash)")
@test occursin(AutoMerge.commit_regex, "Commit: $(commit_hash)")
@test occursin(AutoMerge.commit_regex, "* Foo\n* Commit: $(commit_hash)\n* Bar")
@test occursin(AutoMerge.commit_regex, "* Commit: $(commit_hash)\n* Bar")
@test occursin(AutoMerge.commit_regex, "* Foo\n* Commit: $(commit_hash)")
@test occursin(AutoMerge.commit_regex, "* Commit: $(commit_hash)")
@test !occursin(AutoMerge.commit_regex, "- Commit: mycommit hash 123")
let
m = match(
AutoMerge.commit_regex, "- Foo\n- Commit: mycommithash123\n- Bar"
AutoMerge.commit_regex, "- Foo\n- Commit: $(commit_hash)\n- Bar"
)
@test length(m.captures) == 1
@test m.captures[1] == "mycommithash123"
@test m.captures[1] == "$(commit_hash)"
end
end
end
Expand Down

2 comments on commit 18bf671

@ericphanson
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/66305

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v7.7.0 -m "<description of version>" 18bf67105b9877fe23e1948f275e3eff379a28cf
git push origin v7.7.0

Please sign in to comment.