def scan()

in src/plugins/scanners/gerrit.py [0:0]


def scan(KibbleBit, source):
    source['steps']['issues'] = {
        'time': time.time(),
        'status': 'Analyzing Gerrit tickets...',
        'running': True,
        'good': True
    }
    KibbleBit.updateSource(source)

    url = source['sourceURL']
    # Try matching foo.bar/r/project/subfoo
    m = re.match(r"(.+://.+?/r)/(.+)", url)
    if m:
        base_url = m.group(1)
        project_name = m.group(2)
    # Fall back to old splitty split
    else:
        url = re.sub(r"^git://", "http://", url)
        source_parts = url.split('/')
        project_name = source_parts[-1]
        base_url = '/'.join(source_parts[:-1]) # remove the trailing /blah/

    # TODO: figure out branch from current checkout
    q = "(is:open OR is:new OR is:closed OR is:merged OR is:abandoned) AND project:\"%s\"" % project_name
    all_changes = get_all(base_url, changes,
                                    {'q': q,
                                     'o': ['LABELS', 'DETAILED_ACCOUNTS']})

    print("Found " + str(len(all_changes)) + " changes for project: " +
          project_name)

    people = {}
    for change in all_changes:
        try:
            # TODO: check if needs updating here before getting details
            dhash = make_hash(source, change)

            stored_change = None
            if KibbleBit.exists('issue', dhash):
                stored_change = KibbleBit.get('issue', dhash)

            if not status_changed(stored_change, change):
                #print("change %s seen already and status unchanged. Skipping." %
                #      change['change_id'])
                continue

            details = change_details(base_url, change)

            issue_doc = make_issue(source, base_url, details)
            update_issue(KibbleBit, issue_doc)

            labels = details['labels']
            change_people = []

            if 'owner' in details:
                change_people.append(details['owner'])
            if 'Module-Owner' in labels and 'all' in labels['Module-Owner']:
                change_people.extend(labels['Module-Owner']['all'])
            if 'Code-Review' in labels and 'all' in labels['Code-Review']:
                change_people.extend(labels['Code-Review']['all'])
            if 'Verified' in labels and 'all' in labels['Verified']:
                change_people.extend(labels['Verified']['all'])

            print(change['change_id'] + " -> " + str(len(change_people)) +
                  " people.")

            for person in change_people:
                if 'email' in person and person['email'] not in people:
                    people[person['email']] = person
                    update_person(KibbleBit, make_person(source, person))

        except requests.HTTPError as e:
            print(e)
            
    source['steps']['issues'] = {
        'time': time.time(),
        'status': 'Done analyzing tickets!',
        'running': False,
        'good': True
    }
    KibbleBit.updateSource(source)