Skip to content

Commit fd64abc

Browse files
nmoinvazRomain Dartiguesthomasrockhu
authored
failing on GitLab ≥ 9 (bis) (codecov#264)
* failing on GitLab ≥ 9 (bis) Compatibility with the deprecated variables listed in https://docs.gitlab.com/ee/ci/variables/deprecated_variables.html * Black Co-authored-by: Romain Dartigues <romain.dartigues.ext@orange.com> Co-authored-by: Thomas Hu <tomhu1096@gmail.com>
1 parent 84048cd commit fd64abc

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

codecov/__init__.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@
2828
from urllib import urlencode
2929

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

3636
def quote(arg):
3737
return list2cmdline([arg])
38+
3839
except ImportError:
3940
pass
4041

@@ -758,17 +759,21 @@ def main(*argv, **kwargs):
758759
# Gitlab CI
759760
# ---------
760761
elif os.getenv("CI_SERVER_NAME", "").startswith("GitLab"):
761-
# http://doc.gitlab.com/ci/examples/README.html#environmental-variables
762-
# https://gitlab.com/gitlab-org/gitlab-ci-runner/blob/master/lib/build.rb#L96
762+
# https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
763+
# https://gitlab.com/gitlab-org/gitlab-ci-runner/blob/master/lib/build.rb
763764
query.update(
764765
dict(
765766
service="gitlab",
766-
branch=os.getenv("CI_BUILD_REF_NAME"),
767-
build=os.getenv("CI_BUILD_ID"),
768-
commit=os.getenv("CI_BUILD_REF"),
767+
branch=os.getenv(
768+
"CI_COMMIT_REF_NAME", os.getenv("CI_BUILD_REF_NAME")
769+
),
770+
build=os.getenv("CI_JOB_ID", os.getenv("CI_BUILD_ID")),
771+
commit=os.getenv("CI_COMMIT_SHA", os.getenv("CI_BUILD_REF")),
769772
)
770773
)
771-
if sys.platform == "win32" or os.getenv("CI_PROJECT_DIR", "").startswith("/"):
774+
if sys.platform == "win32" or os.getenv("CI_PROJECT_DIR", "").startswith(
775+
"/"
776+
):
772777
root = os.getenv("CI_PROJECT_DIR")
773778
else:
774779
root = os.getenv("HOME") + "/" + os.getenv("CI_PROJECT_DIR", "")

tests/test.py

+29-1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ def setUp(self):
9898
"CI_PROJECT_DIR",
9999
"CI_BUILD_REF",
100100
"CI_SERVER_NAME",
101+
"CI_COMMIT_REF_NAME",
102+
"CI_JOB_ID",
103+
"CI_REPOSITORY_URL",
104+
"CI_COMMIT_SHA",
101105
"ghprbActualCommit",
102106
"ghprbSourceBranch",
103107
"ghprbPullId",
@@ -791,7 +795,7 @@ def test_ci_magnum(self):
791795
@unittest.skipUnless(
792796
os.getenv("CI_SERVER_NAME", "").startswith("GitLab"), "Skip GitLab CI test"
793797
)
794-
def test_ci_gitlab(self):
798+
def test_ci_gitlab_pre9(self):
795799
self.set_env(
796800
CI_BUILD_REF_NAME="master",
797801
CI_BUILD_ID="1399372237",
@@ -812,6 +816,30 @@ def test_ci_gitlab(self):
812816
self.assertEqual(res["query"]["slug"], "owner/repo")
813817
self.assertEqual(res["codecov"].token, "token")
814818

819+
@unittest.skipUnless(
820+
os.getenv("CI_SERVER_NAME", "").startswith("GitLab"), "Skip GitLab CI test"
821+
)
822+
def test_ci_gitlab(self):
823+
self.set_env(
824+
CI_COMMIT_REF_NAME="master",
825+
CI_JOB_ID="1399372237",
826+
CI_REPOSITORY_URL="https://gitlab.com/owner/repo.git",
827+
CI_SERVER_NAME="GitLab CI",
828+
CI_COMMIT_SHA="d653b934ed59c1a785cc1cc79d08c9aaa4eba73b",
829+
HOME="/",
830+
CI_PROJECT_DIR=os.getcwd().strip("/"),
831+
CODECOV_TOKEN="token",
832+
)
833+
self.fake_report()
834+
res = self.run_cli()
835+
self.assertEqual(res["query"]["service"], "gitlab")
836+
self.assertEqual(
837+
res["query"]["commit"], "d653b934ed59c1a785cc1cc79d08c9aaa4eba73b"
838+
)
839+
self.assertEqual(res["query"]["build"], "1399372237")
840+
self.assertEqual(res["query"]["slug"], "owner/repo")
841+
self.assertEqual(res["codecov"].token, "token")
842+
815843
@unittest.skip("Skip CI None")
816844
def test_ci_none(self):
817845
self.set_env(CODECOV_TOKEN="token")

0 commit comments

Comments
 (0)