Skip to content

Commit 251fc16

Browse files
authored
feat: add support for MERGIFY_TEST_JOB_NAME (#654)
1 parent 7cc6f8f commit 251fc16

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

mergify_cli/ci/junit.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import dataclasses
2+
import os
23
import time
34
import typing
45
from xml.etree import ElementTree as ET # noqa: S405
@@ -62,6 +63,11 @@ async def junit_to_spans(
6263
"test.run.id": run_id,
6364
}
6465

66+
if "MERGIFY_TEST_JOB_NAME" in os.environ:
67+
resource_attributes["mergify.test.job.name"] = os.environ[
68+
"MERGIFY_TEST_JOB_NAME"
69+
]
70+
6571
if (job_name := detector.get_job_name()) is not None:
6672
resource_attributes[cicd_attributes.CICD_PIPELINE_TASK_NAME] = job_name
6773

mergify_cli/tests/ci/test_junit.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import anys
66
import opentelemetry.trace.span
7+
import pytest
78

89
from mergify_cli.ci import detector
910
from mergify_cli.ci import junit
@@ -36,7 +37,9 @@ async def test_parse(
3637
_get_cicd_pipeline_run_attempt: mock.Mock,
3738
_get_head_sha: mock.Mock,
3839
_get_head_ref_name: mock.Mock,
40+
monkeypatch: pytest.MonkeyPatch,
3941
) -> None:
42+
monkeypatch.setenv("MERGIFY_TEST_JOB_NAME", "foobar")
4043
filename = pathlib.Path(__file__).parent / "junit_example.xml"
4144
run_id = (32312).to_bytes(8, "big").hex()
4245
spans = await junit.junit_to_spans(
@@ -62,6 +65,7 @@ async def test_parse(
6265
"telemetry.sdk.language": "python",
6366
"telemetry.sdk.name": "opentelemetry",
6467
"telemetry.sdk.version": anys.ANY_STR,
68+
"mergify.test.job.name": "foobar",
6569
}
6670
assert dictified_spans == [
6771
{

0 commit comments

Comments
 (0)