Commits

Anonymous committed d7e910b

#368: update the nosy list only when necessary.

Comments (0)

Files changed (1)

detectors/autonosy.py

-# Auditor to automatically add users as nosy to issues when
-# the component field gets set
+# This auditor automatically adds users and release managers to the nosy
+# list when the component fields gets set and the priority is changed to
+# 'release blocker' respectively.
+# See also the nosyreaction.py script (they should probably be merged to a
+# single script).
 
 # Python 2.3 ... 2.6 compatibility:
 from roundup.anypy.sets_ import set
 def autonosy(db, cl, nodeid, newvalues):
     components = newvalues.get('components', [])
 
-    nosy = set()
+    current_nosy = set()
     if 'nosy' in newvalues:
-        new_nosy = newvalues.get('nosy', [])
-        new_nosy = [value for value in new_nosy if db.hasnode('user', value)]
-        nosy |= set(new_nosy)
+        # the nosy list changed
+        # newvalues['nosy'] contains all the user ids (new and old)
+        nosy = newvalues.get('nosy', [])
+        nosy = [value for value in nosy if db.hasnode('user', value)]
+        current_nosy |= set(nosy)
     else:
         if nodeid:
+            # the issue already exists
+            # get the values that were already in the nosy
             old_nosy = db.issue.get(nodeid, 'nosy')
-            nosy |= set(old_nosy)
+            current_nosy |= set(old_nosy)
+
+    # make a copy of the current_nosy where to add the new user ids
+    new_nosy = set(current_nosy)
 
     for component in components:
         users = db.component.get(component, 'add_as_nosy')
-        nosy |= set(users)
+        new_nosy |= set(users)
 
     # get the new values if they changed or the already-set ones if they didn't
     if 'priority' in newvalues:
         for version in versions:
             name = db.version.get(version, 'name')
             if name in RELEASE_MANAGERS:
-                nosy.add(RELEASE_MANAGERS[name])
+                new_nosy.add(RELEASE_MANAGERS[name])
 
-    newvalues['nosy'] = list(nosy)
+    if current_nosy != new_nosy:
+        # some user ids have been added automatically, so update the nosy
+        newvalues['nosy'] = list(new_nosy)
 
 
 def init(db):