This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from baldrick.blueprints.github import github_webhook_handler | ||
from baldrick.github.github_api import IssueHandler, PullRequestHandler | ||
|
||
|
||
@github_webhook_handler | ||
def handle_closed_by_bot_label(repo_handler, payload, headers): | ||
""" | ||
Auto-apply closed-by-bot label when bot closes issue or pull request. | ||
""" | ||
event = headers['X-GitHub-Event'] | ||
|
||
if event not in ('pull_request', 'issues') or payload['action'] != 'closed': | ||
return "Not a closed pull_request or issues event" | ||
|
||
repository = repo_handler.repo | ||
installation = repo_handler.installation | ||
closed_by = payload['sender']['login'] # TODO: Is this correct??? | ||
|
||
if event == 'pull_request': | ||
number = payload['pull_request']['number'] | ||
handler = PullRequestHandler(repository, number, installation) | ||
elif event == 'issues': | ||
number = payload['issue']['number'] | ||
handler = IssueHandler(repository, number, installation) | ||
else: | ||
return "Not an issue or pull request" | ||
|
||
if closed_by == 'astropy-bot': | ||
handler.set_labels('closed-by-bot') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# TODO: Add tests here |