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

bot: when a generic bot failure occurs also report it in phabricator. #986

Merged
merged 2 commits into from
Sep 23, 2021
Merged
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
41 changes: 39 additions & 2 deletions bot/code_review_bot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from libmozdata.lando import LandoWarnings
from libmozdata.phabricator import BuildState
from libmozdata.phabricator import PhabricatorAPI
from libmozdata.phabricator import UnitResult
from libmozdata.phabricator import UnitResultState

from code_review_bot import AnalysisException
from code_review_bot import stats
Expand All @@ -26,6 +28,11 @@
logger = structlog.get_logger(__name__)


LANDO_FAILURE_MESSAGE = (
"Static analysis and linting did not run due to a generic failure."
)


def parse_cli():
"""
Setup CLI options parser
Expand Down Expand Up @@ -112,12 +119,17 @@ def main():

# lando the Lando API
lando_reporting_enabled = "lando" in reporters
lando_api = None
lando_publish_generic_failure = False
if lando_reporting_enabled:
if taskcluster.secrets["LANDO"].get("publish", False):
lando_api = LandoWarnings(
api_url=taskcluster.secrets["LANDO"]["url"],
api_key=phabricator["api_key"],
)
lando_publish_generic_failure = taskcluster.secrets["LANDO"][
"publish_failure"
]
reporters["lando"].setup_api(lando_api)

# Load unique revision
Expand Down Expand Up @@ -173,8 +185,33 @@ def main():
extras["error_message"] = str(e)
w.index(revision, state="error", **extras)

# Update Harbormaster status
w.update_status(revision, state=BuildState.Fail)
# Update Phabricator
failure = UnitResult(
abpostelnicu marked this conversation as resolved.
Show resolved Hide resolved
namespace="code-review",
name="general",
result=UnitResultState.Broken,
details="WARNING: A generic error occurred in the code review bot.",
format="remarkup",
duration=0,
)

w.phabricator.update_build_target(
revision.build_target_phid, BuildState.Fail, unit=[failure]
)

# Also update lando
if lando_publish_generic_failure:
try:
abpostelnicu marked this conversation as resolved.
Show resolved Hide resolved
lando_api.lando_api.del_all_warnings(
revision=revision.id, diff=revision.diff["id"]
)
lando_api.add_warning(
abpostelnicu marked this conversation as resolved.
Show resolved Hide resolved
LANDO_FAILURE_MESSAGE,
revision=revision.id,
diff=revision.diff["id"],
)
except Exception as ex:
logger.error(str(ex))

# Then raise to mark task as erroneous
raise
Expand Down