Skip to content

Commit

Permalink
fix(gha): set vcs.ref.head.name correctly on PR (#77)
Browse files Browse the repository at this point in the history
For pull requests, this is not set to the head branch but to pull/XX
  • Loading branch information
jd authored Feb 19, 2025
1 parent 0752112 commit c4910a6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pytest_mergify/resources/github_actions.py
Original file line number Diff line number Diff line change
@@ -25,12 +25,15 @@ def get_github_actions_head_sha() -> str | None:
return str(event["pull_request"]["head"]["sha"])
return os.getenv("GITHUB_SHA")

@staticmethod
def get_github_head_ref_name() -> str | None:
return os.getenv("GITHUB_HEAD_REF") or os.getenv("GITHUB_REF")

OPENTELEMETRY_GHA_MAPPING = {
cicd_attributes.CICD_PIPELINE_NAME: (str, "GITHUB_JOB"),
cicd_attributes.CICD_PIPELINE_RUN_ID: (int, "GITHUB_RUN_ID"),
"cicd.pipeline.run.attempt": (int, "GITHUB_RUN_ATTEMPT"),
cicd_attributes.CICD_PIPELINE_TASK_NAME: (str, "GITHUB_ACTION"),
vcs_attributes.VCS_REF_HEAD_NAME: (str, "GITHUB_REF_NAME"),
vcs_attributes.VCS_REF_HEAD_TYPE: (str, "GITHUB_REF_TYPE"),
vcs_attributes.VCS_REF_BASE_NAME: (str, "GITHUB_BASE_REF"),
"vcs.repository.name": (str, "GITHUB_REPOSITORY"),
@@ -48,6 +51,10 @@ def detect(self) -> Resource:
os.environ["GITHUB_SERVER_URL"] + "/" + os.environ["GITHUB_REPOSITORY"]
)

head_ref = self.get_github_head_ref_name()
if head_ref is not None:
attributes[vcs_attributes.VCS_REF_HEAD_NAME] = head_ref

head_sha = self.get_github_actions_head_sha()
if head_sha is not None:
attributes[vcs_attributes.VCS_REF_HEAD_REVISION] = head_sha

0 comments on commit c4910a6

Please sign in to comment.