-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add cicd provider detector (#18)
Related to MRGFY-4457
- Loading branch information
Showing
5 changed files
with
42 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from opentelemetry.sdk.resources import Resource, ResourceDetector | ||
|
||
from pytest_mergify import utils | ||
|
||
|
||
class CIResourceDetector(ResourceDetector): | ||
"""Detects OpenTelemetry Resource attributes for GitHub Actions.""" | ||
|
||
def detect(self) -> Resource: | ||
if (provider := utils.get_ci_provider()) is None: | ||
return Resource({}) | ||
|
||
return Resource( | ||
{ | ||
"cicd.provider.name": provider, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import _pytest.pytester | ||
import _pytest.config | ||
|
||
from pytest_mergify import utils | ||
|
||
|
||
def test_span_resources_attributes( | ||
pytestconfig: _pytest.config.Config, | ||
) -> None: | ||
plugin = pytestconfig.pluginmanager.get_plugin("PytestMergify") | ||
assert plugin is not None | ||
assert plugin.exporter is not None | ||
spans = plugin.exporter.get_finished_spans() | ||
assert spans[0].resource.attributes["cicd.provider.name"] == utils.get_ci_provider() |