def set_autofix(self, bugs):
        def history_handler(bug, data):
            bugid = str(bug["id"])
            deps = data[bugid]["deps"]
            stats = {}
            for h in bug["history"]:
                for change in h["changes"]:
                    if (change["field_name"] in {"blocks", "depends_on"}
                            and change["added"] in deps
                        ) or change["field_name"] == "cf_has_regression_range":
                        who = h["who"]
                        stats[who] = stats.get(who, 0) + 1

            data[bugid]["winner"] = (max(stats.items(), key=lambda p: p[1])[0]
                                     if stats else None)

        no_assignee = [
            bugid for bugid, info in bugs.items() if not info["assignee"]
        ]
        Bugzilla(bugids=no_assignee,
                 historyhandler=history_handler,
                 historydata=bugs).get_data().wait()

        no_nick = {}
        for bugid, info in bugs.items():
            if info["assignee"]:
                winner = {
                    "mail": info["assignee"]["email"],
                    "nickname": info["assignee"]["nick"],
                }
                self.add_auto_ni(bugid, winner)
            elif info["winner"]:
                winner = info["winner"]
                if winner not in no_nick:
                    no_nick[winner] = []
                no_nick[winner].append(bugid)
            else:
                winner = {
                    "mail": info["creator"]["email"],
                    "nickname": info["creator"]["nick"],
                }
                self.add_auto_ni(bugid, winner)

        if no_nick:

            def user_handler(user, data):
                data[user["name"]] = user["nick"]

            data = {}
            BugzillaUser(
                user_names=list(no_nick.keys()),
                include_fields=["name", "nick"],
                user_handler=user_handler,
                user_data=data,
            ).wait()

            for bzmail, bugids in no_nick.items():
                nick = data[bzmail]
                for bugid in bugids:
                    self.add_auto_ni(bugid, {"mail": bzmail, "nickname": nick})
Exemplo n.º 2
0
def get_nick(authors):
    bz = {}

    def user_handler(u):
        real = u['real_name']
        m = NICK_PAT.search(real)
        nick = m.group(1) if m else ''
        name = u['name']
        bz[name] = {'name': name,
                    'real_name': real,
                    'nick_name': nick}

    authors = list(authors)
    queries = []
    for chunk in Connection.chunks(authors, 20):
        query = BugzillaUser(user_names=chunk,
                             include_fields=['name', 'real_name'],
                             user_handler=user_handler)
        queries.append(query)

    for q in queries:
        q.wait()

    authors = [bz[a] for a in authors if a in bz]
    return authors
    def set_autofix(self, bugs):
        def history_handler(bug, data):
            bugid = str(bug['id'])
            deps = data[bugid]['deps']
            stats = {}
            for h in bug['history']:
                for change in h['changes']:
                    if (
                        change['field_name'] in {'blocks', 'depends_on'}
                        and change['added'] in deps
                    ):
                        who = h['who']
                        stats[who] = stats.get(who, 0) + 1

            data[bugid]['winner'] = (
                max(stats.items(), key=lambda p: p[1])[0] if stats else None
            )

        no_assignee = [bugid for bugid, info in bugs.items() if not info['assignee']]
        Bugzilla(
            bugids=no_assignee, historyhandler=history_handler, historydata=bugs
        ).get_data().wait()

        no_nick = {}
        for bugid, info in bugs.items():
            if info['assignee']:
                winner = {
                    'mail': info['assignee']['email'],
                    'nickname': info['assignee']['nick'],
                }
                self.add_auto_ni(bugid, winner)
            elif info['winner']:
                winner = info['winner']
                if winner not in no_nick:
                    no_nick[winner] = []
                no_nick[winner].append(bugid)
            else:
                winner = {
                    'mail': info['creator']['email'],
                    'nickname': info['creator']['nick'],
                }
                self.add_auto_ni(bugid, winner)

        if no_nick:

            def user_handler(user, data):
                data[user['name']] = user['nick']

            data = {}
            BugzillaUser(
                user_names=list(no_nick.keys()),
                include_fields=['name', 'nick'],
                user_handler=user_handler,
                user_data=data,
            ).wait()

            for bzmail, bugids in no_nick.items():
                nick = data[bzmail]
                for bugid in bugids:
                    self.add_auto_ni(bugid, {'mail': bzmail, 'nickname': nick})
Exemplo n.º 4
0
    def get_nick(self, bzmail):
        if bzmail not in self.nicks:

            def handler(user):
                self.nicks[bzmail] = user['nick']

            BugzillaUser(user_names=[bzmail], user_handler=handler).wait()

        return self.nicks[bzmail]
Exemplo n.º 5
0
    def get_nick(self, bzmail, prod_comp, cal):
        if bzmail not in self.nicks:

            def handler(user):
                self.nicks[bzmail] = user["nick"]

            BugzillaUser(user_names=[bzmail], user_handler=handler).wait()

        if bzmail not in self.nicks:
            self.add_erroneous_bzmail(bzmail, prod_comp, cal)
            return None

        return self.nicks[bzmail]
Exemplo n.º 6
0
def load_users(analysis):
    '''
    Load users linked through roles to an analysis
    '''
    assert analysis is not None, \
        'Missing bug analysis'

    roles = {}

    def _extract_user(user_data, role):
        # Support multiple input structures
        if user_data is None:
            return
        elif isinstance(user_data, dict):
            if 'id' in user_data:
                key = user_data['id']
            elif 'email' in user_data:
                key = user_data['email']
            else:
                raise Exception('Invalid user data : no id or email')

        elif isinstance(user_data, str):
            key = user_data
        else:
            raise Exception('Invalid user data : unsupported format')

        if key not in roles:
            roles[key] = []
        roles[key].append(role)

    # Extract users keys & roles
    _extract_user(analysis['users'].get('creator'), 'creator')
    _extract_user(analysis['users'].get('assignee'), 'assignee')
    for r in analysis['users']['reviewers']:
        _extract_user(r, 'reviewer')
    _extract_user(analysis['uplift_author'], 'uplift_author')

    def _handler(user, data):
        # Store users with their roles
        user['roles'] = roles.get(user['id'], roles.get(user['email'], []))
        data.append(user)

    # Finally fetch clean users data through Bugzilla
    out = []
    BugzillaUser(user_names=roles.keys(), user_handler=_handler,
                 user_data=out).wait()
    return out
Exemplo n.º 7
0
    def get_nicks(self, nicknames):
        def handler(user, data):
            data[user['name']] = user['nick']

        users = set(nicknames.values())
        data = {}
        if users:
            BugzillaUser(
                user_names=list(users),
                include_fields=['name', 'nick'],
                user_handler=handler,
                user_data=data,
            ).wait()

        for bugid, name in nicknames.items():
            nicknames[bugid] = (name, data[name])

        return nicknames
Exemplo n.º 8
0
    def get_user_info(self, bzdata):
        """Get the user info from Bugzilla to have his real name."""

        def handler(user, data):
            data[user["name"]] = user["real_name"]

        users = set()
        for info in bzdata.values():
            users |= info["creators"]
            users |= set(info["commenters"].keys())

        data = {}

        if users:
            BugzillaUser(
                user_names=list(users), user_handler=handler, user_data=data
            ).wait()

        return data
Exemplo n.º 9
0
    def get_bz_userid(self, phids):
        if not phids:
            return {}

        try:
            data = self.phab.load_bz_account(user_phids=list(phids))
            users = {x["phid"]: x["id"] for x in data}
        except PhabricatorBzNotFoundException:
            return {}

        def handler(user, data):
            data[str(user["id"])] = user["name"]

        data = {}
        BugzillaUser(
            user_names=list(users.values()),
            include_fields=["id", "name"],
            user_handler=handler,
            user_data=data,
        ).wait()

        return {phid: data[id] for phid, id in users.items()}