Esempio 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')
Esempio 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
Esempio n. 3
0
 def repository_url(self):
     """The HTTPS URL of the repository as passed to `git clone`."""
     cached_url = getattr(self, '_repository_url', None)
     if not cached_url:
         self._repository_url = repository_module.RepositoryUrl(
             self.repository)
     return self._repository_url
Esempio n. 4
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
Esempio n. 5
0
  def post(self):
    repo = self.request.get('repository')
    git_hash_1 = self.request.get('git_hash', self.request.get('git_hash_1'))
    git_hash_2 = self.request.get('git_hash_2')

    try:
      repository_url = repository.RepositoryUrl(repo)
    except KeyError:
      self.response.out.write(json.dumps(
          {'error': 'Unknown repository: %s' % repo}))
      return

    if not git_hash_1:
      self.response.out.write(json.dumps(
          {'error': "No 'git_hash' parameter specified."}))
      return

    if git_hash_2:
      result = gitiles_service.CommitRange(repo, git_hash_1, git_hash_2)
      self.response.out.write(json.dumps(result))
      return

    result = gitiles_service.CommitInfo(repository_url, git_hash_1)
    self.response.out.write(json.dumps(result))
Esempio n. 6
0
 def repository_url(self):
     """The HTTPS URL of the repository as passed to `git clone`."""
     return repository_module.RepositoryUrl(self.repository)
Esempio n. 7
0
 def testRepositoryUrl(self):
     self.assertEqual(repository.RepositoryUrl('chromium'),
                      test.CHROMIUM_URL)
Esempio n. 8
0
 def testRepositoryUrlRaisesWithUnknownName(self):
     with self.assertRaises(KeyError):
         repository.RepositoryUrl('not chromium')