Skip to content
Draft
26 changes: 23 additions & 3 deletions bot/code_review_bot/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,25 @@ def publish_analysis_phabricator(payload, phabricator_api):
build.target_phid, BuildState.Fail, unit=[failure]
)

elif mode == "fail:git":
extra_content = ""
if build.missing_base_revision:
extra_content = f" because the parent revision ({build.base_revision}) does not exist on the target repository. If possible, you should publish that revision"

failure = UnitResult(
namespace="code-review",
name="git",
result=UnitResultState.Fail,
details="WARNING: The code review bot failed to apply your patch{}.\n\n```{}```".format(
extra_content, extras["message"]
),
format="remarkup",
duration=extras.get("duration", 0),
)
phabricator_api.update_build_target(
build.target_phid, BuildState.Fail, unit=[failure]
)

elif mode == "test_result":
result = UnitResult(
namespace="code-review",
Expand Down Expand Up @@ -192,10 +211,11 @@ def publish_analysis_lando(payload, lando_warnings):
except Exception as ex:
logger.error(str(ex), exc_info=True)

elif mode == "fail:mercurial":
# Send mercurial message to Lando
elif mode in ("fail:mercurial", "fail:git"):
# Send patch application failure message to Lando
logger.info(
"Publishing code review hg failure.",
"Publishing code review VCS failure.",
mode=mode,
revision=build.revision["id"],
diff=build.diff_id,
)
Expand Down
4 changes: 4 additions & 0 deletions bot/code_review_bot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ def main():
"ALLOWED_PATHS": ["*"],
"task_failures_ignored": [],
"ssh_key": None,
"GITHUB_APP_ID": None,
"GITHUB_APP_PRIVKEY": None,
"user_blacklist": [],
},
local_secrets=yaml.safe_load(args.configuration)
Expand All @@ -124,6 +126,8 @@ def main():
taskcluster.secrets["ssh_key"],
args.mercurial_repository,
args.github_repository,
github_app_id=taskcluster.secrets["GITHUB_APP_ID"],

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nicer to create a dedicated GITHUB maaping in the conf with the following parts:

  • app_id
  • app_privkey

This would allow adding more configuration later on (as the needs for Github will certainly grow in that code base).

Also you need to document these new options there : https://github.com/mozilla/code-review/blob/master/docs/configuration.md

github_app_privkey=taskcluster.secrets["GITHUB_APP_PRIVKEY"],
)

# Setup statistics
Expand Down
31 changes: 24 additions & 7 deletions bot/code_review_bot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
)
RepositoryConf = collections.namedtuple(
"RepositoryConf",
"name, try_name, url, try_url, decision_env_prefix, ssh_user",
"name, try_name, url, try_url, decision_env_prefix, ssh_user, repo_type",
# repo_type is optional and defaults to Mercurial so existing repository

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# secrets keep working; set it to "git" to push to a Git remote instead.
defaults=("hg",),
)


Expand Down Expand Up @@ -63,6 +66,10 @@ def __init__(self):
# SSH Key used to push on try
self.ssh_key = None

# GitHub App credentials used to push on Git try repositories
self.github_app_id = None
self.github_app_privkey = None

# List of users that should trigger a new analysis
# Indexed by their Phabricator ID
self.user_blacklist = {}
Expand All @@ -80,6 +87,8 @@ def setup(
ssh_key=None,
mercurial_cache=None,
git_cache=None,
github_app_id=None,
github_app_privkey=None,
):
# Detect source from env
if "TRY_TASK_ID" in os.environ and "TRY_TASK_GROUP_ID" in os.environ:
Expand Down Expand Up @@ -123,13 +132,18 @@ def build_conf(nb, repo):
assert isinstance(
repo, dict
), "Repository configuration #{nb+1} is not a dict"
data = []
data = {}
for key in RepositoryConf._fields:
assert (
key in repo
), f"Missing key {key} in repository configuration #{nb+1}"
data.append(repo[key])
return RepositoryConf._make(data)
if key in repo:
data[key] = repo[key]
elif key in RepositoryConf._field_defaults:
# Optional field, fall back to its default (e.g. repo_type)
data[key] = RepositoryConf._field_defaults[key]
else:
raise AssertionError(
f"Missing key {key} in repository configuration #{nb+1}"
)
return RepositoryConf(**data)

self.repositories = [build_conf(i, repo) for i, repo in enumerate(repositories)]
assert self.repositories, "No repositories available"
Expand Down Expand Up @@ -161,6 +175,9 @@ def build_conf(nb, repo):
# Fallback to mercurial cache to ease migration on production systems
self.git_cache = self.mercurial_cache

self.github_app_id = github_app_id
self.github_app_privkey = github_app_privkey

def load_user_blacklist(self, usernames, phabricator_api):
"""
Load all black listed users from Phabricator API
Expand Down
Loading