Commit e4efd51b authored by apavlov@chromium.org's avatar apavlov@chromium.org

Extend the git-cl-comments command functionality

The "comments" command is taught to:
- accept an arbitrary review issue id;
- post comments on the current or specified review issue.

This is required for the auto-rebaseline bot to notify a
rebaseline requestor of the fact that the rebaseline has happened
by means of posting a comment to the review issue that requested
the rebaseline, as suggested by iannucci@.

R=iannucci, szager, dpranke

Review URL: https://codereview.chromium.org/693873002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@292844 0039d316-1c4b-4281-b951-d872f2087c98
parent 43b48640
...@@ -787,6 +787,9 @@ or verify this branch is set up to track another (via the --track argument to ...@@ -787,6 +787,9 @@ or verify this branch is set up to track another (via the --track argument to
def GetApprovingReviewers(self): def GetApprovingReviewers(self):
return get_approving_reviewers(self.GetIssueProperties()) return get_approving_reviewers(self.GetIssueProperties())
def AddComment(self, message):
return self.RpcServer().add_comment(self.GetIssue(), message)
def SetIssue(self, issue): def SetIssue(self, issue):
"""Set this branch's issue. If issue=0, clears the issue.""" """Set this branch's issue. If issue=0, clears the issue."""
if issue: if issue:
...@@ -1438,28 +1441,41 @@ def CMDissue(parser, args): ...@@ -1438,28 +1441,41 @@ def CMDissue(parser, args):
def CMDcomments(parser, args): def CMDcomments(parser, args):
"""Shows review comments of the current changelist.""" """Shows or posts review comments for any changelist."""
(_, args) = parser.parse_args(args) parser.add_option('-a', '--add-comment', dest='comment',
if args: help='comment to add to an issue')
parser.error('Unsupported argument: %s' % args) parser.add_option('-i', dest='issue',
help="review issue id (defaults to current issue)")
options, args = parser.parse_args(args)
cl = Changelist() issue = None
if cl.GetIssue(): if options.issue:
data = cl.GetIssueProperties() try:
for message in sorted(data['messages'], key=lambda x: x['date']): issue = int(options.issue)
if message['disapproval']: except ValueError:
color = Fore.RED DieWithError('A review issue id is expected to be a number')
elif message['approval']:
color = Fore.GREEN cl = Changelist(issue=issue)
elif message['sender'] == data['owner_email']:
color = Fore.MAGENTA if options.comment:
else: cl.AddComment(options.comment)
color = Fore.BLUE return 0
print '\n%s%s %s%s' % (
color, message['date'].split('.', 1)[0], message['sender'], data = cl.GetIssueProperties()
Fore.RESET) for message in sorted(data['messages'], key=lambda x: x['date']):
if message['text'].strip(): if message['disapproval']:
print '\n'.join(' ' + l for l in message['text'].splitlines()) color = Fore.RED
elif message['approval']:
color = Fore.GREEN
elif message['sender'] == data['owner_email']:
color = Fore.MAGENTA
else:
color = Fore.BLUE
print '\n%s%s %s%s' % (
color, message['date'].split('.', 1)[0], message['sender'],
Fore.RESET)
if message['text'].strip():
print '\n'.join(' ' + l for l in message['text'].splitlines())
return 0 return 0
......
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