Commit 625986db authored by Andrii Shyshkalov's avatar Andrii Shyshkalov Committed by Commit Bot

git cl comment: implement adding comment for Gerrit.

BUG=698236

Change-Id: Ia1a36af71c348be991d77083092c5043c2642c19
Reviewed-on: https://chromium-review.googlesource.com/455877Reviewed-by: 's avatarAaron Gable <agable@chromium.org>
Commit-Queue: Andrii Shyshkalov <tandrii@chromium.org>
parent aa534e50
......@@ -1654,6 +1654,9 @@ class Changelist(object):
# Forward methods to codereview specific implementation.
def AddComment(self, message):
return self._codereview_impl.AddComment(message)
def CloseIssue(self):
return self._codereview_impl.CloseIssue()
......@@ -1752,6 +1755,10 @@ class _ChangelistCodereviewBase(object):
"""Update the description on codereview site."""
raise NotImplementedError()
def AddComment(self, message):
"""Posts a comment to the codereview site."""
raise NotImplementedError()
def CloseIssue(self):
"""Closes the issue."""
raise NotImplementedError()
......@@ -2488,6 +2495,10 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
gerrit_util.SetCommitMessage(self._GetGerritHost(), self.GetIssue(),
description, notify='NONE')
def AddComment(self, message):
gerrit_util.SetReview(self._GetGerritHost(), self.GetIssue(),
msg=message)
def CloseIssue(self):
gerrit_util.AbandonChange(self._GetGerritHost(), self.GetIssue(), msg='')
......@@ -4198,11 +4209,13 @@ def CMDcomments(parser, args):
parser.add_option('-a', '--add-comment', dest='comment',
help='comment to add to an issue')
parser.add_option('-i', dest='issue',
help="review issue id (defaults to current issue)")
help='review issue id (defaults to current issue)')
parser.add_option('-j', '--json-file',
help='File to write JSON summary to')
auth.add_auth_options(parser)
_add_codereview_select_options(parser)
options, args = parser.parse_args(args)
_process_codereview_select_options(parser, options)
auth_config = auth.extract_auth_config_from_options(options)
issue = None
......@@ -4212,7 +4225,10 @@ def CMDcomments(parser, args):
except ValueError:
DieWithError('A review issue id is expected to be a number')
cl = Changelist(issue=issue, codereview='rietveld', auth_config=auth_config)
cl = Changelist(issue=issue,
# TODO(tandrii): remove 'rietveld' default.
codereview=options.forced_codereview or 'rietveld',
auth_config=auth_config)
if options.comment:
cl.AddComment(options.comment)
......
......@@ -3089,6 +3089,34 @@ class TestGitCl(TestCase):
sys.stdout.getvalue(),
'However, your configured .gitcookies file is missing.')
def test_git_cl_comment_add_default(self):
self.mock(git_cl._RietveldChangelistImpl, 'AddComment',
lambda _, message: self._mocked_call('AddComment', message))
self.calls = [
((['git', 'config', 'rietveld.autoupdate'],), CERR1),
((['git', 'config', 'rietveld.server'],), 'codereview.chromium.org'),
(('AddComment', 'msg'), ''),
]
# TODO(tandrii): --rietveld should be specified here.
self.assertEqual(0, git_cl.main(['comment', '-i', '10', '-a', 'msg']))
def test_git_cl_comment_add_gerrit(self):
self.mock(git_cl.gerrit_util, 'SetReview',
lambda host, change, msg:
self._mocked_call('SetReview', host, change, msg))
self.calls = [
((['git', 'symbolic-ref', 'HEAD'],), CERR1),
((['git', 'symbolic-ref', 'HEAD'],), CERR1),
((['git', 'config', 'rietveld.upstream-branch'],), CERR1),
((['git', 'branch', '-r'],), 'origin/HEAD -> origin/master\n'
'origin/master'),
((['git', 'config', 'remote.origin.url'],),
'https://chromium.googlesource.com/infra/infra'),
(('SetReview', 'chromium-review.googlesource.com', 10, 'msg'), None),
]
self.assertEqual(0, git_cl.main(['comment', '--gerrit', '-i', '10',
'-a', 'msg']))
if __name__ == '__main__':
logging.basicConfig(
......
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