Exemplo n.º 1
0
def webhooks_hello(copr_id, uuid):
    # For the documentation of the data we receive see:
    # https://developer.github.com/v3/activity/events/types/#pushevent
    try:
        copr = ComplexLogic.get_copr_by_id_safe(copr_id)
    except ObjectNotFound:
        return page_not_found("Project does not exist")

    if copr.webhook_secret != uuid:
        return access_restricted("This webhook is not valid")

    try:
        request_json = flask.request.json
        clone_url = request_json["repository"]["clone_url"]
    except KeyError:
        return "Bad Request", 400
    if "commits" in request_json:
        commits = request_json["commits"]
    else:
        commits = []

    packages = PackagesLogic.get_for_webhook_rebuild(copr_id, uuid, clone_url, commits)

    for package in packages:
        BuildsLogic.rebuild_package(package)

    db.session.commit()

    return "OK", 200
Exemplo n.º 2
0
def webhooks_hello(copr_id, uuid):
    # For the documentation of the data we receive see:
    # https://developer.github.com/v3/activity/events/types/#pushevent
    try:
        copr = ComplexLogic.get_copr_by_id_safe(copr_id)
    except ObjectNotFound:
        return page_not_found("Project does not exist")

    if copr.webhook_secret != uuid:
        return access_restricted("This webhook is not valid")

    try:
        request_json = flask.request.json
        clone_url = request_json["repository"]["clone_url"]
    except KeyError:
        return "Bad Request", 400
    if "commits" in request_json:
        commits = request_json["commits"]
    else:
        commits = []

    packages = PackagesLogic.get_for_webhook_rebuild(copr_id, uuid, clone_url,
                                                     commits)

    for package in packages:
        BuildsLogic.rebuild_package(package)

    db.session.commit()

    return "OK", 200
Exemplo n.º 3
0
def webhooks_gitlab_push(copr_id, uuid):
    # For the documentation of the data we receive see:
    # https://gitlab.com/help/user/project/integrations/webhooks#events
    try:
        copr = ComplexLogic.get_copr_by_id_safe(copr_id)
    except ObjectNotFound:
        return page_not_found("Project does not exist")

    if copr.webhook_secret != uuid:
        return access_restricted("This webhook is not valid")

    try:
        payload = flask.request.json
        clone_url = payload['project']['git_http_url']
        commits = []
        payload_commits = payload.get('commits', [])
        for payload_commit in payload_commits:
            commits.append({
                'added': payload_commit['added'],
                'modified': payload_commit['modified'],
                'removed': payload_commit['removed'],
            })
        if payload['object_kind'] == 'tag_push':
            ref_type = 'tag'
            ref = os.path.basename(payload.get('ref', ''))
        else:
            ref_type = None
            ref = payload.get('ref', '')

        try:
            submitter = 'gitlab.com:{}'.format(str(payload["user_username"]))
        except KeyError:
            submitter = None

    except KeyError:
        return "Bad Request", 400

    packages = PackagesLogic.get_for_webhook_rebuild(copr_id, uuid, clone_url,
                                                     commits, ref_type, ref)

    committish = (ref if ref_type == 'tag' else payload.get('after', ''))
    for package in packages:
        BuildsLogic.rebuild_package(package, {'committish': committish},
                                    submitted_by=submitter)

    db.session.commit()

    return "OK", 200
Exemplo n.º 4
0
def webhooks_git_push(copr_id, uuid):
    if flask.request.headers["X-GitHub-Event"] == "ping":
        return "OK", 200
    # For the documentation of the data we receive see:
    # https://developer.github.com/v3/activity/events/types/#pushevent
    try:
        copr = ComplexLogic.get_copr_by_id_safe(copr_id)
    except ObjectNotFound:
        return page_not_found("Project does not exist")

    if copr.webhook_secret != uuid:
        return access_restricted("This webhook is not valid")

    try:
        payload = flask.request.json
        clone_url = payload['repository']['clone_url']
        commits = []
        payload_commits = payload.get('commits', [])
        for payload_commit in payload_commits:
            commits.append({
                'added': payload_commit['added'],
                'modified': payload_commit['modified'],
                'removed': payload_commit['removed'],
            })

        ref_type = payload.get('ref_type', '')
        ref = payload.get('ref', '')
        try:
            sender = payload['sender']['url']
        except KeyError:
            sender = None
    except KeyError:
        return "Bad Request", 400

    packages = PackagesLogic.get_for_webhook_rebuild(copr_id, uuid, clone_url,
                                                     commits, ref_type, ref)

    committish = (ref if ref_type == 'tag' else payload.get('after', ''))
    for package in packages:
        BuildsLogic.rebuild_package(package, {'committish': committish},
                                    submitted_by=sender)

    db.session.commit()

    return "OK", 200
Exemplo n.º 5
0
def webhooks_bitbucket_push(copr_id, uuid):
    # For the documentation of the data we receive see:
    # https://confluence.atlassian.com/bitbucket/event-payloads-740262817.html
    try:
        copr = ComplexLogic.get_copr_by_id_safe(copr_id)
    except ObjectNotFound:
        return page_not_found("Project does not exist")

    if copr.webhook_secret != uuid:
        return access_restricted("This webhook is not valid")

    try:
        payload = flask.request.json
        api_url = payload['repository']['links']['self']['href']
        clone_url = payload['repository']['links']['html']['href']
        commits = []
        ref_type = payload['push']['changes'][0]['new']['type']
        ref = payload['push']['changes'][0]['new']['name']
        try:
            actor = payload['actor']['links']['html']['href']
        except KeyError:
            actor = None

        if ref_type == 'tag':
            committish = ref
        else:
            committish = payload['push']['changes'][0]['new']['target']['hash']
    except KeyError:
        return "Bad Request", 400

    packages = PackagesLogic.get_for_webhook_rebuild(copr_id, uuid, clone_url,
                                                     commits, ref_type, ref)

    for package in packages:
        BuildsLogic.rebuild_package(package, {'committish': committish},
                                    submitted_by=actor)

    db.session.commit()

    return "OK", 200
Exemplo n.º 6
0
def webhooks_hello(copr_id, uuid):
    try:
        copr = ComplexLogic.get_copr_by_id_safe(copr_id)
    except ObjectNotFound:
        return page_not_found("Project does not exist")

    if copr.webhook_secret != uuid:
        return access_restricted("This webhook is not valid")

    try:
        request_json = flask.request.json
        clone_url = request_json["repository"]["clone_url"]
    except KeyError:
        return "Bad Request", 400

    packages = PackagesLogic.get_for_webhook_rebuild(copr_id, uuid, clone_url)

    for package in packages:
        BuildsLogic.rebuild_package(package)

    db.session.commit()

    return "OK", 200
Exemplo n.º 7
0
 def handle_403(self, error):
     return access_restricted(self.message(error))
Exemplo n.º 8
0
def handle_403(error):
    return access_restricted(error.message)