Esempio n. 1
0
def check_requirements_closed(issue
                              ,close_date
                              ,issues_w_requirements
                              ,requirements_counter
                              ,measurements
                              ):
    """Check the specified closed issue for requirements that might also have
    been closed

    Args:
        issue - dictionary representing the issue to be checked
        close_date - date the issue was closed
        issues_w_requirements - collection of issue types that have requirements
        requirements_counter - counter object for requirements
        measurements - collection of measurements

    Returns:
        No return value
    """
    reqmnt_cnt = get_requirement_cnt(issue['fields']['description']
                                     ,issues_w_requirements
                                     ,issue['fields']['issuetype']['name'])
    if reqmnt_cnt > 0:
        requirements_counter.closed += reqmnt_cnt
        requirements_counter.open -= reqmnt_cnt

        ts = gen_timestamp(close_date)
        metadata = make_metadata(get_project(issue))
        measurements.append(requirements_closed(reqmnt_cnt, ts, metadata))
Esempio n. 2
0
def log_defect_created(issue, defect_counter, measurements):
    defect_counter.total += 1
    defect_counter.created += 1

    create_datetime = get_datetime(issue, "created")
    if GLOBALS['VERBOSE']:
        fstr = "New Defect: {0} at {1}"
        print(fstr.format(issue['key'], create_datetime))
    ts = gen_timestamp(create_datetime)
    metadata = make_metadata(get_project(issue))
    measurements.append(defects_added(ts, metadata))
    total = defect_counter.total
    measurements.append(defects_total(total, ts, metadata))
Esempio n. 3
0
def sonar_main(config):
    """Main function to retrieve and process results of the SonarQube analysis

    Args:
        config - Fully Populated GripConfig object

    Returns:
        No returned value
    """
    global GLOBALS
    # Hardcoded to use default local SonarQube installation
    # You will likely need to change this for your specific situation
    authenticate = ("admin", "admin")
    url_str = ("http://localhost:9000/api/resources?scopes=PRJ&resource={0}"
               "&metrics=lines,ncloc,duplicated_lines,complexity,"
               "class_complexity,function_complexity,file_complexity,tests"
               "&format=json")
                                         
    url = url_str.format(config.sonarqube_project)
    print("Making Request for: '{0}'".format(url))
    sonar_data = get_rest(url, authenticate)

    if sonar_data is not None:
        print("Got back {} results...".format(len(sonar_data[0]['msr'])))
        # Define the look-up table that will map keys from the SonarQube
        # results to functions that will generate the corresponging
        # GripMeasurements
        lut = {"class_complexity":class_complexity
               ,"complexity":complexity
               ,"duplicated_lines":duplicate_lines
               ,"file_complexity":file_complexity
               ,"function_complexity":function_complexity
               ,"lines":lines_comments
               ,"ncloc":loc
               }
        GLOBALS['TIMESTAMP'] = gen_timestamp(sonar_data[0]['date'])
        measurements = []
        for v in sonar_data[0]['msr']:
            lut[v['key']](v, measurements)

        if measurements:
            for i in measurements:
                print(i)
            gen_json(measurements, config.json_basename + "-sq")
    else:
        err_str = "{0}Unable to retrieve issues for {1}.\n"
        sys.stderr.write(err_str.format(ERR_LABEL, ACCOUNT_NAME))
Esempio n. 4
0
def check_open_requirements(issue
                            ,issues_w_requirements
                            ,requirements_counter
                            ,measurements
                            ):
    """If the issue has requirements, adds to the open and total requirements
    counts

    Unfortunately, this evaluation is not strictly accurate, since they could
    have added the requirement any time after creation.  However, short of
    walking backwards through the list of changes attempting to determine
    when requirements were added, we'll just look at the current state of
    the issue.

    Args:
        cfg_path - string containing the path to the configuration file

    Returns:
        No return value
    """
    i_fields = issue['fields']
    reqmnt_cnt = get_requirement_cnt(i_fields['description']
                                     ,issues_w_requirements
                                     ,i_fields['issuetype']['name']
                                     )
    if reqmnt_cnt > 0:
        if GLOBALS['VERBOSE']:
            fstr = "Adding {0} requirements for: {1}"
            print(fstr.format(reqmnt_cnt, issue['key']))
        requirements_counter.open += reqmnt_cnt
        requirements_counter.total += reqmnt_cnt        

        ts = gen_timestamp(i_fields['created'])
        metadata = make_metadata(get_project(issue))
        measurements.append(requirements_added(reqmnt_cnt, ts , metadata))
        total = requirements_counter.total
        measurements.append(requirements_total(total, ts, metadata))
Esempio n. 5
0
def log_defect_closed(issue, close_date, defect_counter, measurements):
    defect_counter.closed += 1
    ts = gen_timestamp(close_date)
    metadata = make_metadata(get_project(issue))
    measurements.append(defects_closed(ts, metadata))