Exemple #1
0
def _get_items(url, headers):
  """Generator that gets and yields items from a GitHub API endpoint (specified
  by |URL|) sending |headers| with the get request."""
  # Github API response pages are 1-indexed.
  page_counter = 1

  # Set to infinity so we run loop at least once.
  total_num_items = float('inf')

  item_num = 0
  while item_num < total_num_items:
    params = {'per_page': _MAX_ITEMS_PER_PAGE, 'page': str(page_counter)}
    response = _do_get_request(url, params=params, headers=headers)
    response_json = response.json()
    if not response.status_code == 200:
      # Check that request was successful.
      logging.error('Request to %s failed. Code: %d. Response: %s',
                    response.request.url, response.status_code, response_json)
      raise filestore.FilestoreError('Github API request failed.')

    if total_num_items == float('inf'):
      # Set proper total_num_items
      total_num_items = response_json['total_count']

    # Get the key for the items we are after.
    keys = [key for key in response_json.keys() if key != 'total_count']
    assert len(keys) == 1, keys
    items_key = keys[0]

    for item in response_json[items_key]:
      yield item
      item_num += 1

    page_counter += 1
Exemple #2
0
def get_filestore(config):
  """Returns the correct filestore based on the platform in |config|.
  Raises an exception if there is no correct filestore for the platform."""
  # TODO(metzman): Force specifying of filestore.
  if config.platform == config.Platform.EXTERNAL_GITHUB:
    return filestore.github_actions.GithubActionsFilestore(config)
  raise filestore.FilestoreError('Filestore doesn\'t support platform.')
Exemple #3
0
def get_filestore(config):
    """Returns the correct filestore object based on the platform in |config|.
  Raises an exception if there is no correct filestore for the platform."""
    if config.platform == config.Platform.EXTERNAL_GITHUB:
        ci_filestore = filestore.github_actions.GithubActionsFilestore(config)
        if not config.git_store_repo:
            return ci_filestore

        return filestore.git.GitFilestore(config, ci_filestore)

    filestore_cls = FILESTORE_MAPPING.get(config.filestore)
    if filestore_cls is None:
        raise filestore.FilestoreError('Filestore doesn\'t exist.')
    return filestore_cls(config)