Skip to content

Commit 836eb2a

Browse files
Prefer explicitly set REPO_URL over fallback (#72)
1 parent 70b0a9c commit 836eb2a

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

pylynk/utils/ci_info.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,24 @@ def _extract_event_info(self):
228228
if git_tag:
229229
event_info['release_tag'] = git_tag
230230

231+
# Allow explicit environment variables to override or supplement detected data.
232+
explicit_overrides = {
233+
'event_type': os.getenv('EVENT_TYPE'),
234+
'number': os.getenv('PULL_REQUEST_NUMBER') or os.getenv('PR_NUMBER'),
235+
'url': os.getenv('PR_URL'),
236+
'source_branch': os.getenv('BRANCH_NAME') or os.getenv('REPO_BRANCH'),
237+
'target_branch': os.getenv('PR_TARGET_BRANCH'),
238+
'author': os.getenv('PR_AUTHOR'),
239+
}
240+
241+
release_tag = os.getenv('GIT_TAG') or os.getenv('REPO_TAG')
242+
if release_tag:
243+
explicit_overrides['release_tag'] = release_tag
244+
245+
for key, value in explicit_overrides.items():
246+
if value:
247+
event_info[key] = value
248+
231249
return {k: v for k, v in event_info.items() if v}
232250

233251
def _extract_build_info(self):
@@ -299,8 +317,10 @@ def _extract_repository_info(self):
299317
'owner': os.getenv('BITBUCKET_WORKSPACE'),
300318
'url': f"https://bitbucket.org/{os.getenv('BITBUCKET_WORKSPACE')}/{os.getenv('BITBUCKET_REPO_SLUG')}"
301319
})
302-
# Fallbacks - check common repository environment variables
303-
repo_info.setdefault('url', os.getenv('REPO_URL') or os.getenv('REPOSITORY_URL'))
320+
# Explicit environment variables override CI-detected values
321+
explicit_repo_url = os.getenv('REPO_URL') or os.getenv('REPOSITORY_URL')
322+
if explicit_repo_url:
323+
repo_info['url'] = explicit_repo_url
304324
repo_info.setdefault('name', os.getenv('REPO_NAME') or os.getenv('REPOSITORY_NAME'))
305325
return {k: v for k, v in repo_info.items() if v}
306326

0 commit comments

Comments
 (0)