Skip to content

Commit

Permalink
[inactive_ni_pending] Consider new Bugzilla users to be inactive/abse…
Browse files Browse the repository at this point in the history
…nt in a shorter period of time (#2457)

Fixes #1580
  • Loading branch information
benjaminmah authored Aug 22, 2024
1 parent 79ec02e commit 0aed4e7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
5 changes: 3 additions & 2 deletions bugbot/rules/inactive_ni_pending.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def handle_inactive_requestee(self, bugs):

requestee_bugs[flag["requestee"]].append(bugid)

user_activity = UserActivity(include_fields=["groups"])
user_activity = UserActivity(include_fields=["groups", "creation_time"])
needinfo_requestees = set(requestee_bugs.keys())
triage_owners = {bug["triage_owner"] for bug in bugs.values()}
inactive_users = user_activity.check_users(
Expand All @@ -101,7 +101,8 @@ def get_inactive_ni(bug):
"setter": flag["setter"],
"requestee": flag["requestee"],
"requestee_status": user_activity.get_string_status(
inactive_users[flag["requestee"]]["status"]
inactive_users[flag["requestee"]]["status"],
inactive_users[flag["requestee"]]["creation_time"],
),
"requestee_canconfirm": has_canconfirm_group(flag["requestee"]),
}
Expand Down
37 changes: 33 additions & 4 deletions bugbot/user_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(
self,
activity_weeks_count: int = 26,
absent_weeks_count: int = 26,
new_user_weeks_count: int = 4,
unavailable_max_days: int = 7,
include_fields: list | None = None,
phab: PhabricatorAPI | None = None,
Expand All @@ -50,6 +51,8 @@ def __init__(
to a bug before a user being considered as inactive.
absent_weeks_count: the number of weeks since last loaded any page
from Bugzilla before a user being considered as inactive.
new_user_weeks_count: the number of weeks since last made a change
to a bug before a new user being considered as inactive.
unavailable_max_days: a user will be considered inactive if they
have more days left to be available than `unavailable_max_days`.
include_fields: the list of fields to include with the the Bugzilla
Expand All @@ -64,6 +67,7 @@ def __init__(
"""
self.activity_weeks_count = activity_weeks_count
self.absent_weeks_count = absent_weeks_count
self.new_user_weeks_count = new_user_weeks_count
self.include_fields = include_fields or []
self.people = people if people is not None else People.get_instance()
self.phab = phab
Expand All @@ -77,6 +81,19 @@ def __init__(
self.activity_limit_ts = lmdutils.get_date_ymd(self.activity_limit).timestamp()
self.seen_limit = lmdutils.get_date(reference_date, self.absent_weeks_count * 7)

self.new_user_activity_limit = lmdutils.get_date(
reference_date, self.new_user_weeks_count * 7
)
self.new_user_activity_limit_ts = lmdutils.get_date_ymd(
self.new_user_activity_limit
).timestamp()
self.new_user_seen_limit = lmdutils.get_date(
reference_date, self.new_user_weeks_count * 7
)

# Bugzilla accounts younger than 61 days are considered new users
self.new_user_limit = lmdutils.get_date(reference_date, 61)

def _get_phab(self):
if not self.phab:
self.phab = PhabricatorAPI(utils.get_login_info()["phab_api_key"])
Expand Down Expand Up @@ -157,19 +174,25 @@ def check_users(

def get_status_from_bz_user(self, user: dict) -> UserStatus:
"""Get the user status from a Bugzilla user object."""
is_new_user = user["creation_time"] > self.new_user_limit

seen_limit = self.seen_limit if not is_new_user else self.new_user_seen_limit
activity_limit = (
self.activity_limit if not is_new_user else self.new_user_activity_limit
)

if not user["can_login"]:
return UserStatus.DISABLED

if user["creation_time"] > self.seen_limit:
if user["creation_time"] > seen_limit:
return UserStatus.ACTIVE

if user["last_seen_date"] is None or user["last_seen_date"] < self.seen_limit:
if user["last_seen_date"] is None or user["last_seen_date"] < seen_limit:
return UserStatus.ABSENT

if (
user["last_activity_time"] is None
or user["last_activity_time"] < self.activity_limit
or user["last_activity_time"] < activity_limit
):
return UserStatus.INACTIVE

Expand Down Expand Up @@ -307,16 +330,22 @@ def is_active_on_phab(self, user_phid: str) -> bool:

return False

def get_string_status(self, status: UserStatus):
def get_string_status(self, status: UserStatus, user_creation_time: str):
"""Get a string representation of the user status."""

is_new_user = user_creation_time > self.new_user_limit

if status == UserStatus.UNDEFINED:
return "Not specified"
if status == UserStatus.DISABLED:
return "Account disabled"
if status == UserStatus.INACTIVE:
if is_new_user:
return f"Inactive on Bugzilla in last {self.new_user_weeks_count} weeks (new user)"
return f"Inactive on Bugzilla in last {self.activity_weeks_count} weeks"
if status == UserStatus.ABSENT:
if is_new_user:
return f"Not seen on Bugzilla in last {self.new_user_weeks_count} weeks (new user)"
return f"Not seen on Bugzilla in last {self.absent_weeks_count} weeks"

return status.name
Expand Down

0 comments on commit 0aed4e7

Please sign in to comment.