Beispiel #1
0
def get_log_async(
    hostname, project, treeish, path=None, from_treeish=None, limit=None,
    cursor=None,
    **fetch_kwargs):
  """Gets a commit log.

  Does not support paging.

  Returns:
    Log object, or None if no log available.
  """
  _validate_args(hostname, project, treeish, path)
  query_params = {}
  if limit:
    query_params['n'] = limit
  if cursor:
    query_params['s'] = cursor
  path = (path or '').strip('/')
  revision = treeish
  if from_treeish:
    revision = '%s..%s' % (from_treeish, treeish)
  data = yield gerrit.fetch_json_async(
      hostname,
      '%s/+log/%s/%s' % _quote_all(project, revision, path),
      params=query_params,
      **fetch_kwargs)
  if data is None:
    raise ndb.Return(None)
  raise ndb.Return(Log(
      commits=[_parse_commit(c) for c in data.get('log', [])],
      next_cursor=data.get('next'),
  ))
Beispiel #2
0
def get_refs_async(hostname, project, ref_prefix=None, **fetch_kwargs):
    """Gets refs from the server.

  Returns:
    Dict (ref_name -> last_commit_sha), or None if repository was not found.
  """
    ref_prefix = ref_prefix or 'refs/'
    assert ref_prefix.startswith('refs/')
    assert ref_prefix.endswith('/')
    _validate_args(hostname, project)

    path = '%s/+refs' % urllib.quote(project)

    prepend_prefix = False
    if len(ref_prefix) > len('refs/'):
        path += ref_prefix[4:-1]  # exclude "refs" prefix and "/" suffix.
        prepend_prefix = True
    res = yield gerrit.fetch_json_async(hostname, path, **fetch_kwargs)
    if res is None:
        raise ndb.Return(None)

    ret = {}
    for k, v in res.iteritems():
        # if ref_prefix was specified and there is a ref matching exactly the
        # prefix, gitiles returns full ref, not ''.
        if prepend_prefix and k != ref_prefix[:-1]:  # -1 to exclude "/" suffix
            k = ref_prefix + k
        ret[k] = v['value']
    raise ndb.Return(ret)
Beispiel #3
0
def get_log_async(
    hostname, project, treeish, path=None, from_treeish=None, limit=None,
    cursor=None,
    **fetch_kwargs):
  """Gets a commit log.

  Does not support paging.

  Returns:
    Log object, or None if no log available.
  """
  _validate_args(hostname, project, treeish, path)
  query_params = {}
  if limit:
    query_params['n'] = limit
  if cursor:
    query_params['s'] = cursor
  path = (path or '').strip('/')
  revision = treeish
  if from_treeish:
    revision = '%s..%s' % (from_treeish, treeish)
  data = yield gerrit.fetch_json_async(
      hostname,
      '%s/+log/%s/%s' % _quote_all(project, revision, path),
      params=query_params,
      **fetch_kwargs)
  if data is None:
    raise ndb.Return(None)
  raise ndb.Return(Log(
      commits=[_parse_commit(c) for c in data.get('log', [])],
      next_cursor=data.get('next'),
  ))
Beispiel #4
0
def get_commit_async(hostname, project, treeish):
    """Gets a single Git commit.

  Returns:
    Commit object, or None if the commit was not found.
  """
    _validate_args(hostname, project, treeish)
    data = yield gerrit.fetch_json_async(
        hostname, '%s/+/%s' % _quote_all(project, treeish))
    raise ndb.Return(_parse_commit(data) if data is not None else None)
Beispiel #5
0
def get_commit_async(hostname, project, treeish):
  """Gets a single Git commit.

  Returns:
    Commit object, or None if the commit was not found.
  """
  _validate_args(hostname, project, treeish)
  data = yield gerrit.fetch_json_async(
      hostname, '%s/+/%s' % _quote_all(project, treeish))
  raise ndb.Return(_parse_commit(data) if data is not None else None)
Beispiel #6
0
def get_refs_async(hostname, project, **fetch_kwargs):
  """Gets refs from the server.

  Returns:
    Dict (ref_name -> last_commit_sha), or None if repository was not found.
  """
  _validate_args(hostname, project)
  res = yield gerrit.fetch_json_async(
      hostname, '%s/+refs' % urllib.quote(project), **fetch_kwargs)
  if res is None:
    raise ndb.Return(None)
  raise ndb.Return({k: v['value'] for k, v in res.iteritems()})
Beispiel #7
0
def get_refs_async(hostname, project, **fetch_kwargs):
  """Gets refs from the server.

  Returns:
    Dict (ref_name -> last_commit_sha), or None if repository was not found.
  """
  _validate_args(hostname, project)
  res = yield gerrit.fetch_json_async(
      hostname, '%s/+refs' % urllib.quote(project), **fetch_kwargs)
  if res is None:
    raise ndb.Return(None)
  raise ndb.Return({k: v['value'] for k, v in res.iteritems()})
Beispiel #8
0
def get_tree_async(hostname, project, treeish, path=None):
    """Gets a tree object.

  Returns:
    Tree object, or None if the tree was not found.
  """
    _validate_args(hostname, project, treeish, path)
    data = yield gerrit.fetch_json_async(
        hostname, '%s/+/%s%s' % _quote_all(project, treeish, path))
    if data is None:
        raise ndb.Return(None)

    raise ndb.Return(
        Tree(id=data['id'],
             entries=[
                 TreeEntry(
                     id=e['id'],
                     name=e['name'],
                     type=e['type'],
                     mode=e['mode'],
                 ) for e in data.get('entries', [])
             ]))
Beispiel #9
0
def get_tree_async(hostname, project, treeish, path=None):
  """Gets a tree object.

  Returns:
    Tree object, or None if the tree was not found.
  """
  _validate_args(hostname, project, treeish, path)
  data = yield gerrit.fetch_json_async(
      hostname, '%s/+/%s%s' % _quote_all(project, treeish, path))
  if data is None:
    raise ndb.Return(None)

  raise ndb.Return(Tree(
      id=data['id'],
      entries=[
        TreeEntry(
            id=e['id'],
            name=e['name'],
            type=e['type'],
            mode=e['mode'],
        )
        for e in data.get('entries', [])
      ]))