Skip to content

Instantly share code, notes, and snippets.

@isidentical
Created January 4, 2020 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isidentical/51e6da1f44ab2c26cc0cf067c976f56e to your computer and use it in GitHub Desktop.
Save isidentical/51e6da1f44ab2c26cc0cf067c976f56e to your computer and use it in GitHub Desktop.
@defer.inlineCallbacks
def handle_issue_comment(self, payload, event):
changes = []
comment = payload["comment"]["body"].split()
log.msg(f"Handled comment: {comment}")
if payload.get("action") != "created": # should we support edits?
return ([], "git")
if len(comment) < 2 and comment[0] != f"@{BOT}":
return ([], "git")
pull_request = payload["issue"].get("pull_request")
if pull_request is None:
return ([], "git")
else:
pull_request = pull_request["url"].replace(self.github_api_endpoint, "")
log.msg(pull_request)
headers = {
'User-Agent': 'Buildbot'
}
if self._token:
headers['Authorization'] = 'token ' + self._token
http = yield httpclientservice.HTTPClientService.getService(
self.master, self.github_api_endpoint, headers=headers,
debug=self.debug, verify=self.verify)
pr_payload = {}
pr_payload["action"] = "commented"
pr_payload["sender"] = payload["sender"].copy()
pr_payload["number"] = payload["issue"]["number"]
pr_payload["repository"] = payload["repository"].copy()
pull_request_object = yield http.get(pull_request)
pr_payload["pull_request"] = yield pull_request_object.json()
changes, vcs = yield self.handle_pull_request(pr_payload, event)
changes[0]["properties"].update({"action": comment[1]}) # ex: @mycustombot [run] x y
changes[0]["properties"].update({"bots": comment[2:]}) # ex: @mycustombot run [x y]
return changes, vcs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment