Skip to content

Commit 9e0cfd7

Browse files
committed
Add a --github-repository argument to the local repo cache
1 parent 05857cf commit 9e0cfd7

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

bot/code_review_bot/__init__.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,30 @@ def hash(self):
191191
We make the assumption that the message does not contain the line number
192192
If an error occurs reading the file content (locally or remotely), None is returned
193193
"""
194+
from code_review_bot.revisions import GithubRevision, PhabricatorRevision
195+
194196
assert self.revision is not None, "Missing revision"
195197

198+
local_repository = None
199+
if (
200+
isinstance(self.revision, PhabricatorRevision)
201+
and settings.mercurial_cache_checkout
202+
):
203+
local_repository = settings.mercurial_cache_checkout
204+
elif isinstance(self.revision, GithubRevision):
205+
assert (
206+
settings.gtihub_cache
207+
), "Github cache repository is mandatory to analyse a github revision"
208+
local_repository = settings.gtihub_cache
209+
else:
210+
raise NotImplementedError
211+
196212
# Build the hash only if the file is not autogenerated.
197213
# An autogenerated file resides in the build directory that it has the
198214
# format `obj-x86_64-pc-linux-gnu`
199215
file_content = None
200216
if "/obj-" not in self.path:
201-
file_content = self.revision.get_file_content(
202-
self.path, settings.mercurial_cache_checkout
203-
)
217+
file_content = self.revision.get_file_content(self.path, local_repository)
204218

205219
if file_content is None:
206220
self._hash = None

bot/code_review_bot/cli.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
)
2727
from code_review_bot.config import settings
2828
from code_review_bot.report import get_reporters
29-
from code_review_bot.revisions import PhabricatorRevision, Revision
29+
from code_review_bot.revisions import GithubRevision, PhabricatorRevision, Revision
3030
from code_review_bot.tools.libmozdata import setup as setup_libmozdata
3131
from code_review_bot.tools.log import init_logger
3232
from code_review_bot.workflow import Workflow
@@ -64,6 +64,13 @@ def parse_cli():
6464
type=Path,
6565
default=None,
6666
)
67+
parser.add_argument(
68+
"--github-repository",
69+
help="Optional path to a up-to-date github repository matching the analyzed revision.\n"
70+
"This argument is required for Github reviusions in order to compute issues' hashes based on file content.",
71+
type=Path,
72+
default=None,
73+
)
6774
parser.add_argument("--taskcluster-client-id", help="Taskcluster Client ID")
6875
parser.add_argument("--taskcluster-access-token", help="Taskcluster Access token")
6976
return parser.parse_args()
@@ -116,6 +123,7 @@ def main():
116123
taskcluster.secrets["repositories"],
117124
taskcluster.secrets["ssh_key"],
118125
args.mercurial_repository,
126+
args.github_repository,
119127
)
120128

121129
# Setup statistics
@@ -205,6 +213,11 @@ def main():
205213
)
206214
return 1
207215

216+
if isinstance(revision, GithubRevision):
217+
assert (
218+
args.github_repository is not None
219+
), "Girhub revision analysis requires the --github-repository argument to be set"
220+
208221
# Run workflow according to source
209222
w = Workflow(
210223
reporters,

bot/code_review_bot/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def __init__(self):
5858

5959
# Cache to store whole repositories
6060
self.mercurial_cache = None
61+
self.github_cache = None
6162

6263
# SSH Key used to push on try
6364
self.ssh_key = None
@@ -78,6 +79,7 @@ def setup(
7879
repositories,
7980
ssh_key=None,
8081
mercurial_cache=None,
82+
github_cache=None,
8183
):
8284
# Detect source from env
8385
if "TRY_TASK_ID" in os.environ and "TRY_TASK_GROUP_ID" in os.environ:

0 commit comments

Comments
 (0)