|
|
|
@ -3171,6 +3171,89 @@ class TestGitCl(TestCase):
|
|
|
|
|
self.assertEqual(read[1]['date'], '2017-03-13 20:49:34.515270')
|
|
|
|
|
self.assertEqual(read[2]['date'], '2017-03-13 21:50:34.515270')
|
|
|
|
|
|
|
|
|
|
def test_git_cl_comments_fetch_gerrit(self):
|
|
|
|
|
self.mock(sys, 'stdout', StringIO.StringIO())
|
|
|
|
|
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'),
|
|
|
|
|
(('GetChangeDetail', 'chromium-review.googlesource.com', '1',
|
|
|
|
|
['MESSAGES', 'DETAILED_ACCOUNTS']), {
|
|
|
|
|
'owner': {'email': 'owner@example.com'},
|
|
|
|
|
'messages': [
|
|
|
|
|
{
|
|
|
|
|
u'_revision_number': 1,
|
|
|
|
|
u'author': {
|
|
|
|
|
u'_account_id': 1111084,
|
|
|
|
|
u'email': u'commit-bot@chromium.org',
|
|
|
|
|
u'name': u'Commit Bot'
|
|
|
|
|
},
|
|
|
|
|
u'date': u'2017-03-15 20:08:45.000000000',
|
|
|
|
|
u'id': u'f5a6c25ecbd3b3b54a43ae418ed97eff046dc50b',
|
|
|
|
|
u'message': u'Patch Set 1:\n\nDry run: CQ is trying da patch...',
|
|
|
|
|
u'tag': u'autogenerated:cq:dry-run'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
u'_revision_number': 2,
|
|
|
|
|
u'author': {
|
|
|
|
|
u'_account_id': 11151243,
|
|
|
|
|
u'email': u'owner@example.com',
|
|
|
|
|
u'name': u'owner'
|
|
|
|
|
},
|
|
|
|
|
u'date': u'2017-03-16 20:00:41.000000000',
|
|
|
|
|
u'id': u'f5a6c25ecbd3b3b54a43ae418ed97eff046d1234',
|
|
|
|
|
u'message': u'PTAL',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
u'_revision_number': 2,
|
|
|
|
|
u'author': {
|
|
|
|
|
u'_account_id': 148512 ,
|
|
|
|
|
u'email': u'reviewer@example.com',
|
|
|
|
|
u'name': u'reviewer'
|
|
|
|
|
},
|
|
|
|
|
u'date': u'2017-03-17 05:19:37.500000000',
|
|
|
|
|
u'id': u'f5a6c25ecbd3b3b54a43ae418ed97eff046d4568',
|
|
|
|
|
u'message': u'Patch Set 2: Code-Review+1',
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
] * 2
|
|
|
|
|
expected_comments_summary = [
|
|
|
|
|
git_cl._CommentSummary(
|
|
|
|
|
message=u'Patch Set 1:\n\nDry run: CQ is trying da patch...',
|
|
|
|
|
date=datetime.datetime(2017, 3, 15, 20, 8, 45, 0),
|
|
|
|
|
disapproval=False, approval=False, sender=u'commit-bot@chromium.org'),
|
|
|
|
|
git_cl._CommentSummary(
|
|
|
|
|
message=u'PTAL',
|
|
|
|
|
date=datetime.datetime(2017, 3, 16, 20, 0, 41, 0),
|
|
|
|
|
disapproval=False, approval=False, sender=u'owner@example.com'),
|
|
|
|
|
git_cl._CommentSummary(
|
|
|
|
|
message=u'Patch Set 2: Code-Review+1',
|
|
|
|
|
date=datetime.datetime(2017, 3, 17, 5, 19, 37, 500000),
|
|
|
|
|
disapproval=False, approval=False, sender=u'reviewer@example.com'),
|
|
|
|
|
]
|
|
|
|
|
cl = git_cl.Changelist(codereview='gerrit', issue=1)
|
|
|
|
|
self.assertEqual(cl.GetCommentsSummary(), expected_comments_summary)
|
|
|
|
|
|
|
|
|
|
with git_cl.gclient_utils.temporary_directory() as tempdir:
|
|
|
|
|
out_file = os.path.abspath(os.path.join(tempdir, 'out.json'))
|
|
|
|
|
self.assertEqual(0, git_cl.main(['comment', '--gerrit', '-i', '1',
|
|
|
|
|
'-j', out_file]))
|
|
|
|
|
with open(out_file) as f:
|
|
|
|
|
read = json.load(f)
|
|
|
|
|
self.assertEqual(len(read), 3)
|
|
|
|
|
self.assertEqual(read[0]['date'], u'2017-03-15 20:08:45.000000')
|
|
|
|
|
self.assertEqual(read[1]['date'], u'2017-03-16 20:00:41.000000')
|
|
|
|
|
self.assertEqual(read[2], {
|
|
|
|
|
u'date': u'2017-03-17 05:19:37.500000',
|
|
|
|
|
u'message': u'Patch Set 2: Code-Review+1',
|
|
|
|
|
u'approval': False,
|
|
|
|
|
u'disapproval': False,
|
|
|
|
|
u'sender': u'reviewer@example.com'})
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
logging.basicConfig(
|
|
|
|
|