Beispiel #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)
Beispiel #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))
Beispiel #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)
Beispiel #4
0
def detail(jid):
    database = db.get()
    return make_response(
        jsonify({'jobs': list(fetch(database, database.jobs.id == jid))}))
Beispiel #5
0
def succeed():
    return fetch_status(db.get(), JobStatus.SUCCEED)
Beispiel #6
0
def failed():
    return fetch_status(db.get(), JobStatus.FAILED)
Beispiel #7
0
def errored():
    return fetch_status(db.get(), JobStatus.ERRORED)
Beispiel #8
0
def started():
    return fetch_status(db.get(), JobStatus.STARTED)
Beispiel #9
0
def pending():
    return fetch_status(db.get(), JobStatus.PENDING)
Beispiel #10
0
def index():
    database = db.get()
    return make_response(
        jsonify({'jobs': list(fetch(database, database.jobs))}))