Exemple #1
0
def api_v1_org(org):
    """Organization overview. Returns a list of repositories that have been
    run through the system, with their most recent created date and run number.

    :param org: The GitHub username or organization (e.g. 'puppetlabs')
    :return: JSON containing an organization's repositories known to the system.
    """
    response = es.search(q="source:{} AND payload.repository.owner.name:{}".format('jenkins-hookshot', org))

    repos = []
    for hit in response['hits']['hits']:
        repos.append(hit['_source']['payload']['repository']['full_name'])

    result = []
    for repo in set(repos):
        last_run_uuid = redis.lindex(repo, -1).decode('utf-8')
        last_run_num = get_run_number(repo, last_run_uuid)

        resp = es.search(q="source:{} AND id:{}".format('jenkins-hookshot', last_run_uuid))
        hit = resp['hits']['hits'][0]['_source']
        repo = hit['repo']
        last_run_timestamp = hit['@timestamp']

        result.append(dict(
            name=repo,
            last_run_uuid=last_run_uuid,
            last_run_number=last_run_num,
            last_run_timestamp=last_run_timestamp,
        ))

    return jsonify(dict(org=org, repos=sorted(result, key=itemgetter('name'))))
Exemple #2
0
def get_run_uuid(repo, run_number):
    """Given a run number for a particular repo, return the run's UUID.

    :param repo: Full name of the GitHub repository (e.g. 'puppetlabs/puppet')
    :param run_number: Number of the given run (integer)
    :return: Run UUID as a string
    """
    # Runs in the app are one-indexed, but lists in Redis are zero-indexed
    return redis.lindex(repo, run_number - 1).decode('utf-8')