Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include extra information in metadata comments #63

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions homu/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def render(self):


class BuildStarted(Comment):
params = ["head_sha", "merge_sha"]
params = ["head_sha", "merge_sha", "started_at"]

def render(self):
return ":hourglass: Testing commit %s with merge %s..." % (
Expand All @@ -81,7 +81,7 @@ def render(self):


class TryBuildStarted(Comment):
params = ["head_sha", "merge_sha"]
params = ["head_sha", "merge_sha", "started_at"]

def render(self):
return ":hourglass: Trying commit %s with merge %s..." % (
Expand All @@ -90,7 +90,7 @@ def render(self):


class BuildCompleted(Comment):
params = ["approved_by", "base_ref", "builders", "merge_sha"]
params = ["approved_by", "base_ref", "builders", "merge_sha", "ended_at"]

def render(self):
urls = ", ".join(
Expand All @@ -107,7 +107,7 @@ def render(self):


class TryBuildCompleted(Comment):
params = ["builders", "merge_sha"]
params = ["builders", "merge_sha", "ended_at"]

def render(self):
urls = ", ".join(
Expand All @@ -119,7 +119,7 @@ def render(self):


class BuildFailed(Comment):
params = ["builder_url", "builder_name"]
params = ["builder_url", "builder_name", "merge_sha", "ended_at"]

def render(self):
return ":broken_heart: Test failed - [%s](%s)" % (
Expand All @@ -128,7 +128,7 @@ def render(self):


class TryBuildFailed(Comment):
params = ["builder_url", "builder_name"]
params = ["builder_url", "builder_name", "merge_sha", "ended_at"]

def render(self):
return ":broken_heart: Test failed - [%s](%s)" % (
Expand All @@ -137,7 +137,7 @@ def render(self):


class TimedOut(Comment):
params = []
params = ["merge_sha", "ended_at"]

def render(self):
return ":boom: Test timed out"
13 changes: 11 additions & 2 deletions homu/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
from . import utils
from .parse_issue_comment import parse_issue_comment
from .auth import verify as verify_auth
from .utils import lazy_debug
from .utils import (
iso_utc_now,
lazy_debug,
)
import logging
from threading import Thread, Lock, Timer
import time
Expand Down Expand Up @@ -381,6 +384,7 @@ def timed_out():
def timed_out(self):
print('* Test timed out: {}'.format(self))

merge_sha = self.merge_sha
self.merge_sha = ''
self.save()
self.set_status('failure')
Expand All @@ -392,7 +396,10 @@ def timed_out(self):
'',
'Test timed out',
context='homu')
self.add_comment(comments.TimedOut())
self.add_comment(comments.TimedOut(
merge_sha=merge_sha,
ended_at=iso_utc_now(),
))
self.change_labels(LabelEvent.TIMED_OUT)

def record_retry_log(self, src, body):
Expand Down Expand Up @@ -1301,11 +1308,13 @@ def start_build(state, repo_cfgs, buildbot_slots, logger, db, git_cfg):
state.add_comment(comments.TryBuildStarted(
head_sha=state.head_sha,
merge_sha=state.merge_sha,
started_at=iso_utc_now(),
))
else:
state.add_comment(comments.BuildStarted(
head_sha=state.head_sha,
merge_sha=state.merge_sha,
started_at=iso_utc_now(),
))

return True
Expand Down
24 changes: 20 additions & 4 deletions homu/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
)
from . import comments
from . import utils
from .utils import lazy_debug
from .utils import (
iso_utc_now,
lazy_debug,
)
import github3
import jinja2
import requests
Expand Down Expand Up @@ -581,6 +584,8 @@ def fail(err):
except ValueError:
return 'OK'

sha = info['sha']

status_name = ""
if 'status' in repo_cfg:
for name, value in repo_cfg['status'].items():
Expand All @@ -596,7 +601,7 @@ def fail(err):
if row['name'] == state.base_ref:
return 'OK'

report_build_res(info['state'] == 'success', info['target_url'],
report_build_res(info['state'] == 'success', sha, info['target_url'],
'status-' + status_name, state, logger, repo_cfg)

elif event_type == 'check_run':
Expand All @@ -605,6 +610,8 @@ def fail(err):
except ValueError:
return 'OK'

sha = info['check_run']['head_sha']

current_run_name = info['check_run']['name']
checks_name = None
if 'checks' in repo_cfg:
Expand All @@ -624,6 +631,7 @@ def fail(err):

report_build_res(
info['check_run']['conclusion'] == 'success',
sha,
info['check_run']['details_url'],
'checks-' + checks_name,
state, logger, repo_cfg,
Expand All @@ -632,7 +640,7 @@ def fail(err):
return 'OK'


def report_build_res(succ, url, builder, state, logger, repo_cfg):
def report_build_res(succ, sha, url, builder, state, logger, repo_cfg):
lazy_debug(logger,
lambda: 'build result {}: builder = {}, succ = {}, current build_res = {}' # noqa
.format(state, builder, succ,
Expand All @@ -654,6 +662,7 @@ def report_build_res(succ, url, builder, state, logger, repo_cfg):
base_ref=state.base_ref,
builders={k: v["url"] for k, v in state.build_res.items()},
merge_sha=state.merge_sha,
ended_at=iso_utc_now(),
))
state.change_labels(LabelEvent.SUCCEED)
try:
Expand Down Expand Up @@ -685,6 +694,7 @@ def report_build_res(succ, url, builder, state, logger, repo_cfg):
state.add_comment(comments.TryBuildCompleted(
builders={k: v["url"] for k, v in state.build_res.items()},
merge_sha=state.merge_sha,
ended_at=iso_utc_now(),
))
state.change_labels(LabelEvent.TRY_SUCCEED)

Expand All @@ -700,12 +710,16 @@ def report_build_res(succ, url, builder, state, logger, repo_cfg):
state.add_comment(comments.TryBuildFailed(
builder_url=url,
builder_name=builder,
merge_sha=sha,
ended_at=iso_utc_now(),
))
state.change_labels(LabelEvent.TRY_FAILED)
else:
state.add_comment(comments.BuildFailed(
builder_url=url,
builder_name=builder,
merge_sha=sha,
ended_at=iso_utc_now(),
))
state.change_labels(LabelEvent.FAILED)

Expand All @@ -730,6 +744,8 @@ def buildbot():
if not props['revision']:
continue

sha = props['revision']

try:
state, repo_label = find_state(props['revision'])
except ValueError:
Expand Down Expand Up @@ -808,7 +824,7 @@ def buildbot():
else:
logger.error('Corrupt payload from Buildbot')

report_build_res(build_succ, url, info['builderName'],
report_build_res(build_succ, sha, url, info['builderName'],
state, logger, repo_cfg)

elif row['event'] == 'buildStarted':
Expand Down
8 changes: 8 additions & 0 deletions homu/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
import traceback
import requests
import time
import datetime


def iso_utc_now():
return datetime.datetime \
.utcnow() \
.replace(tzinfo=datetime.timezone.utc, microsecond=0) \
.isoformat()


def github_set_ref(repo, ref, sha, *, force=False, auto_create=True, retry=1):
Expand Down