Skip to content

Commit 7dfb11c

Browse files
sigieseczalun
authored andcommitted
Bug 1570648 - Handle inaccessible Phabricator revisions r=zalun
Reviewers: zalun Reviewed By: zalun Bug #: 1570648 Differential Revision: https://phabricator.services.mozilla.com/D39688
1 parent 8425010 commit 7dfb11c

4 files changed

Lines changed: 103 additions & 16 deletions

File tree

moz-phab

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -816,8 +816,11 @@ class ConduitAPI:
816816

817817
# Return revisions in the same order requested.
818818
if ids:
819+
# Skip revisions for which we do not have a query result.
819820
return [
820-
revisions[phids_by_id[rev_id]] for rev_id in ids if phids_by_id[rev_id]
821+
revisions[phids_by_id[rev_id]]
822+
for rev_id in ids
823+
if rev_id in phids_by_id
821824
]
822825
else:
823826
return [revisions[phid] for phid in phids]
@@ -1542,6 +1545,21 @@ class Repository(object):
15421545
if has_arc_rejections(commit["body"]):
15431546
commit_errors.append("contains arc fields")
15441547

1548+
if commit["rev-id"]:
1549+
revisions = conduit.get_revisions(ids=[int(commit["rev-id"])])
1550+
if len(revisions) == 0:
1551+
commit_errors.append(
1552+
"Phabricator did not return a query result for revision D%s"
1553+
" (it might be inaccessible or not exist at all)"
1554+
% commit["rev-id"]
1555+
)
1556+
1557+
# commit_issues identified below this are commit_errors unless
1558+
# self.args.force is True, which makes them commit_warnings
1559+
commit_issues = (
1560+
commit_warnings if self.args and self.args.force else commit_errors
1561+
)
1562+
15451563
for reviewer in commit_invalid_reviewers[commit["node"]]:
15461564
if "disabled" in reviewer:
15471565
commit_errors.append("User %s is disabled" % reviewer["name"])
@@ -1551,10 +1569,7 @@ class Repository(object):
15511569
reviewer["name"],
15521570
reviewer["until"],
15531571
)
1554-
if self.args.force:
1555-
commit_warnings.append(msg)
1556-
else:
1557-
commit_errors.append(msg)
1572+
commit_issues.append(msg)
15581573
else:
15591574
commit_errors.append(
15601575
"%s is not a valid reviewer's name" % reviewer["name"]
@@ -3225,16 +3240,21 @@ def show_commit_stack(
32253240
if commit.get("rev-id"):
32263241
action = action_template % ("D" + commit["rev-id"])
32273242
if validate:
3228-
revision = conduit.get_revisions(ids=[int(commit["rev-id"])])[0]
3229-
# Check if target bug ID is the same as in the Phabricator revision
3230-
change_bug_id = revision["fields"]["bugzilla.bug-id"] and (
3231-
commit["bug-id"] != revision["fields"]["bugzilla.bug-id"]
3232-
)
3233-
# Check if comandeering is required
3234-
whoami = conduit.whoami()
3235-
if revision["fields"]["authorPHID"] != whoami["phid"]:
3236-
is_author = False
3243+
revisions = conduit.get_revisions(ids=[int(commit["rev-id"])])
3244+
if len(revisions) > 0:
3245+
revision = revisions[0]
3246+
3247+
# Check if target bug ID is the same as in the Phabricator revision
3248+
change_bug_id = revision["fields"]["bugzilla.bug-id"] and (
3249+
commit["bug-id"] != revision["fields"]["bugzilla.bug-id"]
3250+
)
32373251

3252+
# Check if comandeering is required
3253+
whoami = conduit.whoami()
3254+
if "authorPHID" in revision["fields"] and (
3255+
revision["fields"]["authorPHID"] != whoami["phid"]
3256+
):
3257+
is_author = False
32383258
else:
32393259
action = action_template % "New"
32403260

tests/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ def in_process(monkeypatch, safe_environ, request):
161161
# Disable calls to sys.exit() at the end of the script. Re-raise errors instead
162162
# to make test debugging easier.
163163
def reraise(*args, **kwargs):
164-
t, v, tb = sys.exc_info()
165-
raise (t, v, tb)
164+
raise
166165

167166
monkeypatch.setattr(sys, "exit", reraise)
168167

tests/test_conduit.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,16 @@ def test_get_revisions_search_by_phids_ordering(get_revs, m_call):
222222
]
223223

224224

225+
def test_get_revisions_search_by_revids_missing(get_revs, m_call):
226+
"""phabricator does not return info on all rev ids"""
227+
m_call.return_value = multiple_phab_result
228+
assert get_revs(ids=[2, 4, 1, 3]) == [
229+
dict(id=2, phid="PHID-2"),
230+
dict(id=1, phid="PHID-1"),
231+
dict(id=3, phid="PHID-3"),
232+
]
233+
234+
225235
@mock.patch("mozphab.ConduitAPI.call")
226236
def test_get_diffs(m_call):
227237
conduit = mozphab.conduit

tests/test_integration-git.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,3 +475,61 @@ def test_submit_update_bug_id(in_process, git_repo_path, init_sha):
475475
},
476476
mock.ANY,
477477
)
478+
479+
480+
def test_submit_update_revision_not_found(in_process, git_repo_path, init_sha):
481+
call_conduit.reset_mock()
482+
call_conduit.side_effect = (
483+
# ping
484+
dict(),
485+
# response for searching D123 and D124
486+
dict(
487+
data=[
488+
{
489+
"fields": {
490+
"bugzilla.bug-id": "1",
491+
"status": {"value": "needs-review"},
492+
},
493+
"phid": "PHID-DREV-y7x5hvdpe2gyerctdqqz",
494+
"id": 123,
495+
"attachments": {"reviewers": {"reviewers": []}},
496+
}
497+
]
498+
),
499+
# moz-phab asks again for D124
500+
dict(data=[]),
501+
# moz-phab asks again for D124
502+
dict(data=[]),
503+
# moz-phab asks again for D124
504+
dict(data=[]),
505+
)
506+
testfile = git_repo_path / "X"
507+
testfile.write_text(u"ą")
508+
git_out("add", ".")
509+
msgfile = git_repo_path / "msg"
510+
msgfile.write_text(
511+
u"""\
512+
Bug 1 - Ą
513+
514+
Differential Revision: http://example.test/D123
515+
"""
516+
)
517+
git_out("commit", "--file", "msg")
518+
testfile.write_text(u"missing repo")
519+
msgfile.write_text(
520+
u"""\
521+
Bug 1 - missing revision
522+
523+
Differential Revision: http://example.test/D124
524+
"""
525+
)
526+
git_out("commit", "--all", "--file", "./msg")
527+
528+
with pytest.raises(mozphab.Error) as excinfo:
529+
mozphab.main(
530+
["submit", "--yes", "--no-arc"]
531+
+ ["--bug", "1"]
532+
+ ["--message", "update message ćwikła"]
533+
+ [init_sha]
534+
)
535+
assert "query result for revision D124" in str(excinfo.value)

0 commit comments

Comments
 (0)