Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated not_landed to get user nicks in 1 call and removed the duplicate - Closes #1101 #2365

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 13 additions & 28 deletions bugbot/rules/not_landed.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def attachment_handler(attachments, data):

return data

def get_bz_userid(self, phids):
def get_bz_users(self, phids):
if not phids:
return {}

Expand All @@ -263,37 +263,18 @@ def get_bz_userid(self, phids):
return {}

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

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

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

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

def get_bz_params(self, date):
self.date = lmdutils.get_date_ymd(date)
fields = ["flags", "depends_on"]
Expand Down Expand Up @@ -330,17 +311,16 @@ def get_bugs(self, date="today", bug_ids=[]):
res = {}

reviewers_phid = set()
nicknames = {}
bug_assignee_map = {}
for bugid, data in bugs_patch.items():
reviewers_phid |= data["reviewers_phid"]
assignee = bugs[bugid]["assigned_to"]
if not assignee:
assignee = max(data["author"], key=data["author"].get)
nicknames[bugid] = assignee
bug_assignee_map[bugid] = assignee
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug_assignee_map dict does not seem to be used anywhere. Do we need it after the changes in this PR?


bz_reviewers = self.get_bz_userid(reviewers_phid)
bz_reviewers = self.get_bz_users(reviewers_phid)
all_reviewers = set(bz_reviewers.keys())
nicknames = self.get_nicks(nicknames)
Jubintgh marked this conversation as resolved.
Show resolved Hide resolved

for bugid, data in bugs_patch.items():
res[bugid] = d = bugs[bugid]
Expand All @@ -349,7 +329,8 @@ def get_bugs(self, date="today", bug_ids=[]):
nickname = d["nickname"]

if not assignee:
assignee, nickname = nicknames[bugid]
assignee_id = bug_assignee_map[bugid]
assignee, nickname = bz_reviewers[assignee_id]
Jubintgh marked this conversation as resolved.
Show resolved Hide resolved

if not assignee:
continue
Expand All @@ -360,7 +341,11 @@ def get_bugs(self, date="today", bug_ids=[]):
if common:
reviewer = random.choice(list(common))
self.add_auto_ni(
bugid, {"mail": bz_reviewers[reviewer], "nickname": None}
bugid,
{
"mail": bz_reviewers[reviewer][0],
"nickname": bz_reviewers[reviewer][1],
},
)

return res
Expand Down