This repository was archived by the owner on May 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Fix notifier without any layout #826
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,13 +1,12 @@ | ||
| import logging | ||
| from typing import Callable, List | ||
| from typing import Callable | ||
|
|
||
| from shared.django_apps.core.models import Repository | ||
| from shared.reports.resources import ReportTotals | ||
| from shared.validation.helpers import LayoutStructure | ||
|
|
||
| from database.models.core import Owner | ||
| from helpers.environment import is_enterprise | ||
| from helpers.metrics import metrics | ||
| from services.billing import BillingPlan | ||
| from services.comparison import ComparisonProxy, FilteredComparison | ||
| from services.notification.notifiers.mixins.message.helpers import ( | ||
|
|
@@ -202,98 +201,92 @@ | |
| def _team_plan_notification( | ||
| self, | ||
| comparison: ComparisonProxy, | ||
| message: List[str], | ||
| message: list[str], | ||
| diff, | ||
| settings, | ||
| links, | ||
| current_yaml, | ||
| ) -> List[str]: | ||
| ) -> list[str]: | ||
| writer_class = TeamPlanWriter() | ||
|
|
||
| with metrics.timer( | ||
| f"worker.services.notifications.notifiers.comment.section.{writer_class.name}" | ||
| ): | ||
| # Settings here enable failed tests results for now as a new product | ||
| message.extend( | ||
| line | ||
| for line in writer_class.header_lines( | ||
| comparison=comparison, diff=diff, settings=settings | ||
| ) | ||
| # Settings here enable failed tests results for now as a new product | ||
giovanni-guidini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| message.extend( | ||
| writer_class.header_lines( | ||
| comparison=comparison, diff=diff, settings=settings | ||
| ) | ||
| message.extend( | ||
| line | ||
| for line in writer_class.middle_lines( | ||
| comparison=comparison, | ||
| diff=diff, | ||
| links=links, | ||
| current_yaml=current_yaml, | ||
| ) | ||
| ) | ||
| message.extend( | ||
| writer_class.middle_lines( | ||
| comparison=comparison, | ||
| diff=diff, | ||
| links=links, | ||
| current_yaml=current_yaml, | ||
| ) | ||
| message.extend(line for line in writer_class.footer_lines()) | ||
| ) | ||
| message.extend(writer_class.footer_lines()) | ||
|
|
||
| return message | ||
| return message | ||
|
|
||
| def write_section_to_msg( | ||
| self, comparison, changes, diff, links, write, section_writer, behind_by=None | ||
| ): | ||
| wrote_something: bool = False | ||
| with metrics.timer( | ||
| f"worker.services.notifications.notifiers.comment.section.{section_writer.name}" | ||
|
|
||
| for line in section_writer.write_section( | ||
| comparison, diff, changes, links, behind_by=behind_by | ||
| ): | ||
| for line in section_writer.write_section( | ||
| comparison, diff, changes, links, behind_by=behind_by | ||
| ): | ||
| wrote_something |= line is not None | ||
| write(line) | ||
| wrote_something |= line is not None | ||
| write(line) | ||
|
|
||
| if wrote_something: | ||
| write("") | ||
|
|
||
| def get_middle_layout_section_names(self, settings): | ||
| sections = map( | ||
| lambda layout: layout.strip(), (settings["layout"] or "").split(",") | ||
| ) | ||
| return [ | ||
| section | ||
| for section in sections | ||
| if section | ||
| not in [ | ||
| "header", | ||
| "newheader", | ||
| "newfooter", | ||
| "newfiles", | ||
| "condensed_header", | ||
| "condensed_footer", | ||
| "condensed_files", | ||
| ] | ||
| ] | ||
|
|
||
| def get_upper_section_names(self, settings): | ||
| sections = list( | ||
| map(lambda layout: layout.strip(), (settings["layout"] or "").split(",")) | ||
| ) | ||
| headers = ["newheader", "header", "condensed_header"] | ||
| if all(x not in sections for x in headers): | ||
| def get_middle_layout_section_names(self, settings: dict) -> list[str]: | ||
| filtered_sections = { | ||
| "header", | ||
| "newheader", | ||
| "newfooter", | ||
| "newfiles", | ||
| "condensed_header", | ||
| "condensed_footer", | ||
| "condensed_files", | ||
| } | ||
|
|
||
| sections = get_sections(settings) | ||
|
|
||
| return [section for section in sections if section not in filtered_sections] | ||
|
|
||
| def get_upper_section_names(self, settings: dict) -> list[str]: | ||
| headers = {"newheader", "header", "condensed_header"} | ||
| allowed_sections = { | ||
| "header", | ||
| "newheader", | ||
| "condensed_header", | ||
| "newfiles", | ||
| "condensed_files", | ||
| } | ||
|
|
||
| sections = get_sections(settings) | ||
|
|
||
| if set(sections).isdisjoint(headers): | ||
| sections.insert(0, "condensed_header") | ||
|
|
||
| if "files" in sections or "tree" in sections: | ||
| sections.append("newfiles") | ||
|
|
||
| return [ | ||
| section | ||
| for section in sections | ||
| if section | ||
| in [ | ||
| "header", | ||
| "newheader", | ||
| "condensed_header", | ||
| "newfiles", | ||
| "condensed_files", | ||
| ] | ||
| ] | ||
|
|
||
| def get_lower_section_name(self, settings): | ||
| if ( | ||
| "newfooter" in settings["layout"] | ||
| or "condensed_footer" in settings["layout"] | ||
| ): | ||
| return [section for section in sections if section in allowed_sections] | ||
|
|
||
| def get_lower_section_name(self, settings: dict) -> str | None: | ||
| sections = get_sections(settings) | ||
|
|
||
| if "newfooter" in sections or "condensed_footer" in sections: | ||
| return "newfooter" | ||
| return None | ||
|
|
||
|
|
||
| def get_sections(settings: dict) -> list[str]: | ||
| layout = (settings.get("layout") or "").strip() | ||
| if not layout: | ||
| return [] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think if you return nothing the PR comment would be empty. The default value is here (and it should not be lost when the YAML is processed, but merged with the user's option - I think that's the real bug) |
||
|
|
||
| return [section.strip() for section in layout.split(",")] | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.