예제 #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
예제 #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
예제 #3
0
def copr_createrepo(copr_id):
    copr = ComplexLogic.get_copr_by_id_safe(copr_id)

    chroots = [c.name for c in copr.active_chroots]
    actions_logic.ActionsLogic.send_createrepo(
        username=('@'+copr.group.name if copr.is_a_group_project else copr.user.name), coprname=copr.name,
        chroots=chroots)

    db.session.commit()
    flask.flash("Repository metadata will be regenerated in a few minutes ...")
    return flask.redirect(url_for_copr_details(copr))
예제 #4
0
def copr_createrepo(copr_id):
    copr = ComplexLogic.get_copr_by_id_safe(copr_id)

    chroots = [c.name for c in copr.active_chroots]
    actions_logic.ActionsLogic.send_createrepo(username=copr.owner_name,
                                               coprname=copr.name,
                                               chroots=chroots)

    db.session.commit()
    flask.flash("Repository metadata will be regenerated in a few minutes ...")
    return flask.redirect(url_for_copr_details(copr))
예제 #5
0
    def decorated_function(**kwargs):
        if not 'copr_id' in kwargs or not 'uuid' in kwargs:
            return 'COPR_ID_OR_UUID_TOKEN_MISSING\n', 400

        copr_id = kwargs.pop('copr_id')
        try:
            copr = ComplexLogic.get_copr_by_id_safe(copr_id)
        except ObjectNotFound:
            return "PROJECT_NOT_FOUND\n", 404

        if copr.webhook_secret != kwargs.pop('uuid'):
            return "BAD_UUID\n", 403

        return route(copr, **kwargs)
예제 #6
0
def copr_createrepo(copr_id):
    copr = ComplexLogic.get_copr_by_id_safe(copr_id)
    if not flask.g.user.can_edit(copr):
        flask.flash(
            "You are not allowed to recreate repository metadata of copr with id {}."
            .format(copr_id), "error")
        return flask.redirect(url_for_copr_details(copr))

    actions_logic.ActionsLogic.send_createrepo(copr)
    db.session.commit()

    flask.flash(
        "Repository metadata in all directories will be regenerated...",
        "success")
    return flask.redirect(url_for_copr_details(copr))
예제 #7
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
예제 #8
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
예제 #9
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
예제 #10
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