Skip to content

Commit 1689998

Browse files
committed
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.
1 parent 71ca27e commit 1689998

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

bioconda_utils/autobump.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,31 +1163,7 @@ async def apply(self, recipe: Recipe) -> None:
11631163
# check if we already have an open PR (=> update in progress)
11641164
pullreqs = await self.ghub.get_prs(from_branch=branch_name, from_user="bioconda")
11651165
if pullreqs:
1166-
if len(pullreqs) > 1:
1167-
logger.error("Multiple PRs updating %s: %s",
1168-
recipe,
1169-
", ".join(str(pull['number']) for pull in pullreqs))
1170-
for pull in pullreqs:
1171-
logger.debug("Found PR %i updating %s: %s",
1172-
pull["number"], recipe, pull["title"])
1173-
# update the PR if title or body changed
1174-
pull = pullreqs[0]
1175-
if body == pull["body"]:
1176-
body = None
1177-
if title == pull["title"]:
1178-
title = None
1179-
if not (body is None and title is None):
1180-
if await self.ghub.modify_issue(number=pull['number'], body=body, title=title):
1181-
logger.info("Updated PR %i updating %s to %s",
1182-
pull['number'], recipe, recipe.version)
1183-
else:
1184-
logger.error("Failed to update PR %i with title=%s and body=%s",
1185-
pull['number'], title, body)
1186-
else:
1187-
logger.debug("Not updating PR %i updating %s - no changes",
1188-
pull['number'], recipe)
1189-
1190-
raise self.UpdateInProgress(recipe)
1166+
title, body = await self._handle_open_PRs(recipe, title, body, pullreqs)
11911167

11921168
# check for matching closed PR (=> update rejected)
11931169
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:
12061182

12071183
logger.info("Created PR %i: %s", pull['number'], title)
12081184

1185+
async def _handle_open_PRs(self, recipe, title, body, pullreqs):
1186+
if len(pullreqs) > 1:
1187+
logger.error("Multiple PRs updating %s: %s",
1188+
recipe,
1189+
", ".join(str(pull['number']) for pull in pullreqs))
1190+
for pull in pullreqs:
1191+
logger.debug("Found PR %i updating %s: %s",
1192+
pull["number"], recipe, pull["title"])
1193+
# update the PR if title or body changed
1194+
pull = pullreqs[0]
1195+
if body == pull["body"]:
1196+
body = None
1197+
if title == pull["title"]:
1198+
title = None
1199+
if not (body is None and title is None):
1200+
if await self.ghub.modify_issue(number=pull['number'], body=body, title=title):
1201+
logger.info("Updated PR %i updating %s to %s",
1202+
pull['number'], recipe, recipe.version)
1203+
else:
1204+
logger.error("Failed to update PR %i with title=%s and body=%s",
1205+
pull['number'], title, body)
1206+
else:
1207+
logger.debug("Not updating PR %i updating %s - no changes",
1208+
pull['number'], recipe)
1209+
1210+
raise self.UpdateInProgress(recipe)
1211+
return title,body
1212+
12091213

12101214
class MaxUpdates(Filter):
12111215
"""Terminate pipeline after **max_updates** recipes have been updated."""

0 commit comments

Comments
 (0)