From 1689998861b4a613dc305f7c1b80627b2a376d18 Mon Sep 17 00:00:00 2001 From: evidencebp Date: Sun, 1 Dec 2024 19:13:40 +0200 Subject: [PATCH] bioconda_utils\autobump.py too-many-branches The method apply of the class CreatePullRequest had 14 branches and, while Pylint recommends having no more than 12. I extracted _handle_open_PRs to reduce the complexity. --- bioconda_utils/autobump.py | 54 ++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/bioconda_utils/autobump.py b/bioconda_utils/autobump.py index 936b88a4d9..9f8162bfcc 100644 --- a/bioconda_utils/autobump.py +++ b/bioconda_utils/autobump.py @@ -1163,31 +1163,7 @@ async def apply(self, recipe: Recipe) -> None: # check if we already have an open PR (=> update in progress) pullreqs = await self.ghub.get_prs(from_branch=branch_name, from_user="bioconda") if pullreqs: - if len(pullreqs) > 1: - logger.error("Multiple PRs updating %s: %s", - recipe, - ", ".join(str(pull['number']) for pull in pullreqs)) - for pull in pullreqs: - logger.debug("Found PR %i updating %s: %s", - pull["number"], recipe, pull["title"]) - # update the PR if title or body changed - pull = pullreqs[0] - if body == pull["body"]: - body = None - if title == pull["title"]: - title = None - if not (body is None and title is None): - if await self.ghub.modify_issue(number=pull['number'], body=body, title=title): - logger.info("Updated PR %i updating %s to %s", - pull['number'], recipe, recipe.version) - else: - logger.error("Failed to update PR %i with title=%s and body=%s", - pull['number'], title, body) - else: - logger.debug("Not updating PR %i updating %s - no changes", - pull['number'], recipe) - - raise self.UpdateInProgress(recipe) + title, body = await self._handle_open_PRs(recipe, title, body, pullreqs) # check for matching closed PR (=> update rejected) pullreqs = await self.ghub.get_prs(from_branch=branch_name, state=self.ghub.STATE.closed) @@ -1206,6 +1182,34 @@ async def apply(self, recipe: Recipe) -> None: logger.info("Created PR %i: %s", pull['number'], title) + async def _handle_open_PRs(self, recipe, title, body, pullreqs): + if len(pullreqs) > 1: + logger.error("Multiple PRs updating %s: %s", + recipe, + ", ".join(str(pull['number']) for pull in pullreqs)) + for pull in pullreqs: + logger.debug("Found PR %i updating %s: %s", + pull["number"], recipe, pull["title"]) + # update the PR if title or body changed + pull = pullreqs[0] + if body == pull["body"]: + body = None + if title == pull["title"]: + title = None + if not (body is None and title is None): + if await self.ghub.modify_issue(number=pull['number'], body=body, title=title): + logger.info("Updated PR %i updating %s to %s", + pull['number'], recipe, recipe.version) + else: + logger.error("Failed to update PR %i with title=%s and body=%s", + pull['number'], title, body) + else: + logger.debug("Not updating PR %i updating %s - no changes", + pull['number'], recipe) + + raise self.UpdateInProgress(recipe) + return title,body + class MaxUpdates(Filter): """Terminate pipeline after **max_updates** recipes have been updated."""