def __init__(self, repo_url=None):
        self._host = None
        self._repo_path = None
        self._repo_url = repo_url
        if repo_url is not None:
            parsed_url = urlparse(repo_url)
            self._host = parsed_url.netloc
            # Remove the / in the front of path.
            self._repo_path = parsed_url.path[1:]
            self._CloneOrUpdateRepoIfNeeded()

        self.changelog_parser = local_git_parsers.GitChangeLogParser()
        self.changelogs_parser = local_git_parsers.GitChangeLogsParser()
        self.blame_parser = local_git_parsers.GitBlameParser()
        self.diff_parser = local_git_parsers.GitDiffParser()
예제 #2
0
 def testGitChangeLogsParserParseEmptyOutput(self):
   self.assertIsNone(local_git_parsers.GitChangeLogsParser()(None, 'repo',
                                                             'ref'))
예제 #3
0
 def testGitChangeLogsParserWithEmptyChangelog(self):
   output = '**Changelog start**\nblablabla'
   self.assertEqual(
       local_git_parsers.GitChangeLogsParser()(output, 'http://repo', 'ref'),
       [])
예제 #4
0
  def testGitChangeLogsParser(self):
    output = textwrap.dedent("""
        **Changelog start**
        commit rev1
        tree 27b0421273ed4aea25e497c6d26d9c7db6481852
        parents rev22c9e

        author author1
        author-mail [email protected]
        author-time 2016-06-02 10:55:38

        committer Commit bot
        committer-mail [email protected]
        committer-time 2016-06-02 10:57:13

        --Message start--
        Message 1
        --Message end--

        :100644 100644 28e117 f12d3 D      a/b.py


        **Changelog start**
        commit rev2
        tree d22d3786e135b83183cfeba5f3d8913959f56299
        parents ac7ee4ce7b8d39b22a710c58d110e0039c11cf9a

        author author2
        author-mail [email protected]
        author-time 2016-06-02 10:53:03

        committer Commit bot
        committer-mail [email protected]
        committer-time 2016-06-02 10:54:14

        --Message start--
        Message 2
        --Message end--

        :100644 100644 7280f df186 A      b/c.py

        **Changelog start**
        commit rev3
        tree d22d3786e135b83183cfeba5f3d8913959f56299
        parents ac7ee4ce7b8d39b22a710c58d110e0039c11cf9a

        author author3
        author-mail [email protected]
        author-time 2016-06-02 10:53:03

        committer Commit bot
        committer-mail [email protected]
        committer-time 2016-06-02 10:54:14

        --Message start--
        Message 3
        --Message end--

        :100644 100644 3f2e 20a5 R078 b/c.py b/cc.py
        """)

    expected_changelogs = [
        change_log.ChangeLog(
            change_log.Contributor('author1', '*****@*****.**',
                                   datetime(2016, 6, 2, 10, 55, 38)),
            change_log.Contributor('Commit bot', '*****@*****.**',
                                   datetime(2016, 6, 2, 10, 57,
                                            13)), 'rev1', None, 'Message 1',
            [change_log.FileChangeInfo('delete', 'a/b.py', None)],
            'http://repo/+/rev1', None, None),
        change_log.ChangeLog(
            change_log.Contributor('author2', '*****@*****.**',
                                   datetime(2016, 6, 2, 10, 53, 3)),
            change_log.Contributor('Commit bot', '*****@*****.**',
                                   datetime(2016, 6, 2, 10, 54,
                                            14)), 'rev2', None, 'Message 2',
            [change_log.FileChangeInfo('add', None, 'b/c.py')],
            'http://repo/+/rev2', None, None),
        change_log.ChangeLog(
            change_log.Contributor('author3', '*****@*****.**',
                                   datetime(2016, 6, 2, 10, 53, 3)),
            change_log.Contributor('Commit bot', '*****@*****.**',
                                   datetime(2016, 6, 2, 10, 54,
                                            14)), 'rev3', None, 'Message 3',
            [change_log.FileChangeInfo('rename', 'b/c.py', 'b/cc.py')],
            'http://repo/+/rev3', None, None),
    ]

    changelogs = local_git_parsers.GitChangeLogsParser()(output, 'http://repo',
                                                         'ref')
    for changelog, expected_changelog in zip(changelogs, expected_changelogs):
      self.assertEqual(changelog.ToDict(), expected_changelog.ToDict())