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 all 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
39 changes: 10 additions & 29 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,33 +311,33 @@ 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]
self.extra_ni[bugid] = data["count"]
assignee = d["assigned_to"]
nickname = d["nickname"]

if not assignee:
assignee, nickname = nicknames[bugid]
user_details = bz_reviewers[assignee]
assignee = user_details["id"]
nickname = user_details["nick"]

if not assignee:
continue

self.add_auto_ni(bugid, {"mail": assignee, "nickname": nickname})

common = all_reviewers & data["reviewers_phid"]
Copy link
Member

Choose a reason for hiding this comment

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

Isn't all_reviewers a set?

common = all_reviewers["name"] & data["reviewers_phid"]
if common:
reviewer = random.choice(list(common))
self.add_auto_ni(
Expand Down