Esempio n. 1
0
 def AsDict(self):
     # CommitInfo is cached in gitiles_service.
     commit_info = gitiles_service.CommitInfo(self.repository_url,
                                              self.git_hash)
     details = {
         'repository': self.repository,
         'git_hash': self.git_hash,
         'url': self.repository_url + '/+/' + commit_info['commit'],
         'subject': commit_info['message'].split('\n', 1)[0],
         'author': commit_info['author']['email'],
         'time': commit_info['committer']['time'],
     }
     commit_position = _ParseCommitPosition(commit_info['message'])
     if commit_position:
         details['commit_position'] = commit_position
     author = details['author']
     if (author == '*****@*****.**' or author.endswith(
             'skia-buildbots.google.com.iam.gserviceaccount.com')):
         message = commit_info['message']
         if message:
             m = re.search(r'TBR=([^,^\s]*)', message)
             if m:
                 details['tbr'] = m.group(1)
     return details
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']

        # Translate repository if it's a URL.
        if repository.startswith('https://'):
            repository = _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
Esempio n. 3
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. 4
0
    def CacheCommitInfo(self):
        try:
            return commit_cache.Get(self.id_string)
        except KeyError:
            commit_info = gitiles_service.CommitInfo(self.repository_url,
                                                     self.git_hash)
            url = self.repository_url + '/+/' + commit_info['commit']
            author = commit_info['author']['email']

            created = ParseDateWithUTCOffset(commit_info['committer']['time'])

            subject = commit_info['message'].split('\n', 1)[0]
            message = commit_info['message']

            commit_cache.Put(self.id_string, url, author, created, subject,
                             message)

            return {
                'url': url,
                'author': author,
                'created': created,
                'subject': subject,
                'message': message,
            }
    def testCache(self):
        self._request_json.return_value = {'log': []}
        self._request.return_value = 'aGVsbG8='

        repository = 'https://chromium.googlesource.com/repo'
        git_hash = '3a44bc56c4efa42a900a1c22b001559b81e457e9'

        gitiles_service.CommitInfo(repository, git_hash)
        self._request_json.assert_called_with('%s/+/%s?format=JSON' %
                                              (repository, git_hash),
                                              use_cache=True,
                                              use_auth=False)

        gitiles_service.CommitRange(repository, git_hash, git_hash)
        self._request_json.assert_called_with('%s/+log/%s..%s?format=JSON' %
                                              (repository, git_hash, git_hash),
                                              use_cache=True,
                                              use_auth=False)

        gitiles_service.FileContents(repository, git_hash, 'path')
        self._request.assert_called_with('%s/+/%s/path?format=TEXT' %
                                         (repository, git_hash),
                                         use_cache=True,
                                         use_auth=False)