Example #1
0
def handle_suppress(args):
    def bug_hash_filter(bug_id, filepath):
        filepath = '%' + filepath
        return [
            ttypes.ReportFilter(bugHash=bug_id, filepath=filepath),
            ttypes.ReportFilter(bugHash=bug_id, filepath=filepath)
        ]

    limit = constants.MAX_QUERY_SIZE

    client = setup_client(args.product_url)

    run_info = check_run_names(client, [args.name])
    run = run_info.get(args.name)

    if 'input' in args:
        with open(args.input) as supp_file:
            suppress_data = suppress_file_handler.get_suppress_data(supp_file)

        for bug_id, file_name, comment in suppress_data:
            reports = client.getRunResults([run.runId], limit, 0, None,
                                           bug_hash_filter(bug_id, file_name),
                                           None)

            for report in reports:
                status = ttypes.ReviewStatus.FALSE_POSITIVE
                client.changeReviewStatus(report.reportId, status, comment)
Example #2
0
def handle_suppress(args):

    init_logger(args.verbose if 'verbose' in args else None)

    limit = constants.MAX_QUERY_SIZE

    client = setup_client(args.product_url)

    run_info = check_run_names(client, [args.name])
    run = run_info.get(args.name)

    if 'input' in args:
        with open(args.input) as supp_file:
            suppress_data = suppress_file_handler.get_suppress_data(supp_file)

        for bug_id, file_name, comment, status in suppress_data:
            file_name = '%' + file_name
            bug_hash_filter = ttypes.ReportFilter(filepath=[file_name],
                                                  reportHash=[bug_id])
            reports = client.getRunResults([run.runId], limit, 0, None,
                                           bug_hash_filter, None)

            for report in reports:
                rw_status = ttypes.ReviewStatus.FALSE_POSITIVE
                if status == 'confirmed':
                    rw_status = ttypes.ReviewStatus.CONFIRMED
                elif status == 'intentional':
                    rw_status = ttypes.ReviewStatus.INTENTIONAL

                client.changeReviewStatus(report.reportId, rw_status, comment)
Example #3
0
def handle_suppress(args):
    def update_suppression_comment(run_id, report_id, comment):
        client.unSuppressBug([run_id], report_id)
        client.suppressBug([run_id], report_id, comment)

    def bug_hash_filter(bug_id, filepath):
        filepath = '%' + filepath
        return [
            codeCheckerDBAccess.ttypes.ReportFilter(bugHash=bug_id,
                                                    suppressed=True,
                                                    filepath=filepath),
            codeCheckerDBAccess.ttypes.ReportFilter(bugHash=bug_id,
                                                    suppressed=False,
                                                    filepath=filepath)
        ]

    already_suppressed = 'Bug {} in file {} already suppressed. Use --force!'
    limit = codeCheckerDBAccess.constants.MAX_QUERY_SIZE

    client = setupClient(args.host, args.port, '/')

    run_info = check_run_names(client, [args.name])
    run_id, run_date = run_info.get(args.name)

    if args.output:
        for suppression in client.getSuppressedBugs(run_id):
            suppress_file_handler.write_to_suppress_file(
                args.output, suppression.bug_hash, suppression.file_name,
                suppression.comment)

    elif args.input:
        with open(args.input) as supp_file:
            suppress_data = suppress_file_handler.get_suppress_data(supp_file)

        for bug_id, file_name, comment in suppress_data:
            reports = client.getRunResults(run_id, limit, 0, None,
                                           bug_hash_filter(bug_id, file_name))

            for report in reports:
                if report.suppressed and not args.force:
                    print(already_suppressed.format(bug_id, file_name))
                else:
                    update_suppression_comment(run_id, report.reportId,
                                               comment)

    elif args.bugid:
        reports = client.getRunResults(run_id, limit, 0, None,
                                       bug_hash_filter(args.bugid, args.file))

        for report in reports:
            if args.x:
                client.unSuppressBug([run_id], report.reportId)
            elif report.suppressed and not args.force:
                print(already_suppressed.format(args.bugid, args.file))
            else:
                update_suppression_comment(run_id, report.reportId,
                                           args.comment)
Example #4
0
def send_suppress(run_id, connection, file_name):
    """
    Collect suppress information from the suppress file to be stored
    in the database.
    """
    suppress_data = []
    if os.path.exists(file_name):
        with codecs.open(file_name, 'r', 'UTF-8') as s_file:
            suppress_data = suppress_file_handler.get_suppress_data(s_file)

    if len(suppress_data) > 0:
        connection.add_suppress_bug(run_id, suppress_data)