Skip to content

Commit

Permalink
Add logging to the PR reporter (#549)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablogsal authored Oct 29, 2024
1 parent d5e7bc5 commit ea272af
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions master/custom/pr_reporter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import logging

from twisted.internet import defer
from twisted.python import log
Expand Down Expand Up @@ -62,6 +63,7 @@ class GitHubPullRequestReporter(reporters.GitHubStatusPush):
@defer.inlineCallbacks
def sendMessage(self, reports):
build = reports[0]['builds'][0]
log.msg("Considering reporting build :{}".format(build['buildid']), logLevel=logging.INFO)

props = Properties.fromDict(build["properties"])
props.master = self.master
Expand All @@ -80,6 +82,7 @@ def sendMessage(self, reports):
return

if state != "failure":
log.msg("Not reporting build {} as it is not a failure".format(build['buildid']), logLevel=logging.INFO)
return

yield getDetailsForBuild(self.master, build, want_logs=True, want_logs_content=True, want_steps=True)
Expand All @@ -91,23 +94,28 @@ def sendMessage(self, reports):
sourcestamps = build["buildset"].get("sourcestamps")

if not (sourcestamps and sourcestamps[0]):
log.msg("Build {} not reported as it doesn't have source stamps".format(build['buildid']), logLevel=logging.INFO)
return

changes = yield self.master.data.get(("builds", build["buildid"], "changes"))

if len(changes) != 1:
log.msg("Build {} not reported as it has more than one change".format(build['buildid']), logLevel=logging.INFO)
return

change = changes[0]
change_comments = change["comments"]

if not change_comments:
log.msg("Build {} not reported as no change comments could be found".format(build['buildid']), logLevel=logging.INFO)
return

# GH-42, gh-42, or #42
m = re.search(r"\((?:GH-|#)(\d+)\)", change_comments, flags=re.IGNORECASE)

if m is None:
log.msg("Build {} not reported as the issue could not be identified from the title".format(
build['buildid']), logLevel=logging.INFO)
return

issue = m.groups()[-1]
Expand All @@ -128,6 +136,7 @@ def sendMessage(self, reports):
)
)

log.msg("Attempting to issue a PR comment for failed build for build {}".format(build['buildid']), logLevel=logging.INFO)
try:
repo_user = repoOwner
repo_name = repoName
Expand Down

0 comments on commit ea272af

Please sign in to comment.