Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue 185] Allow adding labels to issues via a file in the $SHARED_DIR #203

Merged
merged 15 commits into from
Jul 2, 2024
Merged
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Thank you for your interest in the firewatch project! Please find some informati
- Firewatch can optionally be configured to report test failures in a more verbose way (verbose test failure reporting).
- When configured to do this, firewatch will report on EVERY test failure in all JUnit files. The issues created from this will specify the failed test name in the title and description.
- **This functionality has the potential to create A LOT of tickets if cascading failures occur.** Because of this, firewatch is configured by default to only report up to 10 test failures per run. This value can be overridden, but do so with caution.
- Firewatch will add any additional labels listed in the `$SHARED_DIR/firewatch-additional-labels` file to any bug created. Each label must be separated by a new line.
- How to add a label to the file: `echo "some-label" >> $SHARED_DIR/firewatch-additional-labels`
- This should be used if you'd like to dynamically add labels based on parameters that can only be determined during test execution in OpenShift CI.

## Getting Started

Expand Down
4 changes: 4 additions & 0 deletions src/report/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ def _get_issue_labels(
job_name: Optional[str],
type: str,
jira_additional_labels: Optional[list[str]],
jira_additional_labels_filepath: str = f"{os.getenv('SHARED_DIR', '')}/firewatch-additional-labels",
calebevans marked this conversation as resolved.
Show resolved Hide resolved
calebevans marked this conversation as resolved.
Show resolved Hide resolved
failed_test_name: Optional[str] = None,
step_name: Optional[str] = None,
) -> list[Optional[str]]:
Expand All @@ -595,6 +596,9 @@ def _get_issue_labels(
# Add any additional labels
if jira_additional_labels:
labels.extend(jira_additional_labels)
if os.path.exists(jira_additional_labels_filepath):
with open(jira_additional_labels_filepath, "r") as file:
labels.extend(line.strip() for line in file if line.strip())
calebevans marked this conversation as resolved.
Show resolved Hide resolved

return list(set(labels))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

@pytest.fixture
def job_name():
yield "periodic-ci-openshift-pipelines-release-tests-release-v1.11-openshift-pipelines-ocp4.14-lp-interop-openshift-pipelines-interop-aws"
yield "periodic-ci-openshift-pipelines-release-tests-release-v1.14-openshift-pipelines-ocp4.16-lp-interop-openshift-pipelines-interop-aws"


@pytest.fixture
Expand All @@ -40,7 +40,7 @@ def job_name_safe():

@pytest.fixture
def build_id():
yield "1739164176636448768"
yield "1805119554108526592"


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
FIREWATCH_CONFIG_ENV_VAR = "FIREWATCH_CONFIG"

BUILD_IDS_TO_TEST = [
"1739164176636448768",
"1805119554108526592",
]

DEFAULT_JIRA_PROJECTS_TO_TEST = [
Expand Down Expand Up @@ -216,7 +216,7 @@ def firewatch_config(jira):
@pytest.fixture
def job(firewatch_config, build_id):
yield Job(
name="periodic-ci-openshift-pipelines-release-tests-release-v1.11-openshift-pipelines-ocp4.14-lp-interop-openshift-pipelines-interop-aws",
name="periodic-ci-openshift-pipelines-release-tests-release-v1.14-openshift-pipelines-ocp4.16-lp-interop-openshift-pipelines-interop-aws",
name_safe="openshift-pipelines-interop-aws",
build_id=build_id,
gcs_bucket="test-platform-results",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from tests.unittests import helpers
from tests.unittests.functions.report.report_base_test import ReportBaseTest


Expand Down Expand Up @@ -31,6 +32,16 @@ def test_get_issue_labels_with_additional_labels(self):
assert "firewatch" in labels
assert "additional-label-1" and "additional-label-2" in labels

def test_get_issue_labels_with_additional_labels_file(self):
labels = self.report._get_issue_labels(
job_name=self.job.name,
step_name="test-step-name",
type="test_failure",
jira_additional_labels=[],
jira_additional_labels_filepath=helpers._get_additional_labels_filepath(),
)
assert "test-1" and "test-1" in labels
calebevans marked this conversation as resolved.
Show resolved Hide resolved

def test_get_issue_labels_with_failed_test_name(self):
labels = self.report._get_issue_labels(
job_name=self.job.name,
Expand Down
4 changes: 4 additions & 0 deletions tests/unittests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ def _get_tmp_junit_dir(tmp_path: str) -> str:
if not os.path.exists(junit_dir):
os.mkdir(junit_dir)
return junit_dir


def _get_additional_labels_filepath() -> str:
return f"{str(os.path.dirname(__file__))}/resources/firewatch-additional-labels"
2 changes: 2 additions & 0 deletions tests/unittests/resources/firewatch-additional-labels
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test-1
test-2
Loading