switch from check_run to check_suite for github webhooks

This commit is contained in:
jesopo 2021-02-15 21:44:32 +00:00
parent c0810f80f5
commit bfb34a4eb9

View file

@ -5,6 +5,7 @@ COMMIT_URL = "https://github.com/%s/commit/%s"
COMMIT_RANGE_URL = "https://github.com/%s/compare/%s...%s" COMMIT_RANGE_URL = "https://github.com/%s/compare/%s...%s"
CREATE_URL = "https://github.com/%s/tree/%s" CREATE_URL = "https://github.com/%s/tree/%s"
PR_URL = "https://github.com/%s/pull/%s"
PR_COMMIT_RANGE_URL = "https://github.com/%s/pull/%s/files/%s..%s" PR_COMMIT_RANGE_URL = "https://github.com/%s/pull/%s/files/%s..%s"
PR_COMMIT_URL = "https://github.com/%s/pull/%s/commits/%s" PR_COMMIT_URL = "https://github.com/%s/pull/%s/commits/%s"
@ -77,15 +78,14 @@ COMMENT_ACTIONS = {
} }
COMMENT_MAX = 100 COMMENT_MAX = 100
CHECK_RUN_CONCLUSION = { CHECK_SUITE_CONCLUSION = {
"success": "passed", "success": ("passed", colors.COLOR_POSITIVE),
"failure": "failed", "failure": ("failed", colors.COLOR_NEGATIVE),
"neutral": "finished", "neutral": ("finished", colors.COLOR_NEUTRAL),
"cancelled": "was cancelled", "cancelled": ("was cancelled", colors.COLOR_NEGATIVE),
"timed_out": "timed out", "timed_out": ("timed out", colors.COLOR_NEGATIVE),
"action_required": "requires action" "action_required": ("requires action", colors.COLOR_NEUTRAL)
} }
CHECK_RUN_FAILURES = ["failure", "cancelled", "timed_out", "action_required"]
class GitHub(object): class GitHub(object):
def __init__(self, log, exports): def __init__(self, log, exports):
@ -126,8 +126,8 @@ class GitHub(object):
category_action = None category_action = None
if "review" in data and "state" in data["review"]: if "review" in data and "state" in data["review"]:
category = "%s+%s" % (event, data["review"]["state"]) category = "%s+%s" % (event, data["review"]["state"])
elif "check_run" in data and "status" in data["check_run"]: elif "check_suite" in data and "conclusion" in data["check_suite"]:
category = "%s+%s" % (event, data["check_run"]["status"]) category = "%s+%s" % (event, data["check_suite"]["conclusion"])
if action: if action:
if category: if category:
@ -162,8 +162,8 @@ class GitHub(object):
out = self.delete(full_name, data) out = self.delete(full_name, data)
elif event == "release": elif event == "release":
out = self.release(full_name, data) out = self.release(full_name, data)
elif event == "check_run": elif event == "check_suite":
out = self.check_run(data) out = self.check_suite(full_name, data)
elif event == "fork": elif event == "fork":
out = self.fork(full_name, data) out = self.fork(full_name, data)
elif event == "ping": elif event == "ping":
@ -436,50 +436,32 @@ class GitHub(object):
url = self._short_url(data["release"]["html_url"]) url = self._short_url(data["release"]["html_url"])
return ["%s %s a release%s - %s" % (author, action, name, url)] return ["%s %s a release%s - %s" % (author, action, name, url)]
def check_run(self, data): def check_suite(self, full_name, data):
name = data["check_run"]["name"] suite = data["check_suite"]
commit = self._short_hash(data["check_run"]["head_sha"])
commit = self._short_hash(suite["head_sha"])
commit = utils.irc.color(commit, utils.consts.LIGHTBLUE) commit = utils.irc.color(commit, utils.consts.LIGHTBLUE)
pr = "" pr = ""
if ("pull_requests" in data["check_run"] and
data["check_run"]["pull_requests"]):
pr_num = data["check_run"]["pull_requests"][0]["number"]
pr = "/PR%s" % utils.irc.color("#%s" % pr_num, colors.COLOR_ID)
url = "" url = ""
if data["check_run"]["details_url"]: if suite["pull_requests"]:
url = data["check_run"]["details_url"] pr_num = suite["pull_requests"][0]["number"]
url = " - %s" % self.exports.get("shorturl-any")(url) pr = "/PR%s" % utils.irc.color("#%s" % pr_num, colors.COLOR_ID)
url = self._short_url(PR_URL % (full_name, pr_num))
url = " - %s" % url
duration = "" name = suite["app"]["name"]
if data["check_run"]["completed_at"]: conclusion = suite["conclusion"]
started_at = self._iso8601(data["check_run"]["started_at"]) conclusion, conclusion_color = CHECK_SUITE_CONCLUSION[conclusion]
completed_at = self._iso8601(data["check_run"]["completed_at"]) conclusion = utils.irc.color(conclusion, conclusion_color)
if completed_at > started_at:
seconds = (completed_at-started_at).total_seconds()
duration = " in %s" % utils.datetime.format.to_pretty_time(
seconds)
status = data["check_run"]["status"] created_at = self._iso8601(suite["created_at"])
status_str = "" updated_at = self._iso8601(suite["updated_at"])
if status == "queued": seconds = (updated_at-created_at).total_seconds()
status_str = utils.irc.bold("queued") duration = utils.datetime.format.to_pretty_time(seconds)
elif status == "in_progress":
status_str = utils.irc.bold("started")
elif status == "completed":
conclusion = data["check_run"]["conclusion"]
conclusion_color = colors.COLOR_POSITIVE
if conclusion in CHECK_RUN_FAILURES:
conclusion_color = colors.COLOR_NEGATIVE
if conclusion == "neutral":
conclusion_color = colors.COLOR_NEUTRAL
status_str = utils.irc.color( return ["[build @%s%s] %s: %s in %s%s" % (
CHECK_RUN_CONCLUSION[conclusion], conclusion_color) commit, pr, name, conclusion, duration, url)]
return ["[build @%s%s] %s: %s%s%s" % (
commit, pr, name, status_str, duration, url)]
def fork(self, full_name, data): def fork(self, full_name, data):
forker = utils.irc.bold(data["sender"]["login"]) forker = utils.irc.bold(data["sender"]["login"])