Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pull request number to Coveralls.io #251

Merged
merged 2 commits into from
Nov 25, 2019
Merged
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
4 changes: 4 additions & 0 deletions src/coveralls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,13 @@ module Coveralls
elseif lowercase(get(ENV, "APPVEYOR", "false")) == "true"
data["service_job_id"] = ENV["APPVEYOR_JOB_ID"]
data["service_name"] = "appveyor"
appveyor_pr = get(ENV, "APPVEYOR_PULL_REQUEST_NUMBER", "")
isempty(appveyor_pr) || (data["service_pull_request"] = appveyor_pr)
elseif lowercase(get(ENV, "TRAVIS", "false")) == "true"
data["service_job_id"] = ENV["TRAVIS_JOB_ID"]
data["service_name"] = "travis-ci"
travis_pr = get(ENV, "TRAVIS_PULL_REQUEST", "")
isempty(travis_pr) || (data["service_pull_request"] = travis_pr)
elseif lowercase(get(ENV, "JENKINS", "false")) == "true"
data["service_job_id"] = ENV["BUILD_ID"]
data["service_name"] = "jenkins-ci"
Expand Down
137 changes: 69 additions & 68 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,44 +154,48 @@ end
end
end

@testset "codecovio.jl" begin
# these methods are only used for testing the token generation for local repos
# and CI whilst not breaking the current API
construct_uri_string_local(dir=pwd(); kwargs...) = Coverage.Codecov.construct_uri_string(
;Coverage.Codecov.add_local_to_kwargs(dir; kwargs...)...)

construct_uri_string_ci(;kwargs...) = Coverage.Codecov.construct_uri_string(
;Coverage.Codecov.add_ci_to_kwargs(;kwargs...)...)

# empty file coverage for testing
fcs = FileCoverage[]

# set up base system ENV vars for testing
withenv(
"CODECOV_URL" => nothing,
"CODECOV_TOKEN" => nothing,
"TRAVIS" => nothing,
"TRAVIS_BRANCH" => nothing,
"TRAVIS_COMMIT" => nothing,
"TRAVIS_PULL_REQUEST" => nothing,
"TRAVIS_JOB_ID" => nothing,
"TRAVIS_REPO_SLUG" => nothing,
"TRAVIS_JOB_NUMBER" => nothing,
"APPVEYOR" => nothing,
"APPVEYOR_PULL_REQUEST_NUMBER" => nothing,
"APPVEYOR_ACCOUNT_NAME" => nothing,
"APPVEYOR_PROJECT_SLUG" => nothing,
"APPVEYOR_BUILD_VERSION" => nothing,
"APPVEYOR_REPO_BRANCH" => nothing,
"APPVEYOR_REPO_COMMIT" => nothing,
"APPVEYOR_REPO_NAME" => nothing,
"APPVEYOR_JOB_ID" => nothing,
) do

# test local submission process (but only if we are in a git repo)
# set up base system ENV vars for testing
withenv(
"COVERALLS_TOKEN" => "token_name_1",
"CODECOV_URL" => nothing,
"CODECOV_TOKEN" => nothing,
"TRAVIS" => nothing,
"TRAVIS_BRANCH" => nothing,
"TRAVIS_COMMIT" => nothing,
"TRAVIS_PULL_REQUEST" => nothing,
"TRAVIS_JOB_ID" => nothing,
"TRAVIS_REPO_SLUG" => nothing,
"TRAVIS_JOB_NUMBER" => nothing,
"APPVEYOR" => nothing,
"APPVEYOR_PULL_REQUEST_NUMBER" => nothing,
"APPVEYOR_ACCOUNT_NAME" => nothing,
"APPVEYOR_PROJECT_SLUG" => nothing,
"APPVEYOR_BUILD_VERSION" => nothing,
"APPVEYOR_REPO_BRANCH" => nothing,
"APPVEYOR_REPO_COMMIT" => nothing,
"APPVEYOR_REPO_NAME" => nothing,
"APPVEYOR_JOB_ID" => nothing,
"JENKINS" => nothing,
"BUILD_ID" => nothing,
"CI_PULL_REQUEST" => nothing,
"GIT_BRANCH" => nothing
) do

@testset "codecovio.jl" begin
# these methods are only used for testing the token generation for local repos
# and CI whilst not breaking the current API
construct_uri_string_local(dir=pwd(); kwargs...) = Coverage.Codecov.construct_uri_string(
;Coverage.Codecov.add_local_to_kwargs(dir; kwargs...)...)

construct_uri_string_ci(;kwargs...) = Coverage.Codecov.construct_uri_string(
;Coverage.Codecov.add_ci_to_kwargs(;kwargs...)...)

# empty file coverage for testing
fcs = FileCoverage[]

# test local submission process (but only if we are in a git repo)
_dotgit = joinpath(dirname(@__DIR__), ".git")

if isdir(_dotgit) || isfile(_dotgit)
LibGit2.with(LibGit2.GitRepoExt(pwd())) do repo
# default values
Expand Down Expand Up @@ -550,37 +554,26 @@ end
masked = Coverage.Codecov.mask_token(url)
@test masked == "https://enterprise-codecov-1.com/upload/v2?token=<HIDDEN>&build=t_job_num"
end
end


@testset "coveralls" begin
# NOTE: this only returns actual content if this package is devved.
# Hence the test is basically on this function returning something
# (rather than erroring)
git = Coverage.Coveralls.query_git_info()
@test git["remotes"][1]["name"] == "origin"
@test haskey(git["remotes"][1], "url")

# for testing submit_***()
fcs = FileCoverage[]

# an error should be raised if there is no coveralls token set
withenv("COVERALLS_TOKEN" => nothing,
"REPO_TOKEN" => nothing, # this is deprecrated, use COVERALLS_TOKEN
"APPVEYOR" => "true", # use APPVEYOR as an example to make the test reach the repo token check
"APPVEYOR_JOB_ID" => "my_job_id") do
@test_throws ErrorException Coverage.Coveralls.prepare_request(fcs, false)
end

withenv("COVERALLS_TOKEN" => "token_name_1",
"APPVEYOR" => nothing,
"APPVEYOR_JOB_ID" => nothing,
"TRAVIS" => nothing,
"TRAVIS_JOB_ID" => nothing,
"JENKINS" => nothing,
"BUILD_ID" => nothing,
"CI_PULL_REQUEST" => nothing,
"GIT_BRANCH" => nothing) do


@testset "coveralls" begin
# NOTE: this only returns actual content if this package is devved.
# Hence the test is basically on this function returning something
# (rather than erroring)
git = Coverage.Coveralls.query_git_info()
@test git["remotes"][1]["name"] == "origin"
@test haskey(git["remotes"][1], "url")

# for testing submit_***()
fcs = FileCoverage[]

# an error should be raised if there is no coveralls token set
withenv("COVERALLS_TOKEN" => nothing,
"REPO_TOKEN" => nothing, # this is deprecrated, use COVERALLS_TOKEN
"APPVEYOR" => "true", # use APPVEYOR as an example to make the test reach the repo token check
"APPVEYOR_JOB_ID" => "my_job_id") do
@test_throws ErrorException Coverage.Coveralls.prepare_request(fcs, false)
end

# test error if not local and no CI platform can be detected from ENV
@test_throws ErrorException Coverage.Coveralls.prepare_request(fcs, false)
Expand All @@ -593,24 +586,31 @@ end
@test isempty(request["source_files"])
@test haskey(request, "git")
@test request["git"]["remotes"][1]["name"] == "origin"
@test !haskey(request, "service_job_id")
@test !haskey(request, "service_name")
@test !haskey(request, "service_pull_request")
end

# test APPVEYOR
withenv("APPVEYOR" => "true",
"APPVEYOR_PULL_REQUEST_NUMBER" => "t_pr",
"APPVEYOR_JOB_ID" => "my_job_id") do
request = Coverage.Coveralls.prepare_request(fcs, false)
@test request["repo_token"] == "token_name_1"
@test request["service_job_id"] == "my_job_id"
@test request["service_name"] == "appveyor"
@test request["service_pull_request"] == "t_pr"
end

# test Travis
withenv("TRAVIS" => "true",
"TRAVIS_JOB_ID" => "my_job_id") do
"TRAVIS_JOB_ID" => "my_job_id",
"TRAVIS_PULL_REQUEST" => "t_pr") do
request = Coverage.Coveralls.prepare_request(fcs, false)
@test request["repo_token"] == "token_name_1"
@test request["service_job_id"] == "my_job_id"
@test request["service_name"] == "travis-ci"
@test request["service_pull_request"] == "t_pr"
end

# test Jenkins
Expand All @@ -622,6 +622,7 @@ end
@test request["repo_token"] == "token_name_1"
@test request["service_job_id"] == "my_job_id"
@test request["service_name"] == "jenkins-ci"
@test !haskey(request, "service_pull_request")

withenv("CI_PULL_REQUEST" => "false",
"GIT_BRANCH" => "my_remote/my_branch") do
Expand All @@ -643,7 +644,7 @@ end
# or directly a dict
request = Coverage.Coveralls.prepare_request(fcs, false, Dict("test" => "test"))
@test haskey(request, "git")
end
end
end
end

Expand Down