Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
Webhook to add closed-by-bot label
Browse files Browse the repository at this point in the history
  • Loading branch information
pllim committed Aug 7, 2019
1 parent f075eac commit 0ac4e15
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions astropy_bot/closedbybotlabel.py
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')
1 change: 1 addition & 0 deletions astropy_bot/tests/test_closedbybotlabel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TODO: Add tests here

0 comments on commit 0ac4e15

Please sign in to comment.