• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / relman-auto-nag / #4987

03 May 2024 06:37PM CUT coverage: 21.89% (+0.02%) from 21.872%
#4987

push

coveralls-python

suhaibmujahid
Satisfy the type linting in for the People class

716 of 3592 branches covered (19.93%)

1930 of 8817 relevant lines covered (21.89%)

0.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/bugbot/team_managers.py
1
# This Source Code Form is subject to the terms of the Mozilla Public
2
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
3
# You can obtain one at http://mozilla.org/MPL/2.0/.
4

5
import json
×
6
from collections import defaultdict
×
7
from typing import Dict, Optional
×
8

9
from libmozdata.bugzilla import BugzillaUser
×
10

11
from bugbot.components import ComponentName, fetch_component_teams
×
12
from bugbot.people import People
×
13

14
DEFAULT_PATH = "./configs/team_managers.json"
×
15

16

17
class TeamManagers:
×
18
    def __init__(
×
19
        self,
20
        mappers_path: str = DEFAULT_PATH,
21
        people: People = People.get_instance(),
22
    ):
23
        """Constructor
24

25
        Args:
26
            mappers_path: path to the team managers mappings file.
27
            people: instance of the People class to get information about employees.
28
        """
29
        self._component_teams: Dict[ComponentName, str] = {}
×
30
        self.people = people
×
31
        self._load_team_managers(mappers_path)
×
32

33
    def _load_team_managers(self, filepath: str) -> None:
×
34
        with open(filepath) as file:
×
35
            self.managers = {
×
36
                team: {
37
                    "name": manager,
38
                    "mozilla_email": self.people.get_mozmail_from_name(manager),
39
                }
40
                for team, manager in json.load(file).items()
41
            }
42

43
    def get_team_manager(
×
44
        self, team_name: str, fallback: bool = True
45
    ) -> Optional[Dict[str, dict]]:
46
        """Get the manager of the provided team.
47

48
        Args:
49
            team_name: the name of the team.
50
            fallback: if True, will return the fallback manager when cannot find
51
                the team manager; if False, will return None.
52

53
        Returns:
54
            Info for the team manager.
55
        """
56

57
        if team_name not in self.managers:
×
58
            if fallback:
×
59
                return self.managers["fallback"]
×
60
            else:
61
                return None
×
62

63
        return self.managers[team_name]
×
64

65
    def _fetch_managers_nicknames(self) -> None:
×
66
        bz_emails_map = defaultdict(list)
×
67
        for manager in self.managers.values():
×
68
            moz_mail = manager["mozilla_email"]
×
69
            if not moz_mail:
×
70
                continue
×
71

72
            info = self.people.get_info(moz_mail)
×
73
            bz_mail = info["bugzillaEmail"]
×
74
            if not bz_mail:
×
75
                bz_mail = moz_mail
×
76

77
            # Some manager could manage multiple teams, we need to update all of
78
            # them.
79
            bz_emails_map[bz_mail].append(manager)
×
80

81
        def handler(user, data):
×
82
            for manager in data[user["email"]]:
×
83
                manager["nick"] = user["nick"]
×
84
                manager["bz_email"] = user["email"]
×
85

86
        BugzillaUser(
×
87
            list(bz_emails_map.keys()),
88
            include_fields=["email", "nick"],
89
            user_handler=handler,
90
            user_data=bz_emails_map,
91
        ).wait()
92

93
    def get_component_manager(
×
94
        self, product: str, component: str, fallback: bool = True
95
    ) -> Optional[Dict[str, dict]]:
96
        """Get the manager of the team who owns the provided component.
97

98
        Args:
99
            product: the name of the product.
100
            component: the name of the component.
101
            fallback: if True, will return the fallback manager when cannot find
102
                the component manager; if False, will return None.
103

104
        Returns:
105
            Info for the manager of team who owns the component.
106
        """
107
        if not self._component_teams:
×
108
            self._component_teams = fetch_component_teams()
×
109
            self._fetch_managers_nicknames()
×
110

111
        team_name = self._component_teams[ComponentName(product, component)]
×
112
        return self.get_team_manager(team_name, fallback=fallback)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc