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
@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