This repository was archived by the owner on May 29, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbuildkite.py
More file actions
75 lines (58 loc) · 2.27 KB
/
Copy pathbuildkite.py
File metadata and controls
75 lines (58 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
from codecov_cli.helpers.ci_adapters.base import CIAdapterBase
class BuildkiteAdapter(CIAdapterBase):
# https://buildkite.com/docs/pipelines/environment-variables
def detect(self) -> bool:
return bool(os.getenv("BUILDKITE"))
def _get_branch(self):
return os.getenv("BUILDKITE_BRANCH")
def _get_build_code(self):
return os.getenv("BUILDKITE_BUILD_NUMBER")
def _get_build_url(self):
return os.getenv("BUILDKITE_BUILD_URL")
def _get_commit_sha(self):
return os.getenv("BUILDKITE_COMMIT")
def _get_slug(self):
# https://buildkite.com/docs/pipelines/configure/environment-variables#BUILDKITE_REPO
repo_url = os.getenv("BUILDKITE_REPO")
if repo_url:
slug = self._parse_slug_from_repo(repo_url)
if slug:
return slug
# Fallback to organization and pipeline slugs
org = os.getenv("BUILDKITE_ORGANIZATION_SLUG")
repo = os.getenv("BUILDKITE_PIPELINE_SLUG")
if org and repo:
return f"{org}/{repo}"
return None
def _parse_slug_from_repo(self, repo_url: str):
"""
TODO: this is relevant: https://stackoverflow.com/questions/31801271/what-are-the-supported-git-url-formats
supports:
(protocol://)host.xz/path/to/repo(.git/)
(protocol://)host.xz:path/to/repo(.git/)
(protocol://)user@host.xz:path/to/repo(.git/)
(protocol://)user@host.xz/path/to/repo(.git/)
"""
if not repo_url:
return None
value = repo_url.strip()
value = value.removesuffix("/")
value = value.removesuffix(".git")
value = value.replace(":", "/")
parts = [p for p in value.split("/") if p]
if len(parts) >= 2:
return "/".join(parts[-2:])
return None
def _get_service(self):
return "buildkite"
def _get_pull_request_number(self):
pr_number = os.getenv("BUILDKITE_PULL_REQUEST")
# The number of the pull request, if this branch is a pull request.
if pr_number != "false":
return pr_number
return None
def _get_job_code(self):
return os.getenv("BUILDKITE_JOB_ID")
def get_service_name(self):
return "BuildKite"