Exemple #1
0
def rebuild_pr(request, owner, project, pr):
    project_ = Project.objects.filter(owner=owner, name=project).all()[0]
    # Intentionally asking GitHub for the PR
    pull_request = project_.get_pull_request(request.user, int(pr))
    build = JenkinsBuild.new_from_project_pr(project_, pull_request)
    build.trigger_jenkins()
    return HttpResponse(status=204, content_type='application/json')
Exemple #2
0
def pull_request_row(request, owner, project, pr_number):
    project_ = Project.objects.filter(owner=owner, name=project).all()[0]
    pr = PullRequest.objects.get(project=project_, number=int(pr_number))
    if not pr.open:
        data = {'open': False, 'pr_id': _make_pr_id(pr)}
        return HttpResponse(json.dumps(data), content_type='application/json')
    build = JenkinsBuild.search_pull_request(project_, pr.number)
    row = _get_row_dict(project_, pr, build)
    return HttpResponse(json.dumps(row), content_type='application/json')
def _get_build(project_name, pr_number, build_number=None):
    try:
        project = Project.get(project_name)
    except Exception:
        logger.exception()
        return None
    if project is None:
        logger.info('project not found: {0!r}'.format(
            project_name))
        return None
    build = JenkinsBuild.search_pull_request(
        project, int(pr_number), build_number=build_number)
    if build is None:
        logger.info('Build not found: PR {0}, build {1}'.format(
            pr_number, build_number))
        return None
    return build
def github(request):
    data = json.loads(request.body)
    action = data['action']
    pull_request = data['pull_request']
    pr_number = int(pull_request["number"])
    project_name = pull_request['base']['repo']['full_name']
    logger.info('Received event from GitHub: PR #{0}, {1}: {2}'.format(
        pr_number, project_name, action))

    html_url = pull_request['html_url']
    pr = PullRequest.update_pull_request(pr_number, project_name, html_url)
    if pr is None:
        return HttpResponse(status=404)

    if action not in ('opened', 'synchronize'):
        return HttpResponse(status=204)

    build = JenkinsBuild.new_from_project_pr(pr.project, pr)
    build.trigger_jenkins()
    build.notify_github()

    return HttpResponse(status=204)
Exemple #5
0
def _get_pr_build_list(project, pull_requests):
    return [(_make_pr_id(pr), pr, JenkinsBuild.search_pull_request(
        project, pr.number)) for pr in pull_requests]