Skip to content

Commit 7043526

Browse files
author
Steven Silvester
authored
Merge pull request #73 from blink1073/another-pre-commit-fix
2 parents d377dda + 632e040 commit 7043526

1 file changed

Lines changed: 28 additions & 22 deletions

File tree

meeseeksdev/meeseeksbox/commands.py

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,6 @@ def push_the_work(session, payload, arguments, local_config=None):
387387
prnumber = payload["issue"]["number"]
388388
org_name = payload["repository"]["owner"]["login"]
389389
repo_name = payload["repository"]["name"]
390-
comment_url = payload["issue"]["comments_url"]
391390

392391
# collect extended payload on the PR
393392
print("== Collecting data on Pull-request...")
@@ -406,18 +405,19 @@ def push_the_work(session, payload, arguments, local_config=None):
406405
# Push the work
407406
print("== Pushing work....:")
408407
print(f"pushing with workbranch:{branch}")
408+
succeeded = True
409409
try:
410410
repo.remotes.origin.push("workbranch:{}".format(branch), force=True)
411411
except Exception:
412-
session.post_comment(comment_url, body="I was unable to push due to errors")
413-
return
412+
succeeded = False
414413

415414
# Clean up
416415
default_branch = session.ghrequest(
417416
"GET", f"https://api.github.com/repos/{org_name}/{repo_name}"
418417
).json()["default_branch"]
419418
repo.git.checkout(default_branch)
420419
repo.branches.workbranch.delete(repo, "workbranch", force=True)
420+
return succeeded
421421

422422

423423
@admin
@@ -497,19 +497,22 @@ def precommit(*, session, payload, arguments, local_config=None):
497497
),
498498
)
499499

500-
push_the_work(session, payload, arguments, local_config=local_config)
500+
succeeded = push_the_work(session, payload, arguments, local_config=local_config)
501501

502502
# Tell the caller we've finished
503503
comment_url = payload["issue"]["comments_url"]
504-
session.post_comment(
505-
comment_url,
506-
body=dedent(
504+
if succeeded:
505+
session.post_comment(
506+
comment_url,
507+
body=dedent(
508+
"""
509+
I've applied "pre-commit" and pushed. You may have trouble pushing further
510+
commits, but feel free to force push and ask me to run again.
507511
"""
508-
I've applied "pre-commit" and pushed. You may have trouble pushing further
509-
commits, but feel free to force push and ask me to run again.
510-
"""
511-
),
512-
)
512+
),
513+
)
514+
else:
515+
session.post_comment(comment_url, body="I was unable to push due to errors")
513516

514517

515518
@admin
@@ -566,19 +569,22 @@ def blackify(*, session, payload, arguments, local_config=None):
566569
)
567570
return
568571

569-
push_the_work(session, payload, arguments, local_config=local_config)
572+
succeeded = push_the_work(session, payload, arguments, local_config=local_config)
570573

571574
# Tell the caller we've finished
572-
session.post_comment(
573-
comment_url,
574-
body=dedent(
575+
if succeeded:
576+
session.post_comment(
577+
comment_url,
578+
body=dedent(
579+
"""
580+
I've rebased this Pull Request, applied `black` on all the
581+
individual commits, and pushed. You may have trouble pushing further
582+
commits, but feel free to force push and ask me to reformat again.
575583
"""
576-
I've rebased this Pull Request, applied `black` on all the
577-
individual commits, and pushed. You may have trouble pushing further
578-
commits, but feel free to force push and ask me to reformat again.
579-
"""
580-
),
581-
)
584+
),
585+
)
586+
else:
587+
session.post_comment(comment_url, body="I was unable to push due to errors")
582588

583589

584590
@write

0 commit comments

Comments
 (0)