Skip to content

Commit da0fd08

Browse files
fix: Fix harness ci slug parsing
1 parent 3d40d05 commit da0fd08

2 files changed

Lines changed: 18 additions & 35 deletions

File tree

‎codecov-cli/codecov_cli/helpers/ci_adapters/harness.py‎

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,14 @@ def _get_build_url(self):
3030
return os.getenv("CI_BUILD_LINK")
3131

3232
def _get_slug(self):
33-
# DRONE_REPO is the canonical org/repo slug on Harness CI (Drone-compatible).
34-
# CI_REPO is often equivalent but some setups only set the repo name; then use
35-
# DRONE_REPO_NAMESPACE + DRONE_REPO_NAME (or short CI_REPO as the name part).
36-
if drone_repo := os.getenv("DRONE_REPO"):
37-
return drone_repo
3833
ci_repo = os.getenv("CI_REPO")
3934
if ci_repo and "/" in ci_repo:
4035
return ci_repo
41-
namespace = os.getenv("DRONE_REPO_NAMESPACE") or os.getenv("CI_REPO_NAMESPACE")
42-
name = os.getenv("DRONE_REPO_NAME") or (
43-
ci_repo if ci_repo and "/" not in ci_repo else None
44-
)
45-
if namespace and name:
46-
return f"{namespace}/{name}"
47-
# Many Harness builds omit CI_REPO / *_NAMESPACE but still set clone/remotes:
48-
# https://developer.harness.io/docs/continuous-integration/troubleshoot-ci/ci-env-var/
4936
for env_var in (
50-
"DRONE_GIT_HTTP_URL",
5137
"CI_REPO_REMOTE",
38+
"CI_REMOTE_URL",
39+
"CI_REPO_LINK",
40+
"DRONE_GIT_HTTP_URL",
5241
"DRONE_REMOTE_URL",
5342
):
5443
if url := os.getenv(env_var):

‎codecov-cli/tests/ci_adapters/test_harnessci.py‎

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,15 @@ class HarnessEnvEnum(str, Enum):
1111
HARNESS_BUILD_ID = "HARNESS_BUILD_ID"
1212
CI_BUILD_LINK = "CI_BUILD_LINK"
1313
CI_BUILD_NUMBER = "CI_BUILD_NUMBER"
14+
CI_REMOTE_URL = "CI_REMOTE_URL"
1415
CI_REPO = "CI_REPO"
15-
CI_REPO_NAMESPACE = "CI_REPO_NAMESPACE"
16-
DRONE = "DRONE"
16+
CI_REPO_LINK = "CI_REPO_LINK"
17+
CI_REPO_REMOTE = "CI_REPO_REMOTE"
1718
DRONE_COMMIT_BRANCH = "DRONE_COMMIT_BRANCH"
1819
DRONE_COMMIT_SHA = "DRONE_COMMIT_SHA"
1920
DRONE_PULL_REQUEST = "DRONE_PULL_REQUEST"
2021
DRONE_GIT_HTTP_URL = "DRONE_GIT_HTTP_URL"
2122
DRONE_REMOTE_URL = "DRONE_REMOTE_URL"
22-
DRONE_REPO = "DRONE_REPO"
23-
DRONE_REPO_NAME = "DRONE_REPO_NAME"
24-
DRONE_REPO_NAMESPACE = "DRONE_REPO_NAMESPACE"
25-
CI_REPO_REMOTE = "CI_REPO_REMOTE"
2623

2724
class TestHarnessCI(object):
2825
@pytest.mark.parametrize(
@@ -101,30 +98,26 @@ def test_build_url(self, env_dict, expected, mocker):
10198
"env_dict,expected",
10299
[
103100
({}, None),
104-
({HarnessEnvEnum.DRONE_REPO: "owner/repo"}, "owner/repo"),
105101
({HarnessEnvEnum.CI_REPO: "owner/repo"}, "owner/repo"),
102+
({HarnessEnvEnum.CI_REPO: "repo"}, None),
106103
(
107104
{
108-
HarnessEnvEnum.DRONE_REPO_NAMESPACE: "owner",
109-
HarnessEnvEnum.DRONE_REPO_NAME: "repo",
105+
HarnessEnvEnum.CI_REPO_REMOTE: "https://gitlab.com/mygroup/myrepo.git",
110106
},
111-
"owner/repo",
107+
"mygroup/myrepo",
112108
),
113109
(
114110
{
115-
HarnessEnvEnum.DRONE_REPO_NAMESPACE: "owner",
116-
HarnessEnvEnum.CI_REPO: "repo",
111+
HarnessEnvEnum.CI_REMOTE_URL: "https://github.com/from-remote-url/from-remote-url",
117112
},
118-
"owner/repo",
113+
"from-remote-url/from-remote-url",
119114
),
120115
(
121116
{
122-
HarnessEnvEnum.CI_REPO_NAMESPACE: "owner",
123-
HarnessEnvEnum.CI_REPO: "repo",
117+
HarnessEnvEnum.CI_REPO_LINK: "https://github.com/from-repo-link/from-repo-link",
124118
},
125-
"owner/repo",
119+
"from-repo-link/from-repo-link",
126120
),
127-
({HarnessEnvEnum.CI_REPO: "repo"}, None),
128121
(
129122
{
130123
HarnessEnvEnum.DRONE_GIT_HTTP_URL: "https://github.com/myorg/myrepo.git",
@@ -133,15 +126,16 @@ def test_build_url(self, env_dict, expected, mocker):
133126
),
134127
(
135128
{
136-
HarnessEnvEnum.CI_REPO_REMOTE: "https://gitlab.com/mygroup/myrepo.git",
129+
HarnessEnvEnum.DRONE_REMOTE_URL: "git@github.com:acme/coverage.git",
137130
},
138-
"mygroup/myrepo",
131+
"acme/coverage",
139132
),
140133
(
141134
{
142-
HarnessEnvEnum.DRONE_REMOTE_URL: "git@github.com:acme/coverage.git",
135+
HarnessEnvEnum.CI_REPO_REMOTE: "https://github.com/first/first.git",
136+
HarnessEnvEnum.DRONE_GIT_HTTP_URL: "https://github.com/second/second.git",
143137
},
144-
"acme/coverage",
138+
"first/first",
145139
),
146140
],
147141
)

0 commit comments

Comments
 (0)