From 646c51f56d4a3bd2532ac5afd90e3e7ea68691f7 Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Mon, 12 Aug 2019 15:49:53 +0200 Subject: [PATCH 1/2] =?UTF-8?q?failing=20on=20GitLab=20=E2=89=A5=209=20(bi?= =?UTF-8?q?s)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Compatibility with the deprecated variables listed in https://docs.gitlab.com/ee/ci/variables/deprecated_variables.html --- codecov/__init__.py | 10 +++++----- tests/test.py | 30 +++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/codecov/__init__.py b/codecov/__init__.py index c036f425..5c02e8b4 100644 --- a/codecov/__init__.py +++ b/codecov/__init__.py @@ -758,14 +758,14 @@ 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("/"): diff --git a/tests/test.py b/tests/test.py index 279d21ec..a8905df7 100644 --- a/tests/test.py +++ b/tests/test.py @@ -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", @@ -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", @@ -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") From e9b4f2793c40a5db491887531918eeb76214fe93 Mon Sep 17 00:00:00 2001 From: Thomas Hu Date: Wed, 27 May 2020 12:45:45 -0400 Subject: [PATCH 2/2] Black --- codecov/__init__.py | 11 ++++++++--- tests/test.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/codecov/__init__.py b/codecov/__init__.py index 5c02e8b4..00354d11 100644 --- a/codecov/__init__.py +++ b/codecov/__init__.py @@ -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 @@ -763,12 +764,16 @@ def main(*argv, **kwargs): query.update( dict( service="gitlab", - branch=os.getenv("CI_COMMIT_REF_NAME", os.getenv("CI_BUILD_REF_NAME")), + 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", "") diff --git a/tests/test.py b/tests/test.py index a8905df7..5e305eda 100644 --- a/tests/test.py +++ b/tests/test.py @@ -828,7 +828,7 @@ def test_ci_gitlab(self): CI_COMMIT_SHA="d653b934ed59c1a785cc1cc79d08c9aaa4eba73b", HOME="/", CI_PROJECT_DIR=os.getcwd().strip("/"), - CODECOV_TOKEN="token" + CODECOV_TOKEN="token", ) self.fake_report() res = self.run_cli()