Commit 32978d96 authored by agable's avatar agable Committed by Commit bot

git-cl-land: print url of final commit location

BUG=661187

Review-Url: https://codereview.chromium.org/2466953003
parent 86fe47d1
......@@ -483,6 +483,12 @@ def GetChangeDetail(host, change, o_params=None):
return ReadHttpJsonResponse(CreateHttpConn(host, path))
def GetChangeCommit(host, change, revision='current'):
"""Query a gerrit server for a revision associated with a change."""
path = 'changes/%s/revisions/%s/commit?links' % (change, revision)
return ReadHttpJsonResponse(CreateHttpConn(host, path))
def GetChangeDescriptionFromGitiles(url, revision):
"""Query Gitiles for actual commit message for a given url and ref.
......
......@@ -2497,6 +2497,14 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
raise GerritIssueNotExists(issue, self.GetCodereviewServer())
return data
def _GetChangeCommit(self, issue=None):
issue = issue or self.GetIssue()
assert issue, 'issue is required to query Gerrit'
data = gerrit_util.GetChangeCommit(self._GetGerritHost(), str(issue))
if not data:
raise GerritIssueNotExists(issue, self.GetCodereviewServer())
return data
def CMDLand(self, force, bypass_hooks, verbose):
if git_common.is_dirty_git_tree('land'):
return 1
......@@ -2535,6 +2543,11 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
self.SubmitIssue(wait_for_merge=True)
print('Issue %s has been submitted.' % self.GetIssueURL())
links = self._GetChangeCommit().get('web_links', [])
for link in links:
if link.get('name') == 'gerrit' and link.get('url'):
print('Landed as %s' % link.get('url'))
break
return 0
def CMDPatchWithParsedIssue(self, parsed_issue_arg, reject, nocommit,
......
......@@ -2118,11 +2118,17 @@ class TestGitCl(TestCase):
'labels': {},
'current_revision': 'deadbeaf',
}
cl._codereview_impl._GetChangeCommit = lambda: {
'commit': 'deadbeef',
'web_links': [{'name': 'gerrit',
'url': 'https://git.googlesource.com/test/+/deadbeef'}],
}
cl._codereview_impl.SubmitIssue = lambda wait_for_merge: None
out = StringIO.StringIO()
self.mock(sys, 'stdout', out)
self.assertEqual(0, cl.CMDLand(force=True, bypass_hooks=True, verbose=True))
self.assertRegexpMatches(out.getvalue(), 'Issue.*123 has been submitted')
self.assertRegexpMatches(out.getvalue(), 'Landed as .*deadbeef')
BUILDBUCKET_BUILDS_MAP = {
'9000': {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment