Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

failing on GitLab ≥ 9 (bis) #264

Merged
merged 2 commits into from May 27, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 12 additions & 7 deletions codecov/__init__.py
Expand Up @@ -28,13 +28,14 @@
from urllib import urlencode

quote = None
if sys.platform == 'win32': # pragma: no cover
if sys.platform == "win32": # pragma: no cover
try:
# https://github.com/python/cpython/blob/3.7/Lib/subprocess.py#L174-L175
from subprocess import list2cmdline

def quote(arg):
return list2cmdline([arg])

except ImportError:
pass

Expand Down Expand Up @@ -758,17 +759,21 @@ def main(*argv, **kwargs):
# Gitlab CI
# ---------
elif os.getenv("CI_SERVER_NAME", "").startswith("GitLab"):
# http://doc.gitlab.com/ci/examples/README.html#environmental-variables
# https://gitlab.com/gitlab-org/gitlab-ci-runner/blob/master/lib/build.rb#L96
# https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
# https://gitlab.com/gitlab-org/gitlab-ci-runner/blob/master/lib/build.rb
query.update(
dict(
service="gitlab",
branch=os.getenv("CI_BUILD_REF_NAME"),
build=os.getenv("CI_BUILD_ID"),
commit=os.getenv("CI_BUILD_REF"),
branch=os.getenv(
"CI_COMMIT_REF_NAME", os.getenv("CI_BUILD_REF_NAME")
),
build=os.getenv("CI_JOB_ID", os.getenv("CI_BUILD_ID")),
commit=os.getenv("CI_COMMIT_SHA", os.getenv("CI_BUILD_REF")),
)
)
if sys.platform == "win32" or os.getenv("CI_PROJECT_DIR", "").startswith("/"):
if sys.platform == "win32" or os.getenv("CI_PROJECT_DIR", "").startswith(
"/"
):
root = os.getenv("CI_PROJECT_DIR")
else:
root = os.getenv("HOME") + "/" + os.getenv("CI_PROJECT_DIR", "")
Expand Down
30 changes: 29 additions & 1 deletion tests/test.py
Expand Up @@ -98,6 +98,10 @@ def setUp(self):
"CI_PROJECT_DIR",
"CI_BUILD_REF",
"CI_SERVER_NAME",
"CI_COMMIT_REF_NAME",
"CI_JOB_ID",
"CI_REPOSITORY_URL",
"CI_COMMIT_SHA",
"ghprbActualCommit",
"ghprbSourceBranch",
"ghprbPullId",
Expand Down Expand Up @@ -791,7 +795,7 @@ def test_ci_magnum(self):
@unittest.skipUnless(
os.getenv("CI_SERVER_NAME", "").startswith("GitLab"), "Skip GitLab CI test"
)
def test_ci_gitlab(self):
def test_ci_gitlab_pre9(self):
self.set_env(
CI_BUILD_REF_NAME="master",
CI_BUILD_ID="1399372237",
Expand All @@ -812,6 +816,30 @@ def test_ci_gitlab(self):
self.assertEqual(res["query"]["slug"], "owner/repo")
self.assertEqual(res["codecov"].token, "token")

@unittest.skipUnless(
os.getenv("CI_SERVER_NAME", "").startswith("GitLab"), "Skip GitLab CI test"
)
def test_ci_gitlab(self):
self.set_env(
CI_COMMIT_REF_NAME="master",
CI_JOB_ID="1399372237",
CI_REPOSITORY_URL="https://gitlab.com/owner/repo.git",
CI_SERVER_NAME="GitLab CI",
CI_COMMIT_SHA="d653b934ed59c1a785cc1cc79d08c9aaa4eba73b",
HOME="/",
CI_PROJECT_DIR=os.getcwd().strip("/"),
CODECOV_TOKEN="token",
)
self.fake_report()
res = self.run_cli()
self.assertEqual(res["query"]["service"], "gitlab")
self.assertEqual(
res["query"]["commit"], "d653b934ed59c1a785cc1cc79d08c9aaa4eba73b"
)
self.assertEqual(res["query"]["build"], "1399372237")
self.assertEqual(res["query"]["slug"], "owner/repo")
self.assertEqual(res["codecov"].token, "token")

@unittest.skip("Skip CI None")
def test_ci_none(self):
self.set_env(CODECOV_TOKEN="token")
Expand Down