Exemplo n.º 1
0
def hook():
    if request.headers.get('X-Gogs-Signature') != config.SIGNATURE:
        return {'error': 'invalid signature'}, 400

    try:
        event = request.get_json()

    except Exception as err:
        return {'error': str(err)}, 400

    commits = sorted(event['commits'], key=to_maya, reverse=True)
    commit = commits[0]

    job = Job(repository=event['repository']['full_name'],
              ssh_url=event['repository']['ssh_url'],
              clone_url=event['repository']['clone_url'],
              commit_id=commit['id'],
              commit_msg=commit['message'],
              commit_url=commit['url'],
              author='{name} <{email}>'.format(**commit['author']),
              committer='{name} <{email}>'.format(**commit['committer']),
              datetime=to_maya(commit).datetime())
    job.run(db.get())

    return make_response(jsonify({'id': job.id}), 201)
Exemplo n.º 2
0
def detail(jid):
    database = db.get()
    job = database.jobs(jid)

    if job is None:
        abort(404)

    return render_template('detail.html', job=serialize_job(job))
Exemplo n.º 3
0
def index(status):
    database = db.get()

    if status == 'all':
        filter = database.jobs

    else:
        filter = database.jobs.status == getattr(JobStatus, status.upper())

    return render_template('index.html',
                           jobs=fetch_jobs(database, filter),
                           active=status)
Exemplo n.º 4
0
def detail(jid):
    database = db.get()
    return make_response(
        jsonify({'jobs': list(fetch(database, database.jobs.id == jid))}))
Exemplo n.º 5
0
def succeed():
    return fetch_status(db.get(), JobStatus.SUCCEED)
Exemplo n.º 6
0
def failed():
    return fetch_status(db.get(), JobStatus.FAILED)
Exemplo n.º 7
0
def errored():
    return fetch_status(db.get(), JobStatus.ERRORED)
Exemplo n.º 8
0
def started():
    return fetch_status(db.get(), JobStatus.STARTED)
Exemplo n.º 9
0
def pending():
    return fetch_status(db.get(), JobStatus.PENDING)
Exemplo n.º 10
0
def index():
    database = db.get()
    return make_response(
        jsonify({'jobs': list(fetch(database, database.jobs))}))