33# You can obtain one at http://mozilla.org/MPL/2.0/.
44
55import collections
6+ from datetime import datetime , timedelta
67
78from libmozdata import utils as lmdutils
89
@@ -23,6 +24,7 @@ def __init__(self):
2324 self .people = people .People .get_instance ()
2425 self .unassign_count = collections .defaultdict (int )
2526 self .no_bugmail = True
27+ self .one_year_ago = datetime .now () - timedelta (days = 365 )
2628
2729 self .extra_ni = {}
2830
@@ -104,9 +106,13 @@ def add_action(self, bug):
104106 # It's not paramount for triage owners to make an explicit decision here, it's enough for them
105107 # to receive the notification about the unassignment from Bugzilla via email.
106108 if (
107- bug ["priority" ] not in HIGH_PRIORITY
108- and bug ["severity" ] not in HIGH_SEVERITY
109- ) or "stalled" in bug ["keywords" ]:
109+ (
110+ bug ["priority" ] not in HIGH_PRIORITY
111+ and bug ["severity" ] not in HIGH_SEVERITY
112+ )
113+ or "stalled" in bug ["keywords" ]
114+ or (bug ["is_old_priority" ] and bug ["priority" ] in HIGH_PRIORITY )
115+ ):
110116 needinfo = None
111117 autofix ["comment" ] = {
112118 "body" : "The bug assignee is inactive on Bugzilla, so the assignee is being reset."
@@ -126,12 +132,28 @@ def add_action(self, bug):
126132
127133 self .add_prioritized_action (bug , bug ["triage_owner" ], needinfo , autofix )
128134
135+ def get_priority_change_date (self , bug ):
136+ current_priority = bug ["priority" ]
137+
138+ for change in reversed (bug ["history" ]):
139+ if (
140+ change ["field_name" ] == "priority"
141+ and change ["added" ] == current_priority
142+ ):
143+ return datetime .strptime (change ["when" ], "%Y-%m-%dT%H:%M:%SZ" )
144+ return None
145+
129146 def handle_bug (self , bug , data ):
130147 bugid = str (bug ["id" ])
131148 if "triage_owner_detail" not in bug :
132149 logger .warning ("Skip bug %s: no triage owner" , bugid )
133150 return None
134151
152+ priority_change_date = self .get_priority_change_date (bug )
153+ is_old_priority = (
154+ priority_change_date and priority_change_date < self .one_year_ago
155+ )
156+
135157 data [bugid ] = {
136158 "assigned_to" : bug ["assigned_to" ],
137159 "triage_owner" : bug ["triage_owner" ],
@@ -142,6 +164,7 @@ def handle_bug(self, bug, data):
142164 "priority" : bug ["priority" ],
143165 "severity" : bug ["severity" ],
144166 "keywords" : bug ["keywords" ],
167+ "is_old_priority" : is_old_priority ,
145168 }
146169
147170 return bug
@@ -158,6 +181,7 @@ def get_bz_params(self, date):
158181 "priority" ,
159182 "severity" ,
160183 "keywords" ,
184+ "history" ,
161185 ]
162186 params = {
163187 "include_fields" : fields ,
0 commit comments