Skip to content

Commit

Permalink
Merge #227
Browse files Browse the repository at this point in the history
227: GitHub Enterprise Support 2: Electric Boogaloo r=DilumAluthge a=racinmat

Fixes #208 
Closes #221 

- Passing github base url as parameter.
- Removing hardcoded github.com from some places.

Co-authored-by: Matěj Račinský <[email protected]>
Co-authored-by: Dilum Aluthge <[email protected]>
Co-authored-by: Matěj Račinský <[email protected]>
  • Loading branch information
4 people committed Jul 8, 2020
2 parents 38087bc + ba46109 commit 3dfbcdb
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CompatHelper"
uuid = "aa819f21-2bde-4658-8897-bab36330d9b7"
authors = ["Dilum Aluthge <[email protected]>", "Brown Center for Biomedical Informatics"]
version = "1.11.0"
version = "1.12.0"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
9 changes: 7 additions & 2 deletions src/get_project_deps.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import GitHub
import Pkg

function get_project_deps(repo::GitHub.Repo; auth::GitHub.Authorization, master_branch::Union{DefaultBranch, AbstractString}, subdir::AbstractString)
function get_project_deps(api::GitHub.GitHubAPI,
clone_hostname::HostnameForClones,
repo::GitHub.Repo;
auth::GitHub.Authorization,
master_branch::Union{DefaultBranch, AbstractString},
subdir::AbstractString)
original_directory = pwd()
tmp_dir = mktempdir()
atexit(() -> rm(tmp_dir; force = true, recursive = true))
url_with_auth = "https://x-access-token:$(auth.token)@github.com/$(repo.full_name).git"
url_with_auth = "https://x-access-token:$(auth.token)@$(clone_hostname.hostname)/$(repo.full_name).git"
cd(tmp_dir)
try
run(`git clone $(url_with_auth) REPO`)
Expand Down
25 changes: 19 additions & 6 deletions src/main.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Pkg
import HTTP
import GitHub

const default_registries = Pkg.Types.RegistrySpec[Pkg.RegistrySpec(name = "General",
uuid = "23338594-aafe-5451-b93e-139f81909106",
Expand All @@ -12,20 +14,27 @@ function main(precommit_hook::Function = update_manifests,
drop_existing_compat::Bool = false,
master_branch::Union{DefaultBranch, AbstractString} = DefaultBranch(),
pr_title_prefix::String = "",
subdirs::AbstractVector{<:AbstractString} = [""])
subdirs::AbstractVector{<:AbstractString} = [""],
hostname_for_api::String="https://api.github.com",
hostname_for_clone::String="github.com")
if !keep_existing_compat && !drop_existing_compat
throw(ArgumentError("At least one of keep_existing_compat, drop_existing_compat must be true"))
end

COMPATHELPER_PRIV_is_defined = compathelper_priv_is_defined(env)
@info("Environment variable `COMPATHELPER_PRIV` is defined, is nonempty, and is not the string `false`: $(COMPATHELPER_PRIV_is_defined)")

api = GitHub.GitHubWebAPI(HTTP.URI(hostname_for_api))
clone_hostname = HostnameForClones(hostname_for_clone)
GITHUB_TOKEN = github_token(ci_cfg; env = ENV)
GITHUB_REPOSITORY = github_repository(ci_cfg; env = ENV)
auth = GitHub.authenticate(env["GITHUB_TOKEN"])
repo = GitHub.repo(env["GITHUB_REPOSITORY"]; auth = auth)
auth = GitHub.authenticate(api, GITHUB_TOKEN)
repo = GitHub.repo(api, GITHUB_REPOSITORY; auth = auth)

_all_open_prs = get_all_pull_requests(repo, "open"; auth = auth)
_all_open_prs = get_all_pull_requests(api,
repo,
"open";
auth = auth)
_nonforked_prs = exclude_pull_requests_from_forks(repo, _all_open_prs)
my_username = get_my_username(ci_cfg; auth = auth, env = env)
pr_list = only_my_pull_requests(_nonforked_prs; my_username = my_username)
Expand All @@ -38,14 +47,18 @@ function main(precommit_hook::Function = update_manifests,
dep_to_current_compat_entry,
dep_to_current_compat_entry_verbatim,
dep_to_latest_version,
deps_with_missing_compat_entry = get_project_deps(repo;
deps_with_missing_compat_entry = get_project_deps(api,
clone_hostname,
repo;
auth = auth,
master_branch = master_branch,
subdir = subdir)
get_latest_version_from_registries!(dep_to_latest_version,
registries)

make_pr_for_new_version(precommit_hook,
make_pr_for_new_version(api,
clone_hostname,
precommit_hook,
repo,
dep_to_current_compat_entry,
dep_to_current_compat_entry_verbatim,
Expand Down
34 changes: 24 additions & 10 deletions src/new_versions.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import GitHub
import Pkg

function make_pr_for_new_version(precommit_hook::Function,
function make_pr_for_new_version(api::GitHub.GitHubAPI,
clone_hostname::HostnameForClones,
precommit_hook::Function,
repo::GitHub.Repo,
dep_to_current_compat_entry::Dict{Package, Union{Pkg.Types.VersionSpec, Nothing}},
dep_to_current_compat_entry_verbatim::Dict{Package, Union{String, Nothing}},
Expand All @@ -21,7 +23,9 @@ function make_pr_for_new_version(precommit_hook::Function,
original_directory = pwd()
always_assert(keep_existing_compat || drop_existing_compat)
for dep in keys(dep_to_current_compat_entry)
make_pr_for_new_version(precommit_hook,
make_pr_for_new_version(api,
clone_hostname,
precommit_hook,
repo,
dep,
dep_to_current_compat_entry,
Expand All @@ -43,7 +47,9 @@ function make_pr_for_new_version(precommit_hook::Function,
return nothing
end

function make_pr_for_new_version(precommit_hook::Function,
function make_pr_for_new_version(api::GitHub.GitHubAPI,
clone_hostname::HostnameForClones,
precommit_hook::Function,
repo::GitHub.Repo,
dep::Package,
dep_to_current_compat_entry::Dict{Package, Union{Pkg.Types.VersionSpec, Nothing}},
Expand Down Expand Up @@ -84,7 +90,9 @@ function make_pr_for_new_version(precommit_hook::Function,
brand_new_compat = old_compat_to_new_compat(nothing,
compat_entry_for_latest_version,
:brandnewentry)
make_pr_for_new_version(precommit_hook,
make_pr_for_new_version(api,
clone_hostname,
precommit_hook,
compat_entry_for_latest_version,
brand_new_compat,
repo,
Expand All @@ -108,7 +116,9 @@ function make_pr_for_new_version(precommit_hook::Function,
drop_compat = old_compat_to_new_compat(current_compat_entry_verbatim,
compat_entry_for_latest_version,
:drop)
make_pr_for_new_version(precommit_hook,
make_pr_for_new_version(api,
clone_hostname,
precommit_hook,
compat_entry_for_latest_version,
drop_compat,
repo,
Expand All @@ -132,7 +142,9 @@ function make_pr_for_new_version(precommit_hook::Function,
keep_compat = old_compat_to_new_compat(current_compat_entry_verbatim,
compat_entry_for_latest_version,
:keep)
make_pr_for_new_version(precommit_hook,
make_pr_for_new_version(api,
clone_hostname,
precommit_hook,
compat_entry_for_latest_version,
keep_compat,
repo,
Expand Down Expand Up @@ -176,7 +188,9 @@ end
return "$(strip(new_compat))"
end

function make_pr_for_new_version(precommit_hook::Function,
function make_pr_for_new_version(api::GitHub.GitHubAPI,
clone_hostname::HostnameForClones,
precommit_hook::Function,
compat_entry_for_latest_version::String,
new_compat_entry::String,
repo::GitHub.Repo,
Expand Down Expand Up @@ -261,8 +275,8 @@ function make_pr_for_new_version(precommit_hook::Function,
if new_pr_title in pr_titles
@info("An open PR with the title already exists", new_pr_title)
else
url_with_auth = "https://x-access-token:$(auth.token)@github.com/$(repo.full_name).git"
url_for_ssh = "git@github.com:$(repo.full_name).git"
url_with_auth = "https://x-access-token:$(auth.token)@$(clone_hostname.hostname)/$(repo.full_name).git"
url_for_ssh = "git@$(clone_hostname.hostname):$(repo.full_name).git"

tmp_dir = mktempdir()
atexit(() -> rm(tmp_dir; force = true, recursive = true))
Expand Down Expand Up @@ -320,7 +334,7 @@ function make_pr_for_new_version(precommit_hook::Function,
run(`git push -f origin $(new_branch_name)`)
catch
end
create_new_pull_request(repo;
create_new_pull_request(api, repo;
base_branch = master_branch_name,
head_branch = new_branch_name,
title = new_pr_title,
Expand Down
12 changes: 7 additions & 5 deletions src/pull_requests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import GitHub

function get_all_pull_requests(repo::GitHub.Repo,
function get_all_pull_requests(api::GitHub.GitHubAPI,
repo::GitHub.Repo,
state::String;
auth::GitHub.Authorization,
per_page::Integer = 100,
Expand All @@ -9,13 +10,13 @@ function get_all_pull_requests(repo::GitHub.Repo,
myparams = Dict("state" => state,
"per_page" => per_page,
"page" => 1)
prs, page_data = GitHub.pull_requests(repo;
prs, page_data = GitHub.pull_requests(api, repo;
auth=auth,
params = myparams,
page_limit = page_limit)
append!(all_pull_requests, prs)
while haskey(page_data, "next")
prs, page_data = GitHub.pull_requests(repo;
prs, page_data = GitHub.pull_requests(api, repo;
auth=auth,
page_limit = page_limit,
start_page = page_data["next"])
Expand Down Expand Up @@ -68,7 +69,8 @@ function only_my_pull_requests(pr_list::Vector{GitHub.PullRequest}; my_username:
return my_pr_list
end

function create_new_pull_request(repo::GitHub.Repo;
function create_new_pull_request(api::GitHub.GitHubAPI,
repo::GitHub.Repo;
base_branch::String,
head_branch::String,
title::String,
Expand All @@ -79,6 +81,6 @@ function create_new_pull_request(repo::GitHub.Repo;
params["head"] = head_branch
params["base"] = base_branch
params["body"] = body
result = GitHub.create_pull_request(repo; params = params, auth = auth)
result = GitHub.create_pull_request(api, repo; params = params, auth = auth)
return result
end
4 changes: 4 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ struct GitHubActions <: CIService
username::String
end

struct HostnameForClones
hostname::String
end

struct MajorMinorVersion
major::Base.VInt
minor::Base.VInt
Expand Down
3 changes: 2 additions & 1 deletion test/integration-tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ whoami = username(auth)
repo_url_without_auth = "https://github.com/$(COMPATHELPER_INTEGRATION_TEST_REPO)"
repo_url_with_auth = "https://$(whoami):$(TEST_USER_GITHUB_TOKEN)@github.com/$(COMPATHELPER_INTEGRATION_TEST_REPO)"
repo = GitHub.repo(COMPATHELPER_INTEGRATION_TEST_REPO; auth = auth)
api = GitHub.GitHubWebAPI(HTTP.URI("https://api.github.com"))
Test.@test success(`git --version`)
@info("Authenticated to GitHub as \"$(whoami)\"")

Expand Down Expand Up @@ -120,7 +121,7 @@ with_master_branch(templates("master_6"), "master"; repo_url = repo_url_with_aut
end
end

all_prs = CompatHelper.get_all_pull_requests(repo, "open";
all_prs = CompatHelper.get_all_pull_requests(api, repo, "open";
auth = auth,
per_page = 3,
page_limit = 3)
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Base64
import CompatHelper
import Dates
import GitHub
import HTTP
import JSON
import Pkg
import Printf
Expand Down

2 comments on commit 3dfbcdb

@DilumAluthge
Copy link
Member

Choose a reason for hiding this comment

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

@JuliaRegistrator register branch=master

@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/17661

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 v1.12.0 -m "<description of version>" 3dfbcdb20c1e37f0f61eab4ae7da23910cc38ebd
git push origin v1.12.0

Please sign in to comment.