git cl comments: Add --unresolved & improve --json-file

* Don't output to non-json format when --json-file is passed
* Format individual comments as JSON when --json-file is used
* Add "unresolved" field to comments
* --unresolved flag will show only unresolved comments
* Better error message when no issue is associated with the branch

I intend to use this to have gemini-cli fix comments:
https://chromium-review.googlesource.com/c/chromium/src/+/6944524

Change-Id: I3b4d594b065751a600661a89925c69ffbf22aed5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6944465
Reviewed-by: Scott Lee <ddoman@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
This commit is contained in:
Andrew Grieve
2025-09-17 11:28:23 -07:00
committed by LUCI CQ
parent c932af8f97
commit 9d57bd01e8
2 changed files with 113 additions and 55 deletions

View File

@@ -3305,57 +3305,84 @@ class TestGitCl(unittest.TestCase):
]
}),
] * 2 + [(('write_json', 'output.json', [{
u'date':
u'2017-03-16 20:00:41.000000',
u'message': (u'PTAL\n' + u'\n' + u'codereview.settings\n' +
u' Base, Line 42: https://crrev.com/c/1/2/'
u'codereview.settings#b42\n' +
u' I removed this because it is bad\n'),
u'autogenerated':
False,
u'approval':
False,
u'disapproval':
False,
u'sender':
u'owner@example.com'
'date': '2017-03-16 20:00:41.000000',
'message': {
'message':
'PTAL',
'comments': [{
'path': 'codereview.settings',
'line': 42,
'patchset': 'Base',
'unresolved': False,
'content': 'I removed this because it is bad'
}]
},
'sender': 'owner@example.com',
'autogenerated': False,
'approval': False,
'disapproval': False
}, {
u'date':
u'2017-03-17 05:19:37.500000',
u'message':
(u'Patch Set 2: Code-Review+1\n' + u'\n' + u'/COMMIT_MSG\n' +
u' PS2, File comment: https://crrev.com/c/1/2//COMMIT_MSG#\n' +
u' Please include a bug link\n'),
u'autogenerated':
False,
u'approval':
False,
u'disapproval':
False,
u'sender':
u'reviewer@example.com'
'date': '2017-03-17 05:19:37.500000',
'message': {
'message':
'Patch Set 2: Code-Review+1',
'comments': [{
'path': '/COMMIT_MSG',
'line': 0,
'patchset': 'PS2',
'unresolved': False,
'content': 'Please include a bug link'
}]
},
'sender': 'reviewer@example.com',
'autogenerated': False,
'approval': False,
'disapproval': False
}]), '')]
expected_comments_summary = [
git_cl._CommentSummary(
message=(u'PTAL\n' + u'\n' + u'codereview.settings\n' +
u' Base, Line 42: https://crrev.com/c/1/2/' +
u'codereview.settings#b42\n' +
u'codereview.settings#b42 (resolved)\n' +
u' I removed this because it is bad\n'),
message_json={
'message':
'PTAL',
'comments': [{
'path': 'codereview.settings',
'line': 42,
'patchset': 'Base',
'unresolved': False,
'content': 'I removed this because it is bad'
}]
},
date=datetime.datetime(2017, 3, 16, 20, 0, 41, 0),
autogenerated=False,
disapproval=False,
approval=False,
sender=u'owner@example.com'),
git_cl._CommentSummary(message=(
u'Patch Set 2: Code-Review+1\n' + u'\n' + u'/COMMIT_MSG\n' +
u' PS2, File comment: https://crrev.com/c/1/2//COMMIT_MSG#\n' +
u' Please include a bug link\n'),
date=datetime.datetime(
2017, 3, 17, 5, 19, 37, 500000),
autogenerated=False,
disapproval=False,
approval=False,
sender=u'reviewer@example.com'),
git_cl._CommentSummary(
message=(u'Patch Set 2: Code-Review+1\n' + u'\n' +
u'/COMMIT_MSG\n' +
u' PS2, File comment: https://crrev.com/c/1/2/'
u'/COMMIT_MSG# (resolved)\n' +
u' Please include a bug link\n'),
message_json={
'message':
'Patch Set 2: Code-Review+1',
'comments': [{
'path': '/COMMIT_MSG',
'line': 0,
'patchset': 'PS2',
'unresolved': False,
'content': 'Please include a bug link'
}]
},
date=datetime.datetime(2017, 3, 17, 5, 19, 37, 500000),
autogenerated=False,
disapproval=False,
approval=False,
sender=u'reviewer@example.com'),
]
cl = git_cl.Changelist(issue=1, branchref='refs/heads/foo')
self.assertEqual(cl.GetCommentsSummary(), expected_comments_summary)