Exemplo n.º 1
0
def create_numberings():  # pragma: no cover
    git_sha = 'b0b1beef' * 5
    redirect_url = 'https://crrev.com/%s' % git_sha
    numberings = [
        models.NumberingMap(
            numbering_type=models.NumberingType.SVN,
            numbering_identifier='svn://svn.cool.org/cool_src',
            number=100,
            project='cool',
            repo='cool_src',
            git_sha=git_sha,
            redirect_url=redirect_url,
        ),
        models.NumberingMap(
            numbering_type=models.NumberingType.COMMIT_POSITION,
            numbering_identifier='refs/heads/master',
            number=100,
            project='cool',
            repo='cool_src',
            git_sha=git_sha,
            redirect_url=redirect_url,
        ),
    ]

    return numberings
Exemplo n.º 2
0
def parse_commit_message(msg, project, repo):
    """Take a commit message and parse out any numberings."""
    numberings = []
    lines = msg.split('\n')

    # Scan the commit message twice, to catch both the commit-position and the
    # git-svn-id if they both exist. However, we only care about the last instance
    # of each, so we scan the lines backwards.
    for line in reversed(lines):
        git_svn_match = GIT_SVN_ID_REGEX.match(line)
        if git_svn_match:
            full_url = git_svn_match.group(1)
            revision = int(git_svn_match.group(2))

            # SVN folders can be individually checked out, so we add them all here:
            #   svn.chromium.org/chrome
            #   svn.chromium.org/chrome/trunk
            #   svn.chromium.org/chrome/trunk/src
            for i in range(len(full_url.split('/')) - 3):
                url = '/'.join(full_url.split('/')[0:i + 4])
                numberings.append(
                    models.NumberingMap(
                        numbering_type=models.NumberingType.SVN,
                        numbering_identifier=url,
                        number=revision,
                        key=ndb.Key(
                            models.NumberingMap,
                            models.NumberingMap.svn_unique_id(url, revision))))
            break

    for line in reversed(lines):
        git_commit_position_match = GIT_COMMIT_POSITION_REGEX.match(line)
        if git_commit_position_match:
            git_ref = git_commit_position_match.group(1)
            commit_position = int(git_commit_position_match.group(2))
            numberings.append(
                models.NumberingMap(
                    numbering_type=models.NumberingType.COMMIT_POSITION,
                    numbering_identifier=git_ref,
                    number=commit_position,
                    key=ndb.Key(
                        models.NumberingMap,
                        models.NumberingMap.git_unique_id(
                            project, repo, git_ref, commit_position))))
            break

    return numberings
Exemplo n.º 3
0
def create_commit():  # pragma: no cover
    my_commit = models.RevisionMap()
    my_commit.git_sha = 'b0b1beef' * 5
    my_commit.redirect_url = 'https://crrev.com/%s' % my_commit.git_sha
    my_commit.project = 'cool'
    my_commit.repo = 'cool_src'
    my_commit.number = 100
    my_commit.numberings = [
        models.NumberingMap(numbering_type=models.NumberingType.SVN,
                            numbering_identifier='svn://svn.cool.org/cool_src',
                            number=100),
        models.NumberingMap(
            numbering_type=models.NumberingType.COMMIT_POSITION,
            numbering_identifier='refs/heads/master',
            number=100,
            project='cool',
            repo='cool_src'),
    ]

    return my_commit
Exemplo n.º 4
0
    def test_redirect_numeric_log(self):
        # It's necessary to overwrite the model_helpers defaults with chromium/src
        # so that the numbering (which only works in chromium/src) can look up
        # the fake commits we create.
        my_repo = model_helpers.create_repo()
        my_repo.project = 'chromium'
        my_repo.repo = 'chromium/src'
        my_repo.put()
        first_commit = model_helpers.create_commit()
        first_commit.git_sha = 'deadbeef' * 5
        first_commit.project = my_repo.project
        first_commit.repo = my_repo.repo
        first_commit.put()
        second_commit = model_helpers.create_commit()
        second_commit.git_sha = 'baddecaf' * 5
        second_commit.project = my_repo.project
        second_commit.repo = my_repo.repo
        second_commit.put()
        my_numberings = model_helpers.create_numberings()
        my_numberings[1].git_sha = 'deadbeef' * 5
        my_numberings[1].project = my_repo.project
        my_numberings[1].repo = my_repo.repo
        my_numberings.append(
            models.NumberingMap(
                numbering_type=models.NumberingType.COMMIT_POSITION,
                numbering_identifier='refs/heads/master',
                number=123456,
                project='chromium',
                repo='chromium/src',
                git_sha=second_commit.git_sha,
                redirect_url='https://crrev.com/%s' % second_commit.git_sha))

        for numbering in my_numberings:
            numbering.put()

        generated = controller.calculate_redirect('100..123456')
        expected_url = ('https://chromium.googlesource.com/chromium/src/+log/'
                        'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef..'
                        'baddecafbaddecafbaddecafbaddecafbaddecaf')
        expected = models.Redirect(
            redirect_type=models.RedirectType.GIT_LOG,
            redirect_url=expected_url,
            repo=first_commit.repo,
            repo_url='https://chromium.googlesource.com/chromium/src/',
        )

        self.assertEqual(generated, expected)