Skip to content

Commit

Permalink
- Fixed wrong keywords. Debug.
Browse files Browse the repository at this point in the history
  • Loading branch information
miroslavpojer committed Oct 1, 2024
1 parent ec9eb91 commit 17bfaf7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
4 changes: 2 additions & 2 deletions release_notes_generator/action_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ def get_row_format_issue() -> str:
"""
Get the issue row format for the release notes.
"""
return get_action_input(ROW_FORMAT_ISSUE, "#{number} _{title}_ {pull-requests} {assignee} {developed-by} {contributed-by}").strip()
return get_action_input(ROW_FORMAT_ISSUE, "#{number} _{title}_ {pull-requests} {assignee} {developed-by} {co-authored-by}").strip()

@staticmethod
def get_row_format_pr() -> str:
"""
Get the pr row format for the release notes.
"""
return get_action_input(ROW_FORMAT_PR, "#{number} _{title}_ {assignee} {developed-by} {contributed-by}").strip()
return get_action_input(ROW_FORMAT_PR, "#{number} _{title}_ {assignee} {developed-by} {co-authored-by}").strip()

@staticmethod
def get_row_format_link_pr() -> bool:
Expand Down
29 changes: 25 additions & 4 deletions release_notes_generator/model/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,13 @@ def to_chapter_row(self) -> str:
"""
self.increment_present_in_chapters()
row_prefix = f"{ActionInputs.get_duplicity_icon()} " if self.present_in_chapters() > 1 else ""
format_values = {"assignee": f"assigned to @{self.assignee}" if self.assignee is not None else "",
"assignees": f"assigned to @{self.assignees}" if self.assignees is not None else "",
"developers": f"developed by {self.developers}" if self.developers is not None else "",
"contributors": f"co-authored by {self.contributors}" if self.contributors is not None else ""}
format_values = {}

if self.__gh_issue is None:
p = self.__pulls[0]
format_values["number"] = p.number
format_values["title"] = p.title
format_values.update(self.__get_row_format_values(ActionInputs.get_row_format_pr()))

pr_prefix = "PR: " if ActionInputs.get_row_format_link_pr() else ""
row = f"{row_prefix}{pr_prefix}" + ActionInputs.get_row_format_pr().format(**format_values)
Expand All @@ -306,6 +304,7 @@ def to_chapter_row(self) -> str:
format_values["number"] = self.__gh_issue.number
format_values["title"] = self.__gh_issue.title
format_values["pull-requests"] = f"in {self.pr_links}" if len(self.__pulls) > 0 else ""
format_values.update(self.__get_row_format_values(ActionInputs.get_row_format_issue()))

row = f"{row_prefix}" + ActionInputs.get_row_format_issue().format(**format_values)

Expand All @@ -314,6 +313,28 @@ def to_chapter_row(self) -> str:

return row

def __get_row_format_values(self, row_format: str) -> dict:
"""
Create dictionary and fill by user row format defined values.
NoteL some values are API call intensive.
@param row_format: User defined row format.
@return: The dictionary with supported values required by user row format.
"""
format_values = {}

if "{assignee}" in row_format:
format_values["assignee"] = f"assigned to @{self.assignee}" if self.assignee is not None else ""
if "{assignees}" in row_format:
format_values["assignees"] = f"assigned to @{self.assignees}" if self.assignees is not None else ""
if "{developers}" in row_format:
format_values["developers"] = f"developed by {self.developers}" if self.developers is not None else ""
if "{contributors}" in row_format:
format_values["contributors"] = f"co-authored by {self.contributors}" if self.contributors is not None else ""

return format_values


def contains_min_one_label(self, labels: list[str]) -> bool:
"""
Check if the record contains at least one of the specified labels.
Expand Down
2 changes: 1 addition & 1 deletion release_notes_generator/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
ROW_FORMAT_ISSUE = "row-format-issue"
ROW_FORMAT_PR = "row-format-pr"
ROW_FORMAT_LINK_PR = "row-format-link-pr"
SUPPORTED_ROW_FORMAT_KEYS = ["number", "title", "pull-requests", "assignee", "assignees", "developed-by", "contributed-by"]
SUPPORTED_ROW_FORMAT_KEYS = ["number", "title", "pull-requests", "assignee", "assignees", "developed-by", "co-authored-by"]

# Features
WARNINGS = "warnings"
Expand Down
2 changes: 1 addition & 1 deletion release_notes_generator/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ def detect_row_format_invalid_keywords(row_format: str, row_type: str = "Issue")
keywords_in_braces = re.findall(r"\{(.*?)\}", row_format)
invalid_keywords = [keyword for keyword in keywords_in_braces if keyword not in SUPPORTED_ROW_FORMAT_KEYS]
if invalid_keywords:
errors.append(f"Invalid {row_type} row format keyword(s) found: {', '.join(invalid_keywords)}")
errors.append(f"Invalid {row_type} row format '{row_format}'. Invalid keyword(s) found: {', '.join(invalid_keywords)}")
return errors

0 comments on commit 17bfaf7

Please sign in to comment.