コード例 #1
0
ファイル: events.py プロジェクト: openstack-infra/ciwatch
def add_event_to_db(event, commit_=True):
    project = db.get_project(_process_project_name(
        event["change"]["project"]))
    patch_set = db.get_or_create(
        models.PatchSet,
        commit_=False,
        project_id=project.id,
        ref=event['patchSet']['ref'],
        commit_message=event['change']['commitMessage'],
        created=datetime.fromtimestamp(
            int(event['patchSet']['createdOn'])))
    trusted = (event["author"]["name"] == jenkins_check)

    if trusted and "approvals" in event:
        if event["approvals"][0]["value"] in ("1", "2"):
            patch_set.verified = True
        elif event["approvals"][0]["value"] in ("-1", "-2"):
            patch_set.verified = False

    owner_name = event["author"]["name"]
    owner = db.get_or_create(models.CiOwner, name=owner_name)
    for ci, data in event['ci-status'].iteritems():
        ci_server = db.get_or_create(models.CiServer,
                                     commit_=False,
                                     name=ci,
                                     trusted=trusted,
                                     ci_owner_id=owner.id)
        db.update_or_create_comment(commit_=False,
                                    result=data["result"],
                                    log_url=data["log_url"],
                                    ci_server_id=ci_server.id,
                                    patch_set_id=patch_set.id)
    if commit_:
        db.Session().commit()
コード例 #2
0
ファイル: api.py プロジェクト: openstack-infra/ciwatch
def get_context():
    project_name = request.args.get('project', DEFAULT_PROJECT)
    time = request.args.get('time', DEFAULT_TIME_OPTION)
    since = datetime.now() - timedelta(hours=TIME_OPTIONS[time])
    project = db.get_project(project_name)
    patch_sets = db.get_patch_sets(project, since)
    results = OrderedDict()
    for ci in db.get_ci_servers():
        ci_info = _get_ci_info_for_patch_sets(ci, patch_sets)
        if any(result for result in ci_info["results"]):
            results[ci.ci_owner] = results.get(ci.ci_owner, [])
            results[ci.ci_owner].append(
                _get_ci_info_for_patch_sets(ci, patch_sets))

    return {"time_options": get_time_options(),
            "time_option": time,
            "patch_sets": patch_sets,
            "project": project,
            "projects": db.get_projects(),
            "user_results": results}