Beispiel #1
0
def handle_pull_request_comment(payload):
    comment = payload['comment']
    comment_content = comment['content']['raw'].lower()
    retry = 'ci retry' in comment_content
    rebuild = 'ci rebuild' in comment_content
    cleanup_lint = 'cleanup lint' in comment_content
    nocache = 'no cache' in comment_content
    if not (retry or rebuild or cleanup_lint):
        return

    repo = payload['repository']
    pr = payload['pullrequest']
    title = pr['title']

    if pr['state'] != 'OPEN':
        logger.info('Pull request state is not OPEN, ignore tests.')
        return

    source = pr['source']
    target = pr['destination']

    context = Context(repo['full_name'],
                      payload['actor'],
                      'pullrequest',
                      title,
                      source,
                      target,
                      rebuild=rebuild,
                      pr_id=pr['id'],
                      cleanup_lint=cleanup_lint,
                      nocache=nocache)
    start_pipeline.delay(context)
Beispiel #2
0
def handle_repo_commit_comment(payload):
    comment = payload['comment']
    comment_content = comment['content']['raw']

    retry = 'ci retry' in comment_content
    rebuild = 'ci rebuild' in comment_content
    nocache = 'no cache' in comment_content
    if not (retry or rebuild):
        return

    commit_hash = payload['commit']['hash']
    repo = payload['repository']
    repo_name = repo['full_name']

    context = Context(
        repo_name,
        payload['actor'],
        'commit',
        payload['commit']['message'],
        {
            'repository': {
                'full_name': repo_name
            },
            'branch': {
                'name': 'master'
            },
            'commit': {
                'hash': commit_hash
            },
        },
        rebuild=rebuild,
        nocache=nocache,
        clone_depth=0,  # Force a full git clone
    )
    start_pipeline.delay(context)
Beispiel #3
0
def handle_pull_request(payload):
    repo = payload['repository']
    scm = repo['scm']
    if scm.lower() != 'git':
        logger.info('Unsupported version system: %s', scm)
        return

    pr = payload['pullrequest']
    title = pr['title']
    description = pr['description'] or ''
    if 'ci skip' in title or 'ci skip' in description:
        logger.info('ci skip found, ignore tests.')
        return

    if pr['state'] != 'OPEN':
        logger.info('Pull request state is not OPEN, ignore tests.')
        return

    rebuild = False
    if 'ci rebuild' in title.lower() or 'ci rebuild' in description.lower():
        rebuild = True

    source = pr['source']
    target = pr['destination']

    context = Context(repo['full_name'],
                      payload['actor'],
                      'pullrequest',
                      title,
                      source,
                      target,
                      rebuild=rebuild,
                      pr_id=pr['id'])
    start_pipeline.delay(context)
Beispiel #4
0
def handle_repo_push(payload):
    changes = payload['push']['changes']
    if not changes:
        return

    repo = payload['repository']
    scm = repo['scm']
    if scm.lower() != 'git':
        logger.info('Unsupported version system: %s', scm)
        return

    latest_change = changes[0]
    if not latest_change['new'] or latest_change['new']['type'] != 'branch':
        logger.info('Unsupported push type: %s', latest_change['new']['type'])
        return
    if not latest_change['commits']:
        logger.warning('Can not find any commits')
        return

    commit_hash = latest_change['commits'][0]['hash']
    commit_message = latest_change['commits'][0]['message']
    if 'ci skip' in commit_message.lower():
        logger.info('ci skip found, ignore tests.')
        return

    rebuild = False
    if 'ci rebuild' in commit_message.lower():
        rebuild = True

    repo_name = repo['full_name']

    context = Context(
        repo_name,
        payload['actor'],
        'commit',
        commit_message,
        {
            'repository': {
                'full_name': repo_name
            },
            'branch': {
                'name': latest_change['new']['name']
            },
            'commit': {
                'hash': commit_hash
            },
        },
        rebuild=rebuild,
    )
    start_pipeline.delay(context)
Beispiel #5
0
def handle_repo_push(payload):
    changes = payload['push']['changes']
    if not changes:
        return

    repo = payload['repository']
    scm = repo['scm']
    if scm.lower() != 'git':
        logger.info('Unsupported version system: %s', scm)
        return

    for change in changes:
        if not change['new']:
            logger.info('No new changes found')
            continue

        repo_name = repo['full_name']
        push_type = change['new']['type']
        rebuild = False
        if push_type == 'tag':
            commit_hash = change['new']['target']['hash']
            commit_message = change['new']['target']['message']
        elif push_type == 'branch':
            if not change['commits']:
                logger.warning('Can not find any commits')
                continue
            commit_hash = change['commits'][0]['hash']
            commit_message = change['commits'][0]['message']
            if 'ci skip' in commit_message.lower():
                logger.info('ci skip found, ignore tests.')
                continue
            if 'ci rebuild' in commit_message.lower():
                rebuild = True
        else:
            logger.error('Unsupported push type: %s', push_type)
            continue

        source = {
            'repository': {'full_name': repo_name},
            'branch': {'name': change['new']['name']},
            'commit': {'hash': commit_hash}
        }
        context = Context(
            repo_name,
            payload['actor'],
            push_type,
            commit_message,
            source,
            rebuild=rebuild,
        )
        try:
            _cancel_outdated_pipelines(context)
        except Exception:
            sentry.captureException()
        future = start_pipeline.delay(context)
        future.add_done_callback(lambda fut: _RUNNING_PIPELINES.pop(context.task_id, None))
        _RUNNING_PIPELINES[context.task_id] = future
        if push_type == 'branch':
            check_pr_mergeable.delay(context)
Beispiel #6
0
def handle_pull_request(payload):
    repo = payload['repository']
    scm = repo['scm']
    if scm.lower() != 'git':
        logger.info('Unsupported version system: %s', scm)
        return

    pr = payload['pullrequest']
    title = pr['title']
    description = pr['description'] or ''
    if 'ci skip' in title or 'ci skip' in description:
        logger.info('ci skip found, ignore tests.')
        return

    if pr['state'] != 'OPEN':
        logger.info('Pull request state is not OPEN, ignore tests.')
        return

    title_lower = title.lower()
    desc_lower = description.lower()
    rebuild = 'ci rebuild' in title_lower or 'ci rebuild' in desc_lower
    skip_lint = 'lint skip' in title_lower or 'lint skip' in desc_lower

    source = pr['source']
    target = pr['destination']

    context = Context(
        repo['full_name'],
        payload['actor'],
        'pullrequest',
        title,
        source,
        target,
        rebuild=rebuild,
        pr_id=pr['id'],
        skip_lint=skip_lint
    )
    try:
        _cancel_outdated_pipelines(context)
    except Exception:
        sentry.captureException()
    future = start_pipeline.delay(context)
    future.add_done_callback(lambda fut: _RUNNING_PIPELINES.pop(context.task_id, None))
    _RUNNING_PIPELINES[context.task_id] = future
Beispiel #7
0
def handle_pull_request_comment(payload):
    comment = payload['comment']
    comment_content = comment['content']['raw'].lower()
    retry = 'ci retry' in comment_content
    rebuild = 'ci rebuild' in comment_content
    nocache = 'no cache' in comment_content
    if not (retry or rebuild):
        return

    repo = payload['repository']
    pr = payload['pullrequest']
    title = pr['title']

    if pr['state'] != 'OPEN':
        logger.info('Pull request state is not OPEN, ignore tests.')
        return

    title_lower = title.lower()
    description = pr['description'] or ''
    desc_lower = description.lower()
    skip_lint = 'lint skip' in title_lower or 'lint skip' in desc_lower
    source = pr['source']
    target = pr['destination']

    context = Context(
        repo['full_name'],
        payload['actor'],
        'pullrequest',
        title,
        source,
        target,
        rebuild=rebuild,
        pr_id=pr['id'],
        nocache=nocache,
        skip_lint=skip_lint
    )
    try:
        _cancel_outdated_pipelines(context)
    except Exception:
        sentry.captureException()
    future = start_pipeline.delay(context)
    future.add_done_callback(lambda fut: _RUNNING_PIPELINES.pop(context.task_id, None))
    _RUNNING_PIPELINES[context.task_id] = future