def testAddRepository(self):
        name = repository.Repository('https://example/repo',
                                     add_if_missing=True)
        self.assertEqual(name, 'repo')

        self.assertEqual(repository.RepositoryUrl('repo'),
                         'https://example/repo')
        self.assertEqual(repository.Repository('https://example/repo'), 'repo')
Exemple #2
0
    def Deps(self):
        """Return the DEPS of this Commit as a frozenset of Commits."""
        # Download and execute DEPS file.
        try:
            deps_file_contents = gitiles_service.FileContents(
                self.repository_url, self.git_hash, 'DEPS')
        except gitiles_service.NotFoundError:
            return frozenset()  # No DEPS file => no DEPS.

        deps_data = {'Var': lambda variable: deps_data['vars'][variable]}
        exec deps_file_contents in deps_data  # pylint: disable=exec-used

        # Pull out deps dict, including OS-specific deps.
        deps_dict = deps_data['deps']
        for deps_os in deps_data.get('deps_os', {}).itervalues():
            deps_dict.update(deps_os)

        # Convert deps strings to Commit objects.
        commits = []
        for dep_string in deps_dict.itervalues():
            dep_string_parts = dep_string.split('@')
            if len(dep_string_parts) < 2:
                continue  # Dep is not pinned to any particular revision.
            if len(dep_string_parts) > 2:
                raise NotImplementedError('Unknown DEP format: ' + dep_string)

            repository_url, git_hash = dep_string_parts
            repository = repository_module.Repository(repository_url,
                                                      add_if_missing=True)
            commits.append(Commit(repository, git_hash))

        return frozenset(commits)
    def FromDict(cls, data):
        """Create a Commit from a dict.

    If the repository is a repository URL, it will be translated to its short
    form name.

    Raises:
      KeyError: The repository name is not in the local datastore,
                or the git hash is not valid.
    """
        repository = data['repository']

        # Translate repository if it's a URL.
        if repository.startswith('https://'):
            repository = repository_module.Repository(repository)

        git_hash = data['git_hash']

        try:
            # If they send in something like HEAD, resolve to a hash.
            repository_url = repository_module.RepositoryUrl(repository)
            result = gitiles_service.CommitInfo(repository_url, git_hash)
            git_hash = result['commit']
        except gitiles_service.NotFoundError as e:
            raise KeyError(str(e))

        commit = cls(repository, git_hash)

        return commit
    def FromDep(cls, dep):
        """Create a Commit from a Dep namedtuple as returned by Deps().

    If the repository url is unknown, it will be added to the local datastore.

    Arguments:
      dep: A Dep namedtuple.

    Returns:
      A Commit.
    """
        repository = repository_module.Repository(dep.repository_url,
                                                  add_if_missing=True)
        return cls(repository, dep.git_hash)
Exemple #5
0
    def FromDict(cls, data):
        """Create a Commit from a dict.

    If the repository is a repository URL, it will be translated to its short
    form name.

    Raises:
      KeyError: The repository name is not in the local datastore,
                or the git hash is not valid.
    """
        repository = data['repository']

        # Translate repository if it's a URL.
        if repository.startswith('https://'):
            repository = repository_module.Repository(repository)

        commit = cls(repository, data['git_hash'])

        try:
            gitiles_service.CommitInfo(commit.repository_url, commit.git_hash)
        except gitiles_service.NotFoundError as e:
            raise KeyError(str(e))

        return commit
Exemple #6
0
 def _PopulateData(self):
   # Add repository mappings.
   repository.Repository(id='catapult', urls=[CATAPULT_URL]).put()
   repository.Repository(id='chromium', urls=[CHROMIUM_URL]).put()
   repository.Repository(id='another_repo', urls=['https://another/url']).put()
 def testAddRepositoryRaisesWithDuplicateName(self):
     with self.assertRaises(AssertionError):
         repository.Repository('https://example/chromium',
                               add_if_missing=True)
 def testRepositoryRaisesWithUnknownUrl(self):
     with self.assertRaises(KeyError):
         repository.Repository(
             'https://chromium.googlesource.com/nonexistent/repo')
 def testRepository(self):
     self.assertEqual(repository.Repository(_CHROMIUM_URL + '.git'),
                      'chromium')