Skip to content

Commit 198349a

Browse files
author
Steven Silvester
authored
Merge pull request #74 from blink1073/use-maintainer-can-modify
2 parents 7043526 + 3d7f02b commit 198349a

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

meeseeksdev/meeseeksbox/commands.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ def prep_for_command(name, session, payload, arguments, local_config=None):
321321
comment_url = payload["issue"]["comments_url"]
322322

323323
# collect extended payload on the PR
324+
# https://docs.github.com/en/rest/reference/pulls#get-a-pull-request
324325
print("== Collecting data on Pull-request...")
325326
r = session.ghrequest(
326327
"GET",
@@ -332,24 +333,31 @@ def prep_for_command(name, session, payload, arguments, local_config=None):
332333
branch = pr_data["head"]["ref"]
333334
author_login = pr_data["head"]["repo"]["owner"]["login"]
334335
repo_name = pr_data["head"]["repo"]["name"]
336+
maintainer_can_modify = pr_data["maintainer_can_modify"]
335337

336-
# that will likely fail, as if PR, we need to bypass the fact that the
337-
# requester has technically no access to committer repo.
338+
# Check to see if we can successfully push changees to the PR.
338339
target_session = yield "{}/{}".format(author_login, repo_name)
339340
if target_session:
340341
print("installed on target repository")
341342
atk = target_session.token()
342343
session.post_comment(comment_url, body=f"Running {name} on this Pull Request...")
343344
else:
344345
print("use allow edit as maintainer")
346+
if maintainer_can_modify:
347+
msg = "For now I will push as a maintainer since it is enabled."
348+
else:
349+
msg = 'I would push as a maintainer but I cannot unless "Allow edits from maintainers" is enabled for this Pull Request.'
345350
atk = session.token()
346351
session.post_comment(
347352
comment_url,
348-
body=f"@{author_login}, would you mind installing me on your fork so that I can update your branch? \n"
353+
body=f"@{author_login}, would you mind installing me on your fork so that I can update your branch?\n"
349354
"Click [here](https://github.com/apps/meeseeksdev/installations/new) "
350-
"to do that, and follow the instructions to add your fork. "
351-
"I'm going to try to push as a maintainer but this may not work.",
355+
"to do that, and follow the instructions to add your fork.\n\n"
356+
f"{msg}",
352357
)
358+
if not maintainer_can_modify:
359+
print("=== Bailing since we do not have permissions")
360+
return
353361

354362
if os.path.exists(repo_name):
355363
print("== Cleaning up previous work ... ")

0 commit comments

Comments
 (0)