-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
231 additions
and
129 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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,6 +1,12 @@ | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
from .condition import PrerequisiteCondition | ||
from .jira_issue import PrerequisiteJiraIssue | ||
from .rule import PrerequisiteRule | ||
from .schedule import PrerequisiteSchedule | ||
|
||
type Prerequisite = PrerequisiteCondition | PrerequisiteSchedule | PrerequisiteRule | ||
type Prerequisite = ( | ||
PrerequisiteCondition | ||
| PrerequisiteSchedule | ||
| PrerequisiteRule | ||
| PrerequisiteJiraIssue | ||
) |
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
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,93 @@ | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
import os | ||
from collections.abc import Iterator | ||
from itertools import takewhile | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
from retasc.models.release_rule_state import ReleaseRuleState | ||
from retasc.utils import to_comma_separated | ||
|
||
from .base import PrerequisiteBase | ||
|
||
|
||
class JiraIssueTemplate(BaseModel): | ||
id: str = Field(description="Unique identifier for the issue.") | ||
template: str = Field(description="Path to the Jira issue template YAML file") | ||
|
||
|
||
class PrerequisiteJiraIssue(PrerequisiteBase): | ||
"""Prerequisite Rule.""" | ||
|
||
jira_issue_id: str = Field(description="Unique identifier for the issue.") | ||
template: str = Field(description="Path to the Jira issue template YAML file") | ||
subtasks: list[JiraIssueTemplate] = Field(default_factory=list) | ||
|
||
def validation_errors(self, rules) -> list[str]: | ||
errors = [] | ||
|
||
missing_files = { | ||
file for file in template_paths(self) if not os.path.isfile(file) | ||
} | ||
if missing_files: | ||
file_list = to_comma_separated(missing_files) | ||
errors.append(f"Jira issue template files not found: {file_list}") | ||
|
||
own_issue_ids = set(jira_issue_ids(self)) | ||
preceding_issue_ids = { | ||
issue_id | ||
for prereq in takewhile( | ||
lambda x: x is not self, jira_issue_prerequisites(rules) | ||
) | ||
for issue_id in jira_issue_ids(prereq) | ||
} | ||
duplicate_issue_ids = own_issue_ids.intersection(preceding_issue_ids) | ||
if duplicate_issue_ids: | ||
id_list = to_comma_separated(duplicate_issue_ids) | ||
errors.append(f"Jira issue ID(s) already used elsewhere: {id_list}") | ||
|
||
return errors | ||
|
||
def update_state(self, context) -> ReleaseRuleState: | ||
"""Return Completed only if all rules were closed.""" | ||
label = f"retasc-id-{self.jira_issue_id}" | ||
if label in context.closed_issue_labels: | ||
return ReleaseRuleState.Completed | ||
# TODO: Create new or update existing issue from the template if | ||
# context.prerequisites_state is ReleaseRuleState.InProgress | ||
return ReleaseRuleState.InProgress | ||
|
||
def section_name(self) -> str: | ||
return f"jira: {self.jira_issue_id!r}" | ||
|
||
|
||
def templates_root() -> str: | ||
return os.getenv("RETASC_JIRA_TEMPLATES_ROOT", ".") | ||
|
||
|
||
def template_filenames(prereq: PrerequisiteJiraIssue) -> Iterator[str]: | ||
yield prereq.template | ||
for x in prereq.subtasks: | ||
yield x.template | ||
|
||
|
||
def template_paths(prereq: PrerequisiteJiraIssue) -> Iterator[str]: | ||
root = templates_root() | ||
for file in template_filenames(prereq): | ||
yield f"{root}/{file}" | ||
|
||
|
||
def jira_issue_ids(prereq: PrerequisiteJiraIssue) -> Iterator[str]: | ||
yield prereq.jira_issue_id | ||
for x in prereq.subtasks: | ||
yield x.id | ||
|
||
|
||
def jira_issue_prerequisites(rules): | ||
for rule in rules: | ||
for prereq in rule.prerequisites: | ||
if isinstance(prereq, PrerequisiteJiraIssue): | ||
yield prereq | ||
# Ignore this from coverage since rules is always non-empty and the | ||
# iteration always stops at a specific prerequisite. | ||
return # pragma: no cover |
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
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
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,3 @@ | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
def to_comma_separated(items: list) -> str: | ||
return ", ".join(sorted(repr(str(x)) for x in items)) |
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
Oops, something went wrong.