Exemple #1
0
def _walk_api(full_url, db_config, options):
    """
    Call the github api at full_url, and continue to aggregate json
    results as long as a "next" link exists.

    Errors will raise an exception.
    """
    all_jsons = []

    resp = _raw_api(full_url, db_config, options)
    if not resp.ok:
        # for now, just bomb out totally, on the theory that we don't
        # want to deal with stale caches etc.  LATER in the future,
        # make this a little more robust.
        err = "Github API error: %s" % resp.text
        log.error(err)
        raise RuntimeError(err)

    all_jsons.append(resp.text)

    # walk through any "next" links
    if "link" in resp.headers:
        links = [h.strip() for h in resp.headers["link"].split(",")]
        for link in links:
            pieces = [piece.strip() for piece in link.split(";")]
            if pieces[1] == 'rel="next"':
                next_url = pieces[0].strip("<>")
                log.verbose("Found a next link %s, following it." % next_url, options)
                all_jsons.extend(_walk_api(next_url, db_config, options))

    return all_jsons
Exemple #2
0
def whack(traceback_txt, config, options):
    """
    Extract any traceback from traceback_txt and attempt to match it
    to a bug.
    """
    _ensure_tracewhack_data_dir()

    tbs = extract_tracebacks(traceback_txt)
    if not tbs:
        err = "Could not extract a traceback"
        log.error(err)
        raise ValueError(err)

    bugs_with_tbs = _bugs_with_tbs(config, options)
    bug_and_scores = _score_bugs(tbs, bugs_with_tbs)
    print "Displaying best matches:"

    for (match_i, (bug, score)) in enumerate(bug_and_scores):
        if match_i >= options['num_results']:
            break
        print _fmt_bug(bug, score)