コード例 #1
0
ファイル: repository_test.py プロジェクト: zloop1982/catapult
  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')
コード例 #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
コード例 #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
コード例 #4
0
ファイル: commit.py プロジェクト: bopopescu/catapult-8
  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
コード例 #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))
コード例 #6
0
 def repository_url(self):
     """The HTTPS URL of the repository as passed to `git clone`."""
     return repository_module.RepositoryUrl(self.repository)
コード例 #7
0
 def testRepositoryUrl(self):
     self.assertEqual(repository.RepositoryUrl('chromium'),
                      test.CHROMIUM_URL)
コード例 #8
0
 def testRepositoryUrlRaisesWithUnknownName(self):
     with self.assertRaises(KeyError):
         repository.RepositoryUrl('not chromium')