From 0124f9357a14d8d919d6a0e4da9e7f87ffa65853 Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Mon, 12 Aug 2019 15:21:02 +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 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/codecov/__init__.py b/codecov/__init__.py index ea12bf53..91ab6bfd 100644 --- a/codecov/__init__.py +++ b/codecov/__init__.py @@ -468,12 +468,12 @@ 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 os.getenv('CI_PROJECT_DIR', '').startswith('/'): root = os.getenv('CI_PROJECT_DIR') else: From 4069ba997d14b8ad2fa835b3cb73609b5766f3ef Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Mon, 12 Aug 2019 15:49:53 +0200 Subject: [PATCH 2/2] oops: unittests... --- tests/test.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/test.py b/tests/test.py index ed640c6e..f97ec608 100644 --- a/tests/test.py +++ b/tests/test.py @@ -45,7 +45,9 @@ def setUp(self): "APPVEYOR_BUILD_VERSION", "APPVEYOR_JOB_ID", "APPVEYOR_REPO_NAME", "APPVEYOR_REPO_COMMIT", "WERCKER_GIT_BRANCH", "WERCKER_MAIN_PIPELINE_STARTED", "WERCKER_GIT_OWNER", "WERCKER_GIT_REPOSITORY", "CI_BUILD_REF_NAME", "CI_BUILD_ID", "CI_BUILD_REPO", "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", "WERCKER_GIT_COMMIT", "CHANGE_ID"): + os.environ[key] = "" def tearDown(self): @@ -556,7 +558,7 @@ def test_ci_magnum(self): self.assertEqual(res['codecov'].token, 'token') @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', CI_BUILD_REPO='https://gitlab.com/owner/repo.git', @@ -573,6 +575,24 @@ 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')