def open_many_files_adjusted_issue( self, adjusted_files: List[str], labels: List[str], ) -> None: """Open issue if multiple files are changed when updating version. Args: adjusted_files (List[str]): a list of files that were updated labels (List[str]): labels to apply to the issue Returns: None """ error_msg = constants._MULTIPLE_VERSIONS_FOUND_ISSUE_NAME _LOGGER.warning(error_msg) _issue_body = ( constants._MULTIPLE_VERSIONS_FOUND_ISSUE_BODY + "\n`" + ", ".join(adjusted_files) + "`" ) i = get_issue_by_title(self.issue.project, error_msg) if i is None: self.issue.project.create_issue( title=error_msg, body=f"{_issue_body}\nRelated: #{self.issue.id}", labels=labels, )
def open_no_files_adjusted_issue(self, labels) -> None: """Open issue if no files are changed when updating version. Args: labels (List[str]): labels to apply to the issue Returns: None """ error_msg = constants._NO_VERSION_FOUND_ISSUE_NAME _LOGGER.warning(error_msg) i = get_issue_by_title(self.issue.project, error_msg) if i is None: self.issue.project.create_issue( title=error_msg, body=f"Automated version release cannot be performed.\nRelated: #{self.issue.id}", labels=labels, )
def run( # type: ignore self, maintainers: list = None, assignees: list = None, labels: List[str] = [], changelog_file: bool = False, changelog_smart: bool = False, changelog_classifier: str = MLModel.DEFAULT.name, changelog_format: str = Format.DEFAULT.name, pr_releases: bool = True, release_label_config: dict = dict(), ) -> None: """Check issues for new issue request, if a request exists, issue a new PR with adjusted version in sources.""" self.labels = labels if self.parsed_payload: event_type = self.parsed_payload.get("event") if event_type not in _EVENTS_SUPPORTED: _LOGGER.info( "Version Manager doesn't act on %r events.", self.parsed_payload.get("event"), ) return trigger: BaseTrigger if ( pr_releases and self.parsed_payload and utils._is_merge_event(self.parsed_payload) ): trigger_pr = self.project.get_pr( utils._pr_id_from_webhook(self.parsed_payload) ) try: label_config = ReleaseLabelConfig.from_dict(release_label_config) except ValueError as exc: _LOGGER.warning(constants._INVALID_LABEL_CONFIG_ISSUE_NAME) i = get_issue_by_title( self.project, constants._INVALID_LABEL_CONFIG_ISSUE_NAME ) if i is None: self.project.create_issue( title=constants._INVALID_LABEL_CONFIG_ISSUE_NAME, body=messages.RELEASE_LABEL_CONFIG_INVALID, labels=labels, ) raise ManagerFailedException from exc trigger = ReleasePRlabels(label_config, trigger_pr) try: ( branch_name, new_version, changelog, has_prev_release, ) = self._branch_and_update_vers_and_changelog( trigger=trigger, changelog_smart=changelog_smart, changelog_classifier=changelog_classifier, changelog_format=changelog_format, changelog_file=changelog_file, ) except (ThothGlyphException, VersionError) as exc: if isinstance(exc, ThothGlyphException): _LOGGER.exception("Failed to generate smart release log.") trigger_pr.comment(str(exc)) raise ManagerFailedException from exc elif isinstance(exc, VersionError): _LOGGER.exception( "Failed to adjust version information in sources." ) trigger_pr.comment(str(exc)) raise ManagerFailedException from exc self._create_pr_for_trigger_release( trigger=trigger, changelog=changelog, branch_name=branch_name, new_version=new_version, has_prev_release=has_prev_release, ) reported_issues = [] version_update_complete = False for issue in self.project.get_issue_list(): issue_title = issue.title.strip() if issue_title.startswith( ( constants._NO_VERSION_FOUND_ISSUE_NAME, constants._MULTIPLE_VERSIONS_FOUND_ISSUE_NAME, ) ): # Reported issues that should be closed on success version change. reported_issues.append(issue) trigger = ReleaseIssue(issue) if not trigger.is_trigger(): continue elif version_update_complete: reported_issues.append( issue ) # will close duplicate version release issues continue # skip so that we don't open two PRs for same branch if assignees: try: issue.add_assignee(*assignees) except Exception: _LOGGER.exception( f"Failed to assign {assignees} to issue #{issue.id}" ) issue.comment( "Unable to assign provided assignees, please check bot configuration." ) maintainers = maintainers or self._get_maintainers() if issue.author.lower() not in (m.lower() for m in maintainers): issue.comment( f"Sorry, @{issue.author} but you are not stated in maintainers section for " f"this project. Maintainers are @" + ", @".join(maintainers) if maintainers else "Sorry, no maintainers configured." ) issue.close() # Next issue. continue _LOGGER.info( "Found an issue #%s which is a candidate for request of new version release: %s", issue.id, issue.title, ) try: ( branch_name, new_version, changelog, has_prev_release, ) = self._branch_and_update_vers_and_changelog( trigger=trigger, changelog_smart=changelog_smart, changelog_classifier=changelog_classifier, changelog_format=changelog_format, changelog_file=changelog_file, ) except (NoChangesException, ThothGlyphException, VersionError) as exc: if isinstance(exc, NoChangesException): message = f"Closing the issue as there is no changelog between the new release of {self.slug}." _LOGGER.info(message) issue.comment(message) issue.close() return elif isinstance(exc, ThothGlyphException): _LOGGER.exception("Failed to generate smart release log") issue.comment(str(exc)) issue.close() raise ManagerFailedException from exc elif isinstance(exc, VersionError): _LOGGER.exception("Failed to adjust version information in sources") issue.comment(str(exc)) issue.close() raise ManagerFailedException from exc self._create_pr_for_trigger_release( trigger=trigger, changelog=changelog, branch_name=branch_name, new_version=new_version, has_prev_release=has_prev_release, ) version_update_complete = ( True # do not create multiple PRs if multiple release issues exist ) for reported_issue in reported_issues: reported_issue.comment("Closing as this issue is no longer relevant.") reported_issue.close()
def get_issue_by_title(self, title: str) -> Optional[Issue]: """Get an ogr.Issue object with a matching title.""" return utils.get_issue_by_title(self.project, title)