Update series bugtasks status on stable/* changes

Makes update_bug.py Gerrit/LP hook support setting series-specific
bug tasks to FixCommitted status on change-merged to stable/*
branches. Fixes bug 921588.

Also sets "In Progress" on patchset-created to stable/*.

Change-Id: I5e3b7c8d249755a71f3425dd33151764be2a1485
diff --git a/update_bug.py b/update_bug.py
index bf8555d..ee2d418 100755
--- a/update_bug.py
+++ b/update_bug.py
@@ -145,8 +145,18 @@
                 set_fix_committed(bugtask)
         elif args.branch == 'milestone-proposed':
             release_fixcommitted(bugtask)
-        else:
-            tag_in_branchname(bugtask, args.branch)
+        elif args.branch.startswith('stable/'):
+            series = args.branch[7:]
+            # Look for a related task matching the series
+            for reltask in bugtask.related_tasks:
+                if reltask.bug_target_name.endswith("/" + series):
+                    # Use fixcommitted if there is any
+                    set_fix_committed(reltask)
+                    break
+            else:
+                # Use tagging if there isn't any
+                tag_in_branchname(bugtask, args.branch)
+
         add_change_merged_message(bugtask, args.change_url, args.project,
                                   args.commit, args.submitter, args.branch,
                                   git_log)
@@ -154,6 +164,14 @@
     if args.hook == "patchset-created":
         if args.branch == 'master':
             set_in_progress(bugtask, launchpad, args.uploader, args.change_url)
+        elif args.branch.startswith('stable/'):
+            series = args.branch[7:]
+            for reltask in bugtask.related_tasks:
+                if reltask.bug_target_name.endswith("/" + series):
+                    set_in_progress(reltask, launchpad,
+                                    args.uploader, args.change_url)
+                    break
+
         if args.patchset == '1':
             add_change_proposed_message(bugtask, args.change_url,
                                         args.project, args.branch)