-
Notifications
You must be signed in to change notification settings - Fork 30
/
pull-requests.jl
108 lines (101 loc) · 5.42 KB
/
pull-requests.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const new_package_title_regex = r"^New package: (\w*) v(.*)"
const new_version_title_regex = r"^New version: (\w*) v(.*)"
is_new_package(pull_request::GitHub.PullRequest) = occursin(new_package_title_regex, title(pull_request))
is_new_version(pull_request::GitHub.PullRequest) = occursin(new_version_title_regex, title(pull_request))
function parse_pull_request_title(::NewVersion,
pull_request::GitHub.PullRequest)
m = match(new_version_title_regex, title(pull_request))
pkg = convert(String, m.captures[1])::String
version = VersionNumber(m.captures[2])
return pkg, version
end
function parse_pull_request_title(::NewPackage,
pull_request::GitHub.PullRequest)
m = match(new_package_title_regex, title(pull_request))
pkg = convert(String, m.captures[1])::String
version = VersionNumber(m.captures[2])
return pkg, version
end
function pull_request_build(pr_number::Integer,
current_pr_head_commit_sha::String,
registry::GitHub.Repo,
registry_head::String;
whoami::String,
auth::GitHub.Authorization,
authorized_authors::Vector{String},
authorized_authors_special_jll_exceptions::Vector{String},
master_branch::String,
master_branch_is_default_branch::Bool,
suggest_onepointzero::Bool,
registry_deps::Vector{<:AbstractString} = String[])::Nothing
pr = my_retry(() -> GitHub.pull_request(registry, pr_number; auth=auth))
_github_api_pr_head_commit_sha = pull_request_head_sha(pr)
if current_pr_head_commit_sha != _github_api_pr_head_commit_sha
throw(AutoMergeShaMismatch("Current commit sha (\"$(current_pr_head_commit_sha)\") does not match what the GitHub API tells us (\"$(_github_api_pr_head_commit_sha)\")"))
end
result = pull_request_build(pr,
current_pr_head_commit_sha,
registry,
registry_head;
auth=auth,
authorized_authors=authorized_authors,
authorized_authors_special_jll_exceptions=authorized_authors_special_jll_exceptions,
master_branch=master_branch,
master_branch_is_default_branch=master_branch_is_default_branch,
suggest_onepointzero=suggest_onepointzero,
whoami=whoami,
registry_deps=registry_deps)
return result
end
function pull_request_build(pr::GitHub.PullRequest,
current_pr_head_commit_sha::String,
registry::GitHub.Repo,
registry_head::String;
auth::GitHub.Authorization,
authorized_authors::Vector{String},
authorized_authors_special_jll_exceptions::Vector{String},
master_branch::String,
master_branch_is_default_branch::Bool,
suggest_onepointzero::Bool,
whoami::String,
registry_deps::Vector{<:AbstractString} = String[])::Nothing
if is_new_package(pr)
registry_master = clone_repo(registry)
if !master_branch_is_default_branch
checkout_branch(registry_master, master_branch)
end
pull_request_build(NewPackage(),
pr,
current_pr_head_commit_sha,
registry;
auth = auth,
authorized_authors=authorized_authors,
authorized_authors_special_jll_exceptions=authorized_authors_special_jll_exceptions,
registry_head = registry_head,
registry_master = registry_master,
suggest_onepointzero = suggest_onepointzero,
whoami=whoami,
registry_deps = registry_deps)
rm(registry_master; force = true, recursive = true)
elseif is_new_version(pr)
registry_master = clone_repo(registry)
if !master_branch_is_default_branch
checkout_branch(registry_master, master_branch)
end
pull_request_build(NewVersion(),
pr,
current_pr_head_commit_sha,
registry;
auth = auth,
authorized_authors=authorized_authors,
authorized_authors_special_jll_exceptions=authorized_authors_special_jll_exceptions,
registry_head = registry_head,
registry_master = registry_master,
suggest_onepointzero = suggest_onepointzero,
whoami=whoami,
registry_deps = registry_deps)
rm(registry_master; force = true, recursive = true)
else
throw(AutoMergeNeitherNewPackageNorNewVersion("Neither a new package nor a new version. Exiting..."))
end
end