def find_new_responses(new_rtag_list, review_list, seq, cmt, patch, url, rest_api=call_rest_api): """Find new rtags collected by patchwork that we don't know about This is designed to be run in parallel, once for each commit/patch Args: new_rtag_list (list): New rtags are written to new_rtag_list[seq] list, each a dict: key: Response tag (e.g. 'Reviewed-by') value: Set of people who gave that response, each a name/email string review_list (list): New reviews are written to review_list[seq] list, each a List of reviews for the patch, each a Review seq (int): Position in new_rtag_list to update cmt (Commit): Commit object for this commit patch (Patch): Corresponding Patch object for this patch url (str): URL of patchwork server, e.g. 'https://patchwork.ozlabs.org' rest_api (function): API function to call to access Patchwork, for testing """ if not patch: return # Get the content for the patch email itself as well as all comments data = rest_api(url, 'patches/%s/' % patch.id) pstrm = PatchStream.process_text(data['content'], True) rtags = collections.defaultdict(set) for response, people in pstrm.commit.rtags.items(): rtags[response].update(people) data = rest_api(url, 'patches/%s/comments/' % patch.id) reviews = [] for comment in data: pstrm = PatchStream.process_text(comment['content'], True) if pstrm.snippets: submitter = comment['submitter'] person = '%s <%s>' % (submitter['name'], submitter['email']) reviews.append(Review(person, pstrm.snippets)) for response, people in pstrm.commit.rtags.items(): rtags[response].update(people) # Find the tags that are not in the commit new_rtags = collections.defaultdict(set) base_rtags = cmt.rtags for tag, people in rtags.items(): for who in people: is_new = (tag not in base_rtags or who not in base_rtags[tag]) if is_new: new_rtags[tag].add(who) new_rtag_list[seq] = new_rtags review_list[seq] = reviews
def test_blank_line_at_end(self): """Test detecting a blank line at the end of a file""" text = '''This is a patch diff --git a/lib/fdtdec.c b/lib/fdtdec.c index c072e54..942244f 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -1200,7 +1200,8 @@ int fdtdec_setup_mem_size_base(void) } gd->ram_size = (phys_size_t)(res.end - res.start + 1); - debug("%s: Initial DRAM size %llx\n", __func__, (u64)gd->ram_size); + debug("%s: Initial DRAM size %llx\n", __func__, + (unsigned long long)gd->ram_size); + diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c -- 2.7.4 ''' pstrm = PatchStream.process_text(text) self.assertEqual( ["Found possible blank line(s) at end of file 'lib/fdtdec.c'"], pstrm.commit.warn)
def test_space_before_tab(self): """Test a space before a tab""" text = '''This is a patch + \tSomething ''' pstrm = PatchStream.process_text(text) self.assertEqual(["Line 3/0 has space before tab"], pstrm.commit.warn)
def test_invalid_commit_tag(self): """Test an invalid Commit-xxx tag""" text = '''This is a patch Commit-fred: testing ''' pstrm = PatchStream.process_text(text) self.assertEqual(["Line 3: Ignoring Commit-fred"], pstrm.commit.warn)
def test_self_test(self): """Test a tested by tag by this user""" test_line = 'Tested-by: %[email protected]' % os.getenv('USER') text = '''This is a patch %s ''' % test_line pstrm = PatchStream.process_text(text) self.assertEqual(["Ignoring '%s'" % test_line], pstrm.commit.warn)
def test_lines_after_test(self): """Test detecting lines after TEST= line""" text = '''This is a patch TEST=sometest more lines here ''' pstrm = PatchStream.process_text(text) self.assertEqual(["Found 2 lines after TEST="], pstrm.commit.warn)
def test_invalid_tag(self): """Test invalid tag in a patchstream""" text = '''This is a patch Serie-version: 2 ''' with self.assertRaises(ValueError) as exc: pstrm = PatchStream.process_text(text) self.assertEqual("Line 3: Invalid tag = 'Serie-version: 2'", str(exc.exception))
def test_missing_blank_line(self): """Test a missing blank line after a tag""" text = '''This is a patch Series-changes: 2 - First line of changes - Missing blank line after this line Signed-off-by: Fred ''' pstrm = PatchStream.process_text(text) self.assertEqual(["Missing 'blank line' in section 'Series-changes'"], pstrm.commit.warn)
def test_missing_end(self): """Test a missing END tag""" text = '''This is a patch Cover-letter: This is the title missing END after this line Signed-off-by: Fred ''' pstrm = PatchStream.process_text(text) self.assertEqual(["Missing 'END' in section 'cover'"], pstrm.commit.warn)
def testTags(self): """Test collection of tags in a patchstream""" text = '''This is a patch Signed-off-by: Terminator Reviewed-by: %s Reviewed-by: %s Tested-by: %s ''' % (self.joe, self.mary, self.leb) pstrm = PatchStream.process_text(text) self.assertEqual(pstrm.commit.rtags, { 'Reviewed-by': {self.joe, self.mary}, 'Tested-by': {self.leb}})
def test_parse_snippets(self): """Test parsing of review snippets""" text = '''Hi Fred, This is a comment from someone. Something else On some recent date, Fred wrote: > This is why I wrote the patch > so here it is Now a comment about the commit message A little more to say Even more > diff --git a/file.c b/file.c > Some more code > Code line 2 > Code line 3 > Code line 4 > Code line 5 > Code line 6 > Code line 7 > Code line 8 > Code line 9 And another comment > @@ -153,8 +143,13 @@ def check_patch(fname, show_types=False): > further down on the file > and more code > +Addition here > +Another addition here > codey > more codey and another thing in same file > @@ -253,8 +243,13 @@ > with no function context one more thing > diff --git a/tools/patman/main.py b/tools/patman/main.py > +line of code now a very long comment in a different file line2 line3 line4 line5 line6 line7 line8 ''' pstrm = PatchStream.process_text(text, True) self.assertEqual([], pstrm.commit.warn) # We expect to the filename and up to 5 lines of code context before # each comment. The 'On xxx wrote:' bit should be removed. self.assertEqual([ ['Hi Fred,', 'This is a comment from someone.', 'Something else'], [ '> This is why I wrote the patch', '> so here it is', 'Now a comment about the commit message', 'A little more to say', 'Even more' ], [ '> File: file.c', '> Code line 5', '> Code line 6', '> Code line 7', '> Code line 8', '> Code line 9', 'And another comment' ], [ '> File: file.c', '> Line: 153 / 143: def check_patch(fname, show_types=False):', '> and more code', '> +Addition here', '> +Another addition here', '> codey', '> more codey', 'and another thing in same file' ], [ '> File: file.c', '> Line: 253 / 243', '> with no function context', 'one more thing' ], [ '> File: tools/patman/main.py', '> +line of code', 'now a very long comment in a different file', 'line2', 'line3', 'line4', 'line5', 'line6', 'line7', 'line8' ] ], pstrm.snippets)