Beispiel #1
0
def hot_changes(es, index, repository_fullname, params):
    params = deepcopy(params)
    size = params.get("size")
    # Set a significant depth to get an 'accurate' average value
    params["size"] = 500
    top_commented_changes = changes_top_commented(es, index,
                                                  repository_fullname, params)
    # Keep changes with comment events > average
    top_commented_changes = [
        change for change in top_commented_changes["items"]
        if change["doc_count"] > top_commented_changes["count_avg"]
    ]
    mapping = {}
    for top_commented_change in top_commented_changes:
        mapping[
            top_commented_change["key"]] = top_commented_change["doc_count"]
    change_ids = [_id["key"] for _id in top_commented_changes]
    if not change_ids:
        return {"items": []}
    _params = {
        "etype": ("Change", ),
        "state": "OPEN",
        "change_ids": change_ids,
    }
    changes = _scan(es, index, repository_fullname, _params)
    for change in changes:
        change["hot_score"] = mapping[change["change_id"]]
    changes = enhance_changes(changes)
    items = sorted(changes, key=lambda x: x["hot_score"], reverse=True)
    if size:
        items = items[:size]
    return {"items": items}
Beispiel #2
0
def changes_and_events(es, index, repository_fullname, params):
    params = deepcopy(params)
    params["etype"] = (
        "Change",
        "ChangeCreatedEvent",
        "ChangeMergedEvent",
        "ChangeAbandonedEvent",
        "ChangeCommitPushedEvent",
        "ChangeCommitForcePushedEvent",
        "ChangeReviewedEvent",
        "ChangeCommentedEvent",
    )
    body = {
        "sort": [{
            "created_at": {
                "order": "asc"
            }
        }],
        "size": params["size"],
        "from": params["from"],
        "query": generate_filter(es, index, repository_fullname, params),
    }
    data = run_query(es, index, body)
    changes = [r["_source"] for r in data["hits"]["hits"]]
    changes = enhance_changes(changes)
    return {"items": changes, "total": totalc(data["hits"]["total"])}
Beispiel #3
0
def changes_and_events(es, index, repository_fullname, params):
    params = deepcopy(params)
    params['etype'] = (
        "Change",
        'ChangeCreatedEvent',
        "ChangeMergedEvent",
        "ChangeAbandonedEvent",
        "ChangeCommitPushedEvent",
        "ChangeCommitForcePushedEvent",
        "ChangeReviewedEvent",
        "ChangeCommentedEvent",
    )
    body = {
        "sort": [{
            "created_at": {
                "order": "asc"
            }
        }],
        "size": params['size'],
        "from": params['from'],
        "query": generate_filter(repository_fullname, params),
    }
    data = run_query(es, index, body)
    changes = [r['_source'] for r in data['hits']['hits']]
    changes = enhance_changes(changes)
    return {'items': changes, 'total': data['hits']['total']}
Beispiel #4
0
def hot_changes(es, index, repository_fullname, params):
    params = deepcopy(params)
    size = params.get('size')
    # Set a significant depth to get an 'accurate' average value
    params['size'] = 500
    top_commented_changes = changes_top_commented(es, index,
                                                  repository_fullname, params)
    # Keep changes with comment events > average
    top_commented_changes = [
        change for change in top_commented_changes['items']
        if change['doc_count'] > top_commented_changes['count_avg']
    ]
    mapping = {}
    for top_commented_change in top_commented_changes:
        mapping[
            top_commented_change['key']] = top_commented_change['doc_count']
    change_ids = [_id['key'] for _id in top_commented_changes]
    if not change_ids:
        return {'items': []}
    _params = {
        'etype': ('Change', ),
        'state': 'OPEN',
        'change_ids': change_ids,
    }
    changes = _scan(es, index, repository_fullname, _params)
    for change in changes:
        change['hot_score'] = mapping[change['change_id']]
    changes = enhance_changes(changes)
    items = sorted(changes, key=lambda x: x['hot_score'], reverse=True)
    if size:
        items = items[:size]
    return {'items': items}
Beispiel #5
0
def changes(es, index, repository_fullname, params):
    params = deepcopy(params)
    params["etype"] = ["Change"]
    body = {
        "sort": [{"created_at": {"order": "asc"}}],
        "size": params["size"],
        "from": params["from"],
        "query": generate_filter(es, index, repository_fullname, params),
    }
    data = run_query(es, index, body)
    changes = [r["_source"] for r in data["hits"]["hits"]]
    changes = enhance_changes(changes)
    return {"items": changes, "total": totalc(data["hits"]["total"])}
Beispiel #6
0
def last_changes(es, index, repository_fullname, params):
    params = deepcopy(params)
    params['etype'] = ("Change",)
    body = {
        "sort": [{"updated_at": {"order": "desc"}}],
        "size": params['size'],
        "from": params['from'],
        "query": generate_filter(es, index, repository_fullname, params),
    }
    data = run_query(es, index, body)
    changes = [r['_source'] for r in data['hits']['hits']]
    changes = enhance_changes(changes)
    return {'items': changes, 'total': totalc(data['hits']['total'])}
Beispiel #7
0
def cold_changes(es, index, repository_fullname, params):
    params = deepcopy(params)
    size = params.get("size")
    params["etype"] = ("Change",)
    params["state"] = ("OPEN",)
    changes = _scan(es, index, repository_fullname, params)
    _changes_ids = set([change["change_id"] for change in changes])
    params["etype"] = ("ChangeCommentedEvent", "ChangeReviewedEvent")
    del params["state"]
    events = _scan(es, index, repository_fullname, params)
    _events_ids = set([event["change_id"] for event in events])
    changes_ids_wo_rc = _changes_ids.difference(_events_ids)
    changes_wo_rc = [
        change for change in changes if change["change_id"] in changes_ids_wo_rc
    ]
    changes_wo_rc = enhance_changes(changes_wo_rc)
    items = sorted(changes_wo_rc, key=lambda x: is8601_to_dt(x["created_at"]))
    if size:
        items = items[:size]
    return {"items": items}
Beispiel #8
0
def cold_changes(es, index, repository_fullname, params):
    params = deepcopy(params)
    size = params.get('size')
    params['etype'] = ('Change',)
    params['state'] = 'OPEN'
    changes = _scan(es, index, repository_fullname, params)
    _changes_ids = set([change['change_id'] for change in changes])
    params['etype'] = ('ChangeCommentedEvent', 'ChangeReviewedEvent')
    del params['state']
    events = _scan(es, index, repository_fullname, params)
    _events_ids = set([event['change_id'] for event in events])
    changes_ids_wo_rc = _changes_ids.difference(_events_ids)
    changes_wo_rc = [
        change for change in changes if change['change_id'] in changes_ids_wo_rc
    ]
    changes_wo_rc = enhance_changes(changes_wo_rc)
    items = sorted(changes_wo_rc, key=lambda x: is8601_to_dt(x['created_at']))
    if size:
        items = items[:size]
    return {'items': items}