Exemplo n.º 1
0
  def testAddRepository(self):
    name = repository.RepositoryName(
        'https://example/repo', add_if_missing=True)
    self.assertEqual(name, 'repo')

    self.assertEqual(repository.RepositoryUrl('repo'), 'https://example/repo')
    self.assertEqual(repository.RepositoryName('https://example/repo'), 'repo')
Exemplo n.º 2
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']
        git_hash = data['git_hash']

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

        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
Exemplo n.º 3
0
    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.RepositoryName(dep.repository_url,
                                                      add_if_missing=True)
        return cls(repository, dep.git_hash)
Exemplo n.º 4
0
  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.

    If the repository is on the exclusion list returns None.

    Arguments:
      dep: A Dep namedtuple.

    Returns:
      A Commit or None.
    """
    repository = repository_module.RepositoryName(
        dep.repository_url, add_if_missing=True)
    if repository in utils.GetRepositoryExclusions():
      return None
    commit = cls(repository, dep.git_hash)
    commit._repository_url = dep.repository_url
    return commit
Exemplo n.º 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']
    git_hash = data['git_hash']

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

    try:
      # If they send in something like HEAD, resolve to a hash.
      repository_url = repository_module.RepositoryUrl(repository)

      try:
        # If it's already in the hash, then we've resolved this recently, and we
        # don't go resolving the data from the gitiles service.
        result = commit_cache.Get(git_hash)
      except KeyError:
        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)
    commit._repository_url = repository_url

    # IF this is something like HEAD, cache this for a short time so that we
    # avoid hammering gitiles.
    if not gitiles_service.IsHash(data['git_hash']):
      commit.CacheCommitInfo(result, memcache_timeout=30*60)

    return commit
Exemplo n.º 6
0
 def testAddRepositoryRaisesWithDuplicateName(self):
     with self.assertRaises(AssertionError):
         repository.RepositoryName('https://example/chromium',
                                   add_if_missing=True)
Exemplo n.º 7
0
 def testRepositoryRaisesWithUnknownUrl(self):
     with self.assertRaises(KeyError):
         repository.RepositoryName(
             'https://googlesource.com/nonexistent/repo')
Exemplo n.º 8
0
 def testRepository(self):
     name = repository.RepositoryName(test.CHROMIUM_URL + '.git')
     self.assertEqual(name, 'chromium')