def test_parse_comments_for_single_email_thread(self): patchset = parse_comments(find_thread('PATCH v2 1/2')) self.assertTrue(len(patchset.patches) > 0) first_patch = patchset.patches[0] self.assertEqual(first_patch.set_index, 0) self.assertNotEqual(first_patch.text, '') self.assertIn( '[PATCH v2 1/2] Input: i8042 - Prevent intermixing i8042 commands', first_patch.text_with_headers) self.assertEqual(first_patch.comments, [])
def main(): gerrit_url = 'https://linux-review.googlesource.com' gob_url = 'http://linux.googlesource.com' rest = get_gerrit_rest_api('gerritcookies', gerrit_url) gerrit = Gerrit(rest) gerrit_git = GerritGit(git_dir='gerrit_git_dir', cookie_jar_path='gerritcookies', url=gob_url, project='linux/kernel/git/torvalds/linux', branch='master') email_thread = find_thread('PATCH v2 0/4') patchset = parse_comments(email_thread) gerrit_git.apply_patchset_and_cleanup(patchset) find_and_label_all_revision_ids(gerrit, patchset) upload_all_comments(gerrit, patchset)
def test_parse_comments_for_multi_email_thread_with_cover_letter(self): patchset = parse_comments(find_thread('PATCH v2 0/4')) self.assertEqual(len(patchset.patches), 4) first_patch = patchset.patches[0] self.assertEqual(first_patch.set_index, 1) self.assertIn( '[PATCH v2 1/4] kselftests/arm64: add a basic Pointer Authentication test', first_patch.text_with_headers) self.assertNotEqual(first_patch.text, '') self.assertEqual(first_patch.comments, []) self.assertIn( '[PATCH v2 2/4] kselftests/arm64: add nop checks for PAuth tests', patchset.patches[1].text_with_headers)
def test_parse_comments_for_single_email_thread(self): archive_index = ArchiveMessageIndex(MessageDao()) archive_index.update('test_data') patchset = parse_comments( archive_index.find( '<20200827144112.v2.1.I6981f9a9f0c12e60f8038f3b574184f8ffc1b9b5@changeid>' )) self.assertTrue(len(patchset.patches) > 0) first_patch = patchset.patches[0] self.assertEqual(first_patch.set_index, 0) self.assertNotEqual(first_patch.text, '') self.assertIn( '[PATCH v2 1/2] Input: i8042 - Prevent intermixing i8042 commands', first_patch.text_with_headers) self.assertEqual(first_patch.comments, [])
def main(): gerrit_url = 'https://linux-review.googlesource.com' gob_url = 'http://linux.googlesource.com' rest = get_gerrit_rest_api('gerritcookies', gerrit_url) gerrit = Gerrit(rest) gerrit_git = GerritGit(git_dir='gerrit_git_dir', cookie_jar_path='gerritcookies', url=gob_url, project='linux/kernel/git/torvalds/linux', branch='master') archive_index = ArchiveMessageIndex(MessageDao()) archive_index.update('test_data') patchset = parse_comments( archive_index.find('<*****@*****.**>')) gerrit_git.apply_patchset_and_cleanup(patchset) find_and_label_all_revision_ids(gerrit, patchset) upload_all_comments(gerrit, patchset)
def test_parse_comments_for_multi_email_thread_with_cover_letter(self): archive_index = ArchiveMessageIndex(MessageDao()) archive_index.update('test_data') patchset = parse_comments( archive_index.find( '<*****@*****.**>')) self.assertEqual(len(patchset.patches), 4) first_patch = patchset.patches[0] self.assertEqual(first_patch.set_index, 1) self.assertIn( '[PATCH v2 1/4] kselftests/arm64: add a basic Pointer Authentication test', first_patch.text_with_headers) self.assertNotEqual(first_patch.text, '') self.assertEqual(first_patch.comments, []) self.assertIn( '[PATCH v2 2/4] kselftests/arm64: add nop checks for PAuth tests', patchset.patches[1].text_with_headers)
def upload_comments(self, messages_with_new_comments: Collection[str]): failed = 0 for message_id in messages_with_new_comments: email_thread: Message try: email_thread = self.archive_index.find(message_id) patchset = patch_parser.parse_comments(email_thread) gerrit.upload_all_comments(self.gerrit, patchset) except Exception as e: failed += 1 failed_message = message_id if email_thread: failed_message = email_thread.debug_info() logging.exception('Failed to upload comments for %s.', failed_message) continue if failed > 0: logging.warning('Failed to upload %d/%d comments', failed, len(messages_with_new_comments))
def upload_messages(self, messages_to_upload: List[str]): failed = 0 for message_id in messages_to_upload: email_thread: Message try: email_thread = self.archive_index.find(message_id) patchset = patch_parser.parse_comments(email_thread) self.gerrit_git.apply_patchset_and_cleanup( patchset, self.message_dao) gerrit.find_and_label_all_revision_ids(self.gerrit, patchset) gerrit.upload_all_comments(self.gerrit, patchset) except Exception as e: failed += 1 failed_message = message_id if email_thread: failed_message = email_thread.debug_info() logging.exception('Failed to upload %s.', failed_message) continue if failed > 0: logging.warning('Failed to upload %d/%d messages', failed, len(messages_to_upload))
def test_parse_with_replies(self): archive_index = ArchiveMessageIndex(MessageDao()) archive_index.update(test_data_path('fake_patch_with_replies/')) self.assertEqual(archive_index.size(), 2) patchset = parse_comments(archive_index.find('<patch-message-id>')) map_comments_to_gerrit(patchset) self.assertEqual(len(patchset.patches), 1) patch = patchset.patches[0] self.compareCommentsPartialMatch( patch.comments, [ # TODO: stop treating this as a comment Comment( raw_line=-1, file='', line=-1, message= 'On Mon, 31 Aug 2020 at 12:04:46 +0100, The Sender wrote:' ), Comment( raw_line=18, file='file', line=7, # TODO: should be 5 message='Comment on old line 5, want on line 5 in new file.' ), Comment( raw_line=20, file='file', line=9, # TODO: should be 7 message='Comment on old line 7, want on line 8 in new file.' ), ])
def test_parse_comments_for_non_patch_email(self): patchset = parse_comments( generate_email_from_file('test_data/thread_patch0.txt')) self.assertEqual(len(patchset.patches), 0)