Changeset 70020 in webkit


Ignore:
Timestamp:
Oct 18, 2010 7:44:21 PM (14 years ago)
Author:
abarth@webkit.org
Message:

2010-10-18 Adam Barth <abarth@webkit.org>

Reviewed by Eric Seidel.

Implement webkit-patch suggest-reviewers
https://bugs.webkit.org/show_bug.cgi?id=47866

  • Scripts/webkitpy/common/checkout/api.py:
    • The main logic. We look at the last five changes to each modified (non-ChangeLog) file and collect up the reviewers of those changes as well as the authors of those changes who are reviewers.
  • Scripts/webkitpy/common/checkout/api_unittest.py:
    • Test the logic with some fun mocks.
  • Scripts/webkitpy/common/checkout/scm.py:
    • Fix a bug when you have local git commits.
  • Scripts/webkitpy/common/checkout/scm_unittest.py:
    • Test that the bug is fixed.
  • Scripts/webkitpy/tool/commands/queries.py:
    • Add the query.
Location:
trunk/WebKitTools
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r70019 r70020  
     12010-10-18  Adam Barth  <abarth@webkit.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        Implement webkit-patch suggest-reviewers
     6        https://bugs.webkit.org/show_bug.cgi?id=47866
     7
     8        * Scripts/webkitpy/common/checkout/api.py:
     9            - The main logic.  We look at the last five changes to each
     10              modified (non-ChangeLog) file and collect up the reviewers of
     11              those changes as well as the authors of those changes who are
     12              reviewers.
     13        * Scripts/webkitpy/common/checkout/api_unittest.py:
     14            - Test the logic with some fun mocks.
     15        * Scripts/webkitpy/common/checkout/scm.py:
     16            - Fix a bug when you have local git commits.
     17        * Scripts/webkitpy/common/checkout/scm_unittest.py:
     18            - Test that the bug is fixed.
     19        * Scripts/webkitpy/tool/commands/queries.py:
     20            - Add the query.
     21
    1222010-10-18  Kenneth Russell  <kbr@google.com>
    223
  • trunk/WebKitTools/Scripts/webkitpy/common/checkout/api.py

    r63004 r70020  
    8484        return self.commit_info_for_revision(revision).bug_id()
    8585
    86     def modified_changelogs(self, git_commit):
     86    def _modified_files_matching_predicate(self, git_commit, predicate):
    8787        # SCM returns paths relative to scm.checkout_root
    8888        # Callers (especially those using the ChangeLog class) may
     
    9090        changed_files = self._scm.changed_files(git_commit)
    9191        absolute_paths = [os.path.join(self._scm.checkout_root, path) for path in changed_files]
    92         return [path for path in absolute_paths if self._is_path_to_changelog(path)]
     92        return [path for path in absolute_paths if predicate(path)]
     93
     94    def modified_changelogs(self, git_commit):
     95        return self._modified_files_matching_predicate(git_commit, self._is_path_to_changelog)
     96
     97    def modified_non_changelogs(self, git_commit):
     98        return self._modified_files_matching_predicate(git_commit, lambda path: not self._is_path_to_changelog(path))
    9399
    94100    def commit_message_for_this_commit(self, git_commit):
     
    109115        # FIXME: We should sort and label the ChangeLog messages like commit-log-editor does.
    110116        return CommitMessage("".join(changelog_messages).splitlines())
     117
     118    def suggested_reviewers(self, git_commit):
     119        changed_files = self.modified_non_changelogs(git_commit)
     120        revisions = set(sum(map(self._scm.revisions_changing_file, changed_files), []))
     121        commit_infos = set(map(self.commit_info_for_revision, revisions))
     122        reviewers = [commit_info.reviewer() for commit_info in commit_infos if commit_info.reviewer()]
     123        reviewers.extend([commit_info.author() for commit_info in commit_infos if commit_info.author() and commit_info.author().can_review])
     124        return sorted(set(reviewers))
    111125
    112126    def bug_id_for_this_commit(self, git_commit):
  • trunk/WebKitTools/Scripts/webkitpy/common/checkout/api_unittest.py

    r63004 r70020  
    174174        expected_changlogs = ["/foo/bar/ChangeLog", "/foo/bar/relative/path/ChangeLog"]
    175175        self.assertEqual(checkout.modified_changelogs(git_commit=None), expected_changlogs)
     176
     177    def test_suggested_reviewers(self):
     178        def mock_changelog_entries_for_revision(revision):
     179            if revision % 2 == 0:
     180                return [ChangeLogEntry(_changelog1entry1)]
     181            return [ChangeLogEntry(_changelog1entry2)]
     182
     183        def mock_revisions_changing_file(path, limit=5):
     184            if path.endswith("ChangeLog"):
     185                return [3]
     186            return [4, 8]
     187
     188        scm = Mock()
     189        scm.checkout_root = "/foo/bar"
     190        scm.changed_files = lambda git_commit: ["file1", "file2", "relative/path/ChangeLog"]
     191        scm.revisions_changing_file = mock_revisions_changing_file
     192        checkout = Checkout(scm)
     193        checkout.changelog_entries_for_revision = mock_changelog_entries_for_revision
     194        reviewers = checkout.suggested_reviewers(git_commit=None)
     195        reviewer_names = [reviewer.full_name for reviewer in reviewers]
     196        self.assertEqual(reviewer_names, [u'Tor Arne Vestb\xf8'])
  • trunk/WebKitTools/Scripts/webkitpy/common/checkout/scm.py

    r70014 r70020  
    669669    def revisions_changing_file(self, path, limit=5):
    670670        commit_ids = self.run(["git", "log", "--pretty=format:%H", "-%s" % limit, path]).splitlines()
    671         return map(self.svn_revision_from_git_commit, commit_ids)
     671        return filter(lambda revision: revision, map(self.svn_revision_from_git_commit, commit_ids))
    672672
    673673    def conflicted_files(self):
     
    707707
    708708    def svn_revision_from_git_commit(self, commit_id):
    709         return int(self.run(['git', 'svn', 'find-rev', commit_id]).rstrip())
     709        try:
     710            return int(self.run(['git', 'svn', 'find-rev', commit_id]).rstrip())
     711        except ValueError, e:
     712            return None
    710713
    711714    def contents_at_revision(self, path, revision):
  • trunk/WebKitTools/Scripts/webkitpy/common/checkout/scm_unittest.py

    r70014 r70020  
    972972        self._two_local_commits()
    973973
     974    def test_revisions_changing_files_with_local_commit(self):
     975        self._one_local_commit()
     976        self.assertEquals(self.scm.revisions_changing_file('test_file_commit1'), [])
     977
    974978    def test_commit_with_message(self):
    975979        self._one_local_commit_plus_working_copy_changes()
  • trunk/WebKitTools/Scripts/webkitpy/tool/commands/queries.py

    r68813 r70020  
    3131from optparse import make_option
    3232
     33import webkitpy.tool.steps as steps
     34
    3335from webkitpy.common.checkout.commitinfo import CommitInfo
    3436from webkitpy.common.config.committers import CommitterList
     
    4042from webkitpy.common.system.deprecated_logging import log
    4143from webkitpy.layout_tests import port
     44
     45
     46class SuggestReviewers(AbstractDeclarativeCommand):
     47    name = "suggest-reviewers"
     48    help_text = "Suggest reviewers for a patch based on recent changes to the modified files."
     49
     50    def __init__(self):
     51        options = [
     52            steps.Options.git_commit,
     53        ]
     54        AbstractDeclarativeCommand.__init__(self, options=options)
     55
     56    def execute(self, options, args, tool):
     57        reviewers = tool.checkout().suggested_reviewers(options.git_commit)
     58        print "\n".join([reviewer.full_name for reviewer in reviewers])
    4259
    4360
Note: See TracChangeset for help on using the changeset viewer.