Beispiel #1
0
def run_rerun(proj, build_id, run):
    r = _get_run(proj, build_id, run)
    permissions.assert_internal_user()
    for t in r.tests:
        db.session.delete(t)
    r.set_status(BuildStatus.QUEUED)
    db.session.commit()
    return jsendify({})
Beispiel #2
0
def project_trigger_list():
    permissions.assert_internal_user()
    t = request.args.get("type")
    if t:
        t = TriggerTypes[t].value
        query = ProjectTrigger.query.filter(ProjectTrigger.type == t)
    else:
        query = ProjectTrigger.query.all()
    return jsendify([x.as_json() for x in query])
Beispiel #3
0
def test_incomplete_list():
    permissions.assert_internal_user()
    tests = []
    complete = (BuildStatus.PASSED, BuildStatus.FAILED)
    for t in Test.query.filter(~Test.status.in_(complete)):
        tests.append(t.as_json(detailed=True))
        tests[-1]['metadata'] = t.run.meta
        tests[-1]['api_key'] = t.run.api_key
    return jsendify({'tests': tests})
Beispiel #4
0
def test_find():
    permissions.assert_internal_user()
    context = request.args.get('context')
    if not context:
        raise ApiError(401, {'message': 'Missing "context" query argument'})

    tests = []
    for t in Test.query.filter_by(context=context):
        tests.append(t.as_json(detailed=True))
        tests[-1]['metadata'] = t.run.meta
        tests[-1]['api_key'] = t.run.api_key
    return jsendify({'tests': tests})
Beispiel #5
0
def project_create():
    d = request.get_json() or {}
    proj = d.get('name')
    if not proj:
        raise ApiError(401, 'Missing required parameter: "name"')
    sync = d.get('synchronous-builds', False)

    permissions.assert_internal_user()
    db.session.add(Project(proj, sync))
    db.session.commit()

    url = url_for('api_project.project_get', proj=proj, _external=True)
    return jsendify({'url': url}, 201)
Beispiel #6
0
def create_webhook(proj):
    u = permissions.assert_internal_user()
    p = get_or_404(Project.query.filter_by(name=proj))

    d = request.get_json() or {}
    required = ('githubtok', 'owner', 'project')
    missing = []
    for x in required:
        if x not in d:
            missing.append(x)
    if missing:
        raise ApiError(401, 'Missing parameters: %s' % ','.join(missing))

    owner = d.pop('owner')
    hook_url = 'https://api.github.com/repos/%s/%s/hooks'
    hook_url = hook_url % (owner, d.pop('project'))

    d['webhook-key'] = secrets.token_urlsafe()
    dr = df = None
    try:
        dr = d.pop('definition_repo')
        df = d.pop('definition_file')
    except KeyError:
        pass

    user = owner
    if u:
        user = str(u)

    db.session.add(ProjectTrigger(
        user, TriggerTypes.github_pr.value, p, dr, df, d))

    _register_github_hook(p, hook_url, d['githubtok'], d['webhook-key'])
    db.session.commit()
    return jsendify({}, 201)
Beispiel #7
0
def project_create_trigger(proj):
    u = permissions.assert_internal_user()
    p = get_or_404(Project.query.filter_by(name=proj))

    d = request.get_json() or {}
    ttype = d.pop('type')
    if not ttype:
        raise ApiError(401, 'Missing parameter: type')
    ttype = TriggerTypes[ttype].value

    try:
        owner = d.pop('owner')
    except KeyError:
        owner = 'unknown-internal'
    if u:
        owner = str(u)
    dr = df = None
    try:
        dr = d.pop('definition_repo')
        df = d.pop('definition_file')
    except KeyError:
        pass

    try:
        secrets = d.pop('secrets')
        # convert array of [{'name': <name>, 'value': <value>}, ...] dicts
        # into dictionary of {<name>: <value>, ...}
        secrets = {x['name']: x['value'] for x in secrets}
    except KeyError:
        secrets = d

    db.session.add(ProjectTrigger(owner, ttype, p, dr, df, secrets))

    db.session.commit()
    return jsendify({}, 201)