예제 #1
0
def get_shipit_facts(issuewrapper,
                     meta,
                     module_indexer,
                     core_team=[],
                     botnames=[]):
    """ Count shipits by maintainers/community/other """

    # maintainers - people who maintain this file/module
    # community - people who maintain file(s) in the same directory
    # other - anyone else who comments with shipit/+1/LGTM

    iw = issuewrapper
    nmeta = {
        'shipit': False,
        'owner_pr': False,
        'shipit_ansible': False,
        'shipit_community': False,
        'shipit_count_other': False,
        'shipit_count_community': False,
        'shipit_count_maintainer': False,
        'shipit_count_ansible': False,
        'shipit_actors': None,
        'community_usernames': [],
        'notify_community_shipit': False,
    }

    if not iw.is_pullrequest():
        return nmeta

    module_utils_files_owned = 0  # module_utils files for which submitter is maintainer
    if meta['is_module_util']:
        for f in iw.files:
            if f.startswith('lib/ansible/module_utils'
                            ) and f in module_indexer.botmeta['files']:
                maintainers = module_indexer.botmeta['files'][f].get(
                    'maintainers', [])
                if maintainers and (iw.submitter in maintainers):
                    module_utils_files_owned += 1
        if module_utils_files_owned == len(iw.files):
            nmeta['owner_pr'] = True
            return nmeta

    if not meta['module_match']:
        return nmeta

    # https://github.com/ansible/ansibullbot/issues/722
    if iw.wip:
        logging.debug('WIP PRs do not get shipits')
        return nmeta

    if meta['is_needs_revision'] or meta['is_needs_rebase']:
        logging.debug(
            'PRs with needs_revision or needs_rebase label do not get shipits')
        return nmeta

    maintainers = meta['module_match']['maintainers']
    maintainers = \
        ModuleIndexer.replace_ansible(
            maintainers,
            core_team,
            bots=botnames
        )

    modules_files_owned = 0
    if not meta['is_new_module']:
        for f in iw.files:
            if f.startswith(
                    'lib/ansible/modules'
            ) and iw.submitter in module_indexer.modules[f]['maintainers']:
                modules_files_owned += 1
    nmeta['owner_pr'] = modules_files_owned + module_utils_files_owned == len(
        iw.files)

    # community is the other maintainers in the same namespace
    mnamespace = meta['module_match']['namespace']
    community = \
        module_indexer.get_maintainers_for_namespace(mnamespace)
    community = [
        x for x in community
        if x != 'ansible' and x not in core_team and x != 'DEPRECATED'
    ]

    # shipit tallies
    ansible_shipits = 0
    maintainer_shipits = 0
    community_shipits = 0
    other_shipits = 0
    shipit_actors = []
    shipit_actors_other = []

    for event in iw.history.history:

        if event['event'] not in [
                'commented', 'committed', 'review_approved', 'review_comment'
        ]:
            continue
        if event['actor'] in botnames:
            continue

        # commits reset the counters
        if event['event'] == 'committed':
            ansible_shipits = 0
            maintainer_shipits = 0
            community_shipits = 0
            other_shipits = 0
            shipit_actors = []
            shipit_actors_other = []
            continue

        actor = event['actor']
        body = event.get('body', '')
        body = body.strip()
        if not is_approval(body):
            continue
        logging.info('%s shipit' % actor)

        # ansible shipits
        if actor in core_team:
            if actor not in shipit_actors:
                ansible_shipits += 1
                shipit_actors.append(actor)
            continue

        # maintainer shipits
        if actor in maintainers:
            if actor not in shipit_actors:
                maintainer_shipits += 1
                shipit_actors.append(actor)
            continue

        # community shipits
        if actor in community:
            if actor not in shipit_actors:
                community_shipits += 1
                shipit_actors.append(actor)
            continue

        # other shipits
        if actor not in shipit_actors_other:
            other_shipits += 1
            shipit_actors_other.append(actor)
        continue

    # submitters should count if they are core team/maintainers/community
    if iw.submitter in core_team:
        if iw.submitter not in shipit_actors:
            ansible_shipits += 1
            shipit_actors.append(iw.submitter)
    elif iw.submitter in maintainers:
        if iw.submitter not in shipit_actors:
            maintainer_shipits += 1
            shipit_actors.append(iw.submitter)
    elif iw.submitter in community:
        if iw.submitter not in shipit_actors:
            community_shipits += 1
            shipit_actors.append(iw.submitter)

    nmeta['shipit_count_other'] = other_shipits
    nmeta['shipit_count_community'] = community_shipits
    nmeta['shipit_count_maintainer'] = maintainer_shipits
    nmeta['shipit_count_ansible'] = ansible_shipits
    nmeta['shipit_actors'] = shipit_actors
    nmeta['shipit_actors_other'] = shipit_actors_other
    nmeta['community_usernames'] = sorted(community)

    total = community_shipits + maintainer_shipits + ansible_shipits

    # include shipits from other people to push over the edge
    if total == 1 and other_shipits > 2:
        total += other_shipits

    if total > 1:
        nmeta['shipit'] = True
    elif meta['is_new_module'] or \
            (len(maintainers) == 1 and maintainer_shipits == 1):
        if community:
            bpc = iw.history.get_boilerplate_comments()
            if 'community_shipit_notify' not in bpc:
                nmeta['notify_community_shipit'] = True

    logging.info('total shipits: %s' % total)

    return nmeta
예제 #2
0
def get_shipit_facts(issuewrapper,
                     inmeta,
                     module_indexer,
                     core_team=[],
                     botnames=[]):
    """ Count shipits by maintainers/community/other """

    # supershipit - maintainers with isolated commit access
    # maintainers - people who maintain this file/module
    # community - people who maintain file(s) in the same directory
    # other - anyone else who comments with shipit/+1/LGTM

    meta = inmeta.copy()
    iw = issuewrapper
    nmeta = {
        u'shipit': False,
        u'supershipit': False,
        u'owner_pr': False,
        u'shipit_ansible': False,
        u'shipit_community': False,
        u'shipit_count_other': False,
        u'shipit_count_community': False,
        u'shipit_count_maintainer': False,
        u'shipit_count_ansible': False,
        u'shipit_count_vtotal': False,
        u'shipit_count_historical': False,
        u'shipit_actors': None,
        u'supershipit_actors': None,
        u'community_usernames': [],
        u'notify_community_shipit': False,
        u'is_rebuild_merge': False,
    }

    if not iw.is_pullrequest():
        return nmeta

    # https://github.com/ansible/ansibullbot/issues/1147
    meta[u'component_matches'] = [
        x for x in meta.get(u'component_matches', [])
        if not x[u'repo_filename'].startswith(u'changelogs/fragments/')
    ]

    files = [f for f in iw.files if not f.startswith(u'changelogs/fragments/')]
    module_utils_files_owned = 0  # module_utils files for which submitter is maintainer
    if meta[u'is_module_util']:
        for f in files:
            if f.startswith(u'lib/ansible/module_utils'
                            ) and f in module_indexer.botmeta[u'files']:
                maintainers = module_indexer.botmeta[u'files'][f].get(
                    u'maintainers', [])
                if maintainers and (iw.submitter in maintainers):
                    module_utils_files_owned += 1

    modules_files_owned = 0
    if not meta[u'is_new_module']:
        for f in files:
            if f.startswith(u'lib/ansible/modules') and iw.submitter in meta[
                    u'component_maintainers']:
                modules_files_owned += 1
    nmeta[u'owner_pr'] = modules_files_owned + module_utils_files_owned == len(
        files)

    # https://github.com/ansible/ansibullbot/issues/722
    if iw.wip:
        logging.debug(u'WIP PRs do not get shipits')
        return nmeta

    if meta[u'is_needs_revision'] or meta[u'is_needs_rebase']:
        logging.debug(
            u'PRs with needs_revision or needs_rebase label do not get shipits'
        )
        return nmeta

    supershipiteers_byfile = {}
    supershipiteers_byuser = {}
    for cm in meta.get('component_matches', []):
        _ss = cm.get(u'supershipit', [])
        supershipiteers_byfile[cm[u'repo_filename']] = _ss[:]
        for ss in _ss:
            if ss not in supershipiteers_byuser:
                supershipiteers_byuser[ss] = []
            supershipiteers_byuser[ss].append(cm[u'repo_filename'])

    maintainers = meta.get(u'component_maintainers', [])
    maintainers = \
        ModuleIndexer.replace_ansible(
            maintainers,
            core_team,
            bots=botnames
        )

    # community is the other maintainers in the same namespace
    community = meta.get(u'component_namespace_maintainers', [])
    community = [
        x for x in community
        if x != u'ansible' and x not in core_team and x != u'DEPRECATED'
    ]

    # shipit tallies
    ansible_shipits = 0
    maintainer_shipits = 0
    community_shipits = 0
    other_shipits = 0
    shipit_actors = []
    shipit_actors_other = []
    supershipiteers_voted = set()
    rebuild_merge = False
    shipits_historical = set()

    for event in iw.history.history:

        if event[u'event'] not in [
                u'commented', u'committed', u'review_approved',
                u'review_comment'
        ]:
            continue
        if event[u'actor'] in botnames:
            continue

        # commits reset the counters
        if event[u'event'] == u'committed':
            logging.info(event)
            ansible_shipits = 0
            maintainer_shipits = 0
            community_shipits = 0
            other_shipits = 0
            shipit_actors = []
            shipit_actors_other = []
            supershipiteers_voted = set()
            rebuild_merge = False
            logging.info('commit detected, resetting shipit tallies')
            continue

        actor = event[u'actor']
        body = event.get(u'body', u'')
        body = body.strip()

        if not is_approval(body):
            continue

        # historical shipits (keep track of all of them, even if reset)
        shipits_historical.add(actor)

        if actor in core_team and is_rebuild_merge(body):
            rebuild_merge = True
            logging.info(u'%s shipit [rebuild_merge]' % actor)
        else:
            logging.info(u'%s shipit' % actor)

        # super shipits
        if actor in supershipiteers_byuser:
            supershipiteers_voted.add(actor)

        # ansible shipits
        if actor in core_team:
            if actor not in shipit_actors:
                ansible_shipits += 1
                shipit_actors.append(actor)
            continue

        # maintainer shipits
        if actor in maintainers:
            if actor not in shipit_actors:
                maintainer_shipits += 1
                shipit_actors.append(actor)
            continue

        # community shipits
        if actor in community:
            if actor not in shipit_actors:
                community_shipits += 1
                shipit_actors.append(actor)
            continue

        # other shipits
        if actor not in shipit_actors_other:
            other_shipits += 1
            shipit_actors_other.append(actor)

        continue

    # submitters should count if they are core team/maintainers/community
    if iw.submitter in core_team:
        if iw.submitter not in shipit_actors:
            ansible_shipits += 1
            shipit_actors.append(iw.submitter)
        shipits_historical.add(iw.submitter)
    elif iw.submitter in maintainers:
        if iw.submitter not in shipit_actors:
            maintainer_shipits += 1
            shipit_actors.append(iw.submitter)
        shipits_historical.add(iw.submitter)
    elif iw.submitter in community:
        if iw.submitter not in shipit_actors:
            community_shipits += 1
            shipit_actors.append(iw.submitter)
        shipits_historical.add(iw.submitter)

    nmeta[u'shipit_count_other'] = other_shipits
    nmeta[u'shipit_count_community'] = community_shipits
    nmeta[u'shipit_count_maintainer'] = maintainer_shipits
    nmeta[u'shipit_count_ansible'] = ansible_shipits
    nmeta[u'shipit_actors'] = shipit_actors
    nmeta[u'shipit_actors_other'] = shipit_actors_other
    nmeta[u'community_usernames'] = sorted(community)
    nmeta[u'shipit_count_historical'] = list(shipits_historical)
    nmeta[u'shipit_count_htotal'] = len(list(shipits_historical))

    total = community_shipits + maintainer_shipits + ansible_shipits
    nmeta[u'shipit_count_vtotal'] = total + other_shipits

    if rebuild_merge:
        nmeta['is_rebuild_merge'] = True

    # include shipits from other people to push over the edge
    if total == 1 and other_shipits > 2:
        total += other_shipits

    if total > 1 or rebuild_merge:
        nmeta[u'shipit'] = True
    elif meta[u'is_new_module'] or \
            (len(maintainers) == 1 and maintainer_shipits == 1):
        # don't notify if there is no maintainer or if submitter is the only namespace maintainer
        if set(community) - {iw.submitter}:
            bpc = iw.history.get_boilerplate_comments()
            bpc = [x[0] for x in bpc]
            if u'community_shipit_notify' not in bpc:
                nmeta[u'notify_community_shipit'] = True

    logging.info(u'total shipits: %s' % total)

    # supershipit ...
    #   if a supershipiteer for each file exists and has blessed the PR
    #   on the current commit, then override all shipit tallies and get this PR merged
    if supershipiteers_voted:
        nmeta[u'supershipit_actors'] = list(supershipiteers_voted)
        cm_files = [x[u'repo_filename'] for x in meta[u'component_matches']]
        ss_files = set()
        for ssv in supershipiteers_voted:
            for fn in supershipiteers_byuser[ssv]:
                ss_files.add(fn)

        if sorted(set(cm_files)) == sorted(set(ss_files)):
            logging.info(u'supershipit enabled on %s' % iw.html_url)
            nmeta[u'supershipit'] = True
            nmeta[u'shipit'] = True
        else:
            for cm_file in sorted(cm_files):
                if cm_file not in ss_files:
                    logging.info('%s is not governed by supershipit' % cm_file)

    return nmeta
예제 #3
0
def get_shipit_facts(issuewrapper, inmeta, module_indexer, core_team=[], botnames=[]):
    """ Count shipits by maintainers/community/other """

    # supershipit - maintainers with isolated commit access
    # maintainers - people who maintain this file/module
    # community - people who maintain file(s) in the same directory
    # other - anyone else who comments with shipit/+1/LGTM

    meta = inmeta.copy()
    iw = issuewrapper
    nmeta = {
        u'shipit': False,
        u'supershipit': False,
        u'owner_pr': False,
        u'shipit_ansible': False,
        u'shipit_community': False,
        u'shipit_count_other': False,
        u'shipit_count_community': False,
        u'shipit_count_maintainer': False,
        u'shipit_count_ansible': False,
        u'shipit_count_vtotal': False,
        u'shipit_actors': None,
        u'supershipit_actors': None,
        u'community_usernames': [],
        u'notify_community_shipit': False,
        u'is_rebuild_merge': False,
    }

    if not iw.is_pullrequest():
        return nmeta

    # https://github.com/ansible/ansibullbot/issues/1147
    meta[u'component_matches'] = [
        x for x in meta.get(u'component_matches', [])
        if not x[u'repo_filename'].startswith(u'changelogs/fragments/')
    ]

    module_utils_files_owned = 0  # module_utils files for which submitter is maintainer
    if meta[u'is_module_util']:
        for f in iw.files:
            if f.startswith(u'lib/ansible/module_utils') and f in module_indexer.botmeta[u'files']:
                maintainers = module_indexer.botmeta[u'files'][f].get(u'maintainers', [])
                if maintainers and (iw.submitter in maintainers):
                    module_utils_files_owned += 1

    modules_files_owned = 0
    if not meta[u'is_new_module']:
        for f in iw.files:
            if f.startswith(u'lib/ansible/modules') and iw.submitter in meta[u'component_maintainers']:
                modules_files_owned += 1
    nmeta[u'owner_pr'] = modules_files_owned + module_utils_files_owned == len(iw.files)

    # https://github.com/ansible/ansibullbot/issues/722
    if iw.wip:
        logging.debug(u'WIP PRs do not get shipits')
        return nmeta

    if meta[u'is_needs_revision'] or meta[u'is_needs_rebase']:
        logging.debug(u'PRs with needs_revision or needs_rebase label do not get shipits')
        return nmeta

    supershipiteers_byfile = {}
    supershipiteers_byuser = {}
    for cm in meta.get('component_matches', []):
        _ss = cm.get(u'supershipit', [])
        supershipiteers_byfile[cm[u'repo_filename']] = _ss[:]
        for ss in _ss:
            if ss not in supershipiteers_byuser:
                supershipiteers_byuser[ss] = []
            supershipiteers_byuser[ss].append(cm[u'repo_filename'])

    maintainers = meta.get(u'component_maintainers', [])
    maintainers = \
        ModuleIndexer.replace_ansible(
            maintainers,
            core_team,
            bots=botnames
        )

    # community is the other maintainers in the same namespace
    community = meta.get(u'component_namespace_maintainers', [])
    community = [x for x in community if x != u'ansible' and
                 x not in core_team and
                 x != u'DEPRECATED']

    # shipit tallies
    ansible_shipits = 0
    maintainer_shipits = 0
    community_shipits = 0
    other_shipits = 0
    shipit_actors = []
    shipit_actors_other = []
    supershipiteers_voted = set()
    rebuild_merge = False

    for event in iw.history.history:

        if event[u'event'] not in [u'commented', u'committed', u'review_approved', u'review_comment']:
            continue
        if event[u'actor'] in botnames:
            continue

        # commits reset the counters
        if event[u'event'] == u'committed':
            logging.info(event)
            ansible_shipits = 0
            maintainer_shipits = 0
            community_shipits = 0
            other_shipits = 0
            shipit_actors = []
            shipit_actors_other = []
            supershipiteers_voted = set()
            rebuild_merge = False
            logging.info('commit detected, resetting shipit tallies')
            continue

        actor = event[u'actor']
        body = event.get(u'body', u'')
        body = body.strip()

        if not is_approval(body):
            continue

        if actor in core_team and is_rebuild_merge(body):
            rebuild_merge = True
            logging.info(u'%s shipit [rebuild_merge]' % actor)
        else:
            logging.info(u'%s shipit' % actor)

        # super shipits
        if actor in supershipiteers_byuser:
            supershipiteers_voted.add(actor)

        # ansible shipits
        if actor in core_team:
            if actor not in shipit_actors:
                ansible_shipits += 1
                shipit_actors.append(actor)
            continue

        # maintainer shipits
        if actor in maintainers:
            if actor not in shipit_actors:
                maintainer_shipits += 1
                shipit_actors.append(actor)
            continue

        # community shipits
        if actor in community:
            if actor not in shipit_actors:
                community_shipits += 1
                shipit_actors.append(actor)
            continue

        # other shipits
        if actor not in shipit_actors_other:
            other_shipits += 1
            shipit_actors_other.append(actor)

        continue

    # submitters should count if they are core team/maintainers/community
    if iw.submitter in core_team:
        if iw.submitter not in shipit_actors:
            ansible_shipits += 1
            shipit_actors.append(iw.submitter)
    elif iw.submitter in maintainers:
        if iw.submitter not in shipit_actors:
            maintainer_shipits += 1
            shipit_actors.append(iw.submitter)
    elif iw.submitter in community:
        if iw.submitter not in shipit_actors:
            community_shipits += 1
            shipit_actors.append(iw.submitter)

    nmeta[u'shipit_count_other'] = other_shipits
    nmeta[u'shipit_count_community'] = community_shipits
    nmeta[u'shipit_count_maintainer'] = maintainer_shipits
    nmeta[u'shipit_count_ansible'] = ansible_shipits
    nmeta[u'shipit_actors'] = shipit_actors
    nmeta[u'shipit_actors_other'] = shipit_actors_other
    nmeta[u'community_usernames'] = sorted(community)

    total = community_shipits + maintainer_shipits + ansible_shipits
    nmeta[u'shipit_count_vtotal'] = total + other_shipits

    if rebuild_merge:
        nmeta['is_rebuild_merge'] = True

    # include shipits from other people to push over the edge
    if total == 1 and other_shipits > 2:
        total += other_shipits

    if total > 1 or rebuild_merge:
        nmeta[u'shipit'] = True
    elif meta[u'is_new_module'] or \
            (len(maintainers) == 1 and maintainer_shipits == 1):
        # don't notify if there is no maintainer or if submitter is the only namespace maintainer
        if set(community) - {iw.submitter}:
            bpc = iw.history.get_boilerplate_comments()
            bpc = [x[0] for x in bpc]
            if u'community_shipit_notify' not in bpc:
                nmeta[u'notify_community_shipit'] = True

    logging.info(u'total shipits: %s' % total)

    # supershipit ...
    #   if a supershipiteer for each file exists and has blessed the PR
    #   on the current commit, then override all shipit tallies and get this PR merged
    if supershipiteers_voted:
        nmeta[u'supershipit_actors'] = list(supershipiteers_voted)
        cm_files = [x[u'repo_filename'] for x in meta[u'component_matches']]
        ss_files = set()
        for ssv in supershipiteers_voted:
            for fn in supershipiteers_byuser[ssv]:
                ss_files.add(fn)

        if sorted(set(cm_files)) == sorted(set(ss_files)):
            logging.info(u'supershipit enabled on %s' % iw.html_url)
            nmeta[u'supershipit'] = True
            nmeta[u'shipit'] = True
        else:
            for cm_file in sorted(cm_files):
                if cm_file not in ss_files:
                    logging.info('%s is not governed by supershipit' % cm_file)

    return nmeta
예제 #4
0
def get_shipit_facts(issuewrapper,
                     meta,
                     module_indexer,
                     core_team=[],
                     botnames=[]):
    # shipit/+1/LGTM in comment.body from maintainer

    # AUTOMERGE
    # * New module, existing namespace: require a "shipit" from some
    #   other maintainer in the namespace. (Ideally, identify a maintainer
    #   for the entire namespace.)
    # * New module, new namespace: require discussion with the creator
    #   of the namespace, which will likely be a vendor.
    # * And all new modules, of course, go in as "preview" mode.

    iw = issuewrapper
    nmeta = {
        'shipit': False,
        'owner_pr': False,
        'shipit_ansible': False,
        'shipit_community': False,
        'shipit_count_community': False,
        'shipit_count_maintainer': False,
        'shipit_count_ansible': False,
        'shipit_actors': None,
        'community_usernames': [],
        'notify_community_shipit': False,
    }

    if not iw.is_pullrequest():
        return nmeta
    if not meta['module_match']:
        return nmeta

    maintainers = meta['module_match']['maintainers']
    maintainers = \
        ModuleIndexer.replace_ansible(
            maintainers,
            core_team,
            bots=botnames
        )

    if not meta['is_new_module'] and iw.submitter in maintainers:
        nmeta['owner_pr'] = True

    # community is the other maintainers in the same namespace
    mnamespace = meta['module_match']['namespace']
    community = \
        module_indexer.get_maintainers_for_namespace(mnamespace)
    community = [
        x for x in community
        if x != 'ansible' and x not in core_team and x != 'DEPRECATED'
    ]

    # shipit tallies
    ansible_shipits = 0
    maintainer_shipits = 0
    community_shipits = 0
    shipit_actors = []

    for event in iw.history.history:

        if event['event'] not in ['commented', 'committed']:
            continue
        if event['actor'] in botnames:
            continue

        # commits reset the counters
        if event['event'] == 'committed':
            ansible_shipits = 0
            maintainer_shipits = 0
            community_shipits = 0
            shipit_actors = []
            continue

        actor = event['actor']
        body = event['body']

        # ansible shipits
        if actor in core_team:
            if 'shipit' in body or '+1' in body or 'LGTM' in body:
                logging.info('%s shipit' % actor)
                if actor not in shipit_actors:
                    ansible_shipits += 1
                    shipit_actors.append(actor)
                continue

        # maintainer shipits
        if actor in maintainers:
            if 'shipit' in body or '+1' in body or 'LGTM' in body:
                logging.info('%s shipit' % actor)
                if actor not in shipit_actors:
                    maintainer_shipits += 1
                    shipit_actors.append(actor)
                continue

        # community shipits
        if actor in community:
            if 'shipit' in body or '+1' in body or 'LGTM' in body:
                logging.info('%s shipit' % actor)
                if actor not in shipit_actors:
                    community_shipits += 1
                    shipit_actors.append(actor)
                continue

    # submitters should count if they are maintainers/community
    if iw.submitter in maintainers:
        if iw.submitter not in shipit_actors:
            maintainer_shipits += 1
            shipit_actors.append(iw.submitter)
    elif iw.submitter in community:
        if iw.submitter not in shipit_actors:
            community_shipits += 1
            shipit_actors.append(iw.submitter)

    nmeta['shipit_count_community'] = community_shipits
    nmeta['shipit_count_maintainer'] = maintainer_shipits
    nmeta['shipit_count_ansible'] = ansible_shipits
    nmeta['shipit_actors'] = shipit_actors
    nmeta['community_usernames'] = sorted(community)

    if (community_shipits + maintainer_shipits + ansible_shipits) > 1:
        nmeta['shipit'] = True
    elif meta['is_new_module'] or \
            (len(maintainers) == 1 and maintainer_shipits == 1):
        if community:
            bpc = iw.history.get_boilerplate_comments()
            if 'community_shipit_notify' not in bpc:
                nmeta['notify_community_shipit'] = True

    logging.info('total shipits: %s' %
                 (community_shipits + maintainer_shipits + ansible_shipits))

    return nmeta
예제 #5
0
def get_shipit_facts(issuewrapper, meta, module_indexer, core_team=[], botnames=[]):
    """ Count shipits by maintainers/community/other """

    # maintainers - people who maintain this file/module
    # community - people who maintain file(s) in the same directory
    # other - anyone else who comments with shipit/+1/LGTM

    iw = issuewrapper
    nmeta = {
        u'shipit': False,
        u'owner_pr': False,
        u'shipit_ansible': False,
        u'shipit_community': False,
        u'shipit_count_other': False,
        u'shipit_count_community': False,
        u'shipit_count_maintainer': False,
        u'shipit_count_ansible': False,
        u'shipit_count_vtotal': False,
        u'shipit_actors': None,
        u'community_usernames': [],
        u'notify_community_shipit': False,
    }

    if not iw.is_pullrequest():
        return nmeta

    module_utils_files_owned = 0  # module_utils files for which submitter is maintainer
    if meta[u'is_module_util']:
        for f in iw.files:
            if f.startswith(u'lib/ansible/module_utils') and f in module_indexer.botmeta[u'files']:
                maintainers = module_indexer.botmeta[u'files'][f].get(u'maintainers', [])
                if maintainers and (iw.submitter in maintainers):
                    module_utils_files_owned += 1

    modules_files_owned = 0
    if not meta[u'is_new_module']:
        for f in iw.files:
            if f.startswith(u'lib/ansible/modules') and iw.submitter in meta[u'component_maintainers']:
                modules_files_owned += 1
    nmeta[u'owner_pr'] = modules_files_owned + module_utils_files_owned == len(iw.files)

    #if not meta['module_match']:
    #    return nmeta

    # https://github.com/ansible/ansibullbot/issues/722
    if iw.wip:
        logging.debug(u'WIP PRs do not get shipits')
        return nmeta

    if meta[u'is_needs_revision'] or meta[u'is_needs_rebase']:
        logging.debug(u'PRs with needs_revision or needs_rebase label do not get shipits')
        return nmeta

    maintainers = meta.get(u'component_maintainers', [])
    maintainers = \
        ModuleIndexer.replace_ansible(
            maintainers,
            core_team,
            bots=botnames
        )

    # community is the other maintainers in the same namespace
    community = meta.get(u'component_namespace_maintainers', [])
    community = [x for x in community if x != u'ansible' and
                 x not in core_team and
                 x != u'DEPRECATED']

    # shipit tallies
    ansible_shipits = 0
    maintainer_shipits = 0
    community_shipits = 0
    other_shipits = 0
    shipit_actors = []
    shipit_actors_other = []

    for event in iw.history.history:

        if event[u'event'] not in [u'commented', u'committed', u'review_approved', u'review_comment']:
            continue
        if event[u'actor'] in botnames:
            continue

        # commits reset the counters
        if event[u'event'] == u'committed':
            ansible_shipits = 0
            maintainer_shipits = 0
            community_shipits = 0
            other_shipits = 0
            shipit_actors = []
            shipit_actors_other = []
            continue

        actor = event[u'actor']
        body = event.get(u'body', u'')
        body = body.strip()
        if not is_approval(body):
            continue
        logging.info(u'%s shipit' % actor)

        # ansible shipits
        if actor in core_team:
            if actor not in shipit_actors:
                ansible_shipits += 1
                shipit_actors.append(actor)
            continue

        # maintainer shipits
        if actor in maintainers:
            if actor not in shipit_actors:
                maintainer_shipits += 1
                shipit_actors.append(actor)
            continue

        # community shipits
        if actor in community:
            if actor not in shipit_actors:
                community_shipits += 1
                shipit_actors.append(actor)
            continue

        # other shipits
        if actor not in shipit_actors_other:
            other_shipits += 1
            shipit_actors_other.append(actor)
        continue

    # submitters should count if they are core team/maintainers/community
    if iw.submitter in core_team:
        if iw.submitter not in shipit_actors:
            ansible_shipits += 1
            shipit_actors.append(iw.submitter)
    elif iw.submitter in maintainers:
        if iw.submitter not in shipit_actors:
            maintainer_shipits += 1
            shipit_actors.append(iw.submitter)
    elif iw.submitter in community:
        if iw.submitter not in shipit_actors:
            community_shipits += 1
            shipit_actors.append(iw.submitter)

    nmeta[u'shipit_count_other'] = other_shipits
    nmeta[u'shipit_count_community'] = community_shipits
    nmeta[u'shipit_count_maintainer'] = maintainer_shipits
    nmeta[u'shipit_count_ansible'] = ansible_shipits
    nmeta[u'shipit_actors'] = shipit_actors
    nmeta[u'shipit_actors_other'] = shipit_actors_other
    nmeta[u'community_usernames'] = sorted(community)

    total = community_shipits + maintainer_shipits + ansible_shipits
    nmeta[u'shipit_count_vtotal'] = total + other_shipits

    # include shipits from other people to push over the edge
    if total == 1 and other_shipits > 2:
        total += other_shipits

    if total > 1:
        nmeta[u'shipit'] = True
    elif meta[u'is_new_module'] or \
            (len(maintainers) == 1 and maintainer_shipits == 1):
        # don't notify if there is no maintainer or if submitter is the only namespace maintainer
        if set(community) - {iw.submitter}:
            bpc = iw.history.get_boilerplate_comments()
            bpc = [x[0] for x in bpc]
            if u'community_shipit_notify' not in bpc:
                nmeta[u'notify_community_shipit'] = True

    logging.info(u'total shipits: %s' % total)

    return nmeta
예제 #6
0
파일: shipit.py 프로젝트: b3rn/ansibullbot
def get_shipit_facts(issuewrapper, meta, module_indexer, core_team=[], botnames=[]):
    """ Count shipits by maintainers/community/other """

    # maintainers - people who maintain this file/module
    # community - people who maintain file(s) in the same directory
    # other - anyone else who comments with shipit/+1/LGTM

    iw = issuewrapper
    nmeta = {
        'shipit': False,
        'owner_pr': False,
        'shipit_ansible': False,
        'shipit_community': False,
        'shipit_count_other': False,
        'shipit_count_community': False,
        'shipit_count_maintainer': False,
        'shipit_count_ansible': False,
        'shipit_actors': None,
        'community_usernames': [],
        'notify_community_shipit': False,
    }

    if not iw.is_pullrequest():
        return nmeta
    if not meta['module_match']:
        return nmeta

    maintainers = meta['module_match']['maintainers']
    maintainers = \
        ModuleIndexer.replace_ansible(
            maintainers,
            core_team,
            bots=botnames
        )

    if not meta['is_new_module'] and iw.submitter in maintainers:
        nmeta['owner_pr'] = True

    # community is the other maintainers in the same namespace
    mnamespace = meta['module_match']['namespace']
    community = \
        module_indexer.get_maintainers_for_namespace(mnamespace)
    community = [x for x in community if x != 'ansible' and
                 x not in core_team and
                 x != 'DEPRECATED']

    # shipit tallies
    ansible_shipits = 0
    maintainer_shipits = 0
    community_shipits = 0
    other_shipits = 0
    shipit_actors = []
    shipit_actors_other = []

    for event in iw.history.history:

        if event['event'] not in ['commented', 'committed']:
            continue
        if event['actor'] in botnames:
            continue

        # commits reset the counters
        if event['event'] == 'committed':
            ansible_shipits = 0
            maintainer_shipits = 0
            community_shipits = 0
            other_shipits = 0
            shipit_actors = []
            shipit_actors_other = []
            continue

        actor = event['actor']
        body = event['body']
        body = body.strip()
        if 'shipit' not in body and '+1' not in body and 'LGTM' not in body:
            continue
        logging.info('%s shipit' % actor)

        # ansible shipits
        if actor in core_team:
            if actor not in shipit_actors:
                ansible_shipits += 1
                shipit_actors.append(actor)
            continue

        # maintainer shipits
        if actor in maintainers:
            if actor not in shipit_actors:
                maintainer_shipits += 1
                shipit_actors.append(actor)
            continue

        # community shipits
        if actor in community:
            if actor not in shipit_actors:
                community_shipits += 1
                shipit_actors.append(actor)
            continue

        # other shipits
        if actor not in shipit_actors_other:
            other_shipits += 1
            shipit_actors_other.append(actor)
        continue

    # submitters should count if they are maintainers/community
    if iw.submitter in maintainers:
        if iw.submitter not in shipit_actors:
            maintainer_shipits += 1
            shipit_actors.append(iw.submitter)
    elif iw.submitter in community:
        if iw.submitter not in shipit_actors:
            community_shipits += 1
            shipit_actors.append(iw.submitter)

    nmeta['shipit_count_other'] = other_shipits
    nmeta['shipit_count_community'] = community_shipits
    nmeta['shipit_count_maintainer'] = maintainer_shipits
    nmeta['shipit_count_ansible'] = ansible_shipits
    nmeta['shipit_actors'] = shipit_actors
    nmeta['shipit_actors_other'] = shipit_actors_other
    nmeta['community_usernames'] = sorted(community)

    total = community_shipits + maintainer_shipits + ansible_shipits

    # include shipits from other people to push over the edge
    if total == 1 and other_shipits > 2:
        total += other_shipits

    if total > 1:
        nmeta['shipit'] = True
    elif meta['is_new_module'] or \
            (len(maintainers) == 1 and maintainer_shipits == 1):
        if community:
            bpc = iw.history.get_boilerplate_comments()
            if 'community_shipit_notify' not in bpc:
                nmeta['notify_community_shipit'] = True

    logging.info('total shipits: %s' % total)

    return nmeta