[p4dti-discussion] Renumbering bugs

Nick Barnes nb at ravenbrook.com
Thu Oct 20 21:43:29 BST 2005


At 2005-10-20 00:02:44+0000, "Pavloff, Alex \(IE\) @ SONOMAEO" writes:

> Hi,
> 
> I've got the problem where the bugs numbers aren't prefixed with 0s.  Of
> course, I didn't realize that until after the system was in use, and now
> Perforce doesn't sort the jobs right, so people don't see all the jobs
> appear.
> 
> What's the best to renumber the jobs and retain all the information
> without breaking anything?

A user contributed the attached patch, which has not yet been
incorporated into the P4DTI.  He says the following:

> I have now learnt python enough (I still prefer perl) to extend P4DTI to
> have a customisable jobname_function in config.py and extended the
> replicator so it deletes and recreates the job in P4 and transfers any
> fixes, if the job name changes.
> 
> I have added info to the admin guide with an example on how to customise
> this function to use the bugzilla alias (new with 2.18) if it exists or the
> standard bugNNN.

I hope this helps.  It's not yet supported.

Nick Barnes
P4DTI Project
Ravenbrook Limited

-------------- next part --------------
diff -Naur p4dti-bugzilla-2.2.1/ag/index.html p4dti-bugzilla-2.2.1_jc/ag/index.html
--- p4dti-bugzilla-2.2.1/ag/index.html  2005-03-17 14:53:44.000000000 +0000
+++ p4dti-bugzilla-2.2.1_jc/ag/index.html       2005-03-17 14:51:32.000000000 +0000
@@ -1323,10 +1323,8 @@
 tracker. </p>
 
 <p> If this parameter is 0 (the default), the <abbr title="Perforce
-Defect Tracking Integration">P4DTI</abbr> tries to match the defect
-tracker's names for the issues it replicates.  <span
-class="bugzilla">In the Bugzilla integration, jobs are called bug1,
-bug2, and so on.</span>
+Defect Tracking Integration">P4DTI</abbr> uses the <b>config-jobname_function</b> function to define
+the name for the issue.  
 </p>
 
 <p> Example: <code class="source">1</code> </p>
@@ -1336,6 +1334,41 @@
 jobs get the style of name you requested. </p>
 
 
+<h4> <a id="config-jobname_function" name="config-jobname_function"><code class="source">config-jobname_function</code></a> </h4>
+
+<p>(Only applies if <b>use_perforce_jobnames=0</b>)</p>
+
+<p> Description: This parameter defines the function the <abbr title="Perforce
+Defect Tracking Integration">P4DTI</abbr> will use to create the name
+used for the replicated issues. 
+</p>
+<p>
+<span
+class="bugzilla">In the standard Bugzilla integration configuration, jobs are called bug1,
+bug2, and so on, where the number matches as the issue number in Bugzilla.</span>
+</p>
+
+<p> Example (standard):
+
+ <code class="source"><pre>
+  def jobname_function(issue):
+      return 'bug%d' % issue['bug_id']
+</pre></code> </p>
+
+<p> Example using alias names in preference to the bug number:
+
+ <code class="source"><pre>
+  def jobname_function(issue):
+      if issue['alias'] > "":
+          return '%s' % string.lower(issue['alias'])
+      else:
+          return 'bug%d' % issue['bug_id']
+</pre></code> </p>
+
+<p> If you change this function, the <abbr title="Perforce Defect
+Tracking Integration">P4DTI</abbr> doesn't rename existing jobs, but new
+jobs get the style of name you requested. </p>
+
 <h4> <a id="config-use_windows_event_log" name="config-use_windows_event_log"><code class="source">use_windows_event_log</code></a> </h4>
 
 <p>(Windows only)</p>
@@ -4822,6 +4855,16 @@
 
 </tr>
 
+<tr valign="top">
+
+  <td>2005-03-17</td>
+
+  <td>JC</a></td>
+
+  <td>Added config jobname_function</td>
+
+</tr>
+
 </table>
 
 
diff -Naur p4dti-bugzilla-2.2.1/catalog.py p4dti-bugzilla-2.2.1_jc/catalog.py
--- p4dti-bugzilla-2.2.1/catalog.py     2005-03-17 14:44:22.000000000 +0000
+++ p4dti-bugzilla-2.2.1_jc/catalog.py  2005-03-17 14:44:03.000000000 +0000
@@ -219,7 +219,6 @@
     554: (message.NOTICE, "Perforce replicator user <%s> added to Bugzilla as user %d."),
     555: (message.ERR, "User %d must be in group '%s' to edit bug %d."),
     556: (message.ERR, "User %d must be in group '%s' to edit bug %d in product '%s'."),
-
     # 2.6. Messages from dt_teamtrack.py (600-699)
     # That module has been removed, so all these messages are now NOT_USED.
 
@@ -435,6 +434,7 @@
     926: (message.INFO, "Job changer"),
     927: (message.WARNING, "Can't use Perforce client %s."),
     928: (message.WARNING, "Attempting to make working Perforce client %s."),
+    929: (message.INFO, "Changing issue '%s' job from '%s' to '%s' and repropagating."),
 
     # 2.9. Messages from init.py, check.py, check_jobs.py, run.py,
     # refresh.py, mysqldb_support.py, service.py, portable.py,
@@ -470,7 +470,6 @@
     1101: (message.NOT_USED, "Table '%s' not recognized."),
     1102: (message.NOT_USED, "Table '%s' has no field named '%s'."),
     1103: (message.NOT_USED, "Unknown option: '%s'."),
-
     }
 
 
@@ -609,6 +608,8 @@
 # 2004-05-28 NB Bugzilla 2.17.7 support (added 555, 556; removed 500,
 # 507; changed 128, 304, 527-529).
 #
+# 2005-03-17 JC Add 929
+#
 #
 # C. COPYRIGHT AND LICENSE
 #
diff -Naur p4dti-bugzilla-2.2.1/config.py p4dti-bugzilla-2.2.1_jc/config.py
--- p4dti-bugzilla-2.2.1/config.py      2005-03-17 14:44:22.000000000 +0000
+++ p4dti-bugzilla-2.2.1_jc/config.py   2005-03-17 14:44:03.000000000 +0000
@@ -22,6 +22,7 @@
 # Developers: If you add parameters to this file, update section 2.1 of
 # init.py as well.
 
+import string
 import message
 
 
@@ -174,9 +175,16 @@
     return 1
 
 # Set this to 1 to use Perforce-style jobnames (like job000001) for
-# replicated issues rather than using the defect tracker's name.
+# replicated issues rather than using the defect tracker's name as set
+# by jobname_function below.
 use_perforce_jobnames = 0
 
+# A function that selects the job name to be used when replicating.
+# See section 5.1.3 of the the Administrator's Guide.
+def jobname_function(issue):
+    return 'bug%d' % issue['bug_id']
+        
+
 # Set this to 1 to log activity to the Windows Event Log; 0
 # otherwise.
 use_windows_event_log = 0
diff -Naur p4dti-bugzilla-2.2.1/configure_bugzilla.py p4dti-bugzilla-2.2.1_jc/configure_bugzilla.py
--- p4dti-bugzilla-2.2.1/configure_bugzilla.py  2005-03-17 14:44:22.000000000 +0000
+++ p4dti-bugzilla-2.2.1_jc/configure_bugzilla.py       2005-03-17 14:44:03.000000000 +0000
@@ -724,8 +724,7 @@
     # Set configuration parameters needed by dt_bugzilla.
     config.append_only_fields = append_only_fields
     config.read_only_fields = read_only_fields
-    config.jobname_function = lambda bug: 'bug%d' % bug['bug_id']
-
+    
     # Set configuration parameters needed by the replicator.
     config.date_translator = dt_bugzilla.date_translator()
     config.job_owner_field = fields_bz_to_p4.get('assigned_to', 'User')
@@ -874,6 +873,7 @@
 #
 # 2004-05-28 NB Add bugmail as alternative to processmail.
 #
+# 2005-03-17 JC Moved jobname_function to config.py.
 #
 # C. COPYRIGHT AND LICENSE
 #
diff -Naur p4dti-bugzilla-2.2.1/dt_bugzilla.py p4dti-bugzilla-2.2.1_jc/dt_bugzilla.py
--- p4dti-bugzilla-2.2.1/dt_bugzilla.py 2005-03-17 14:44:22.000000000 +0000
+++ p4dti-bugzilla-2.2.1_jc/dt_bugzilla.py      2005-03-17 14:44:03.000000000 +0000
@@ -153,6 +153,13 @@
         self.p4dti_bug['jobname'] = jobname
         self.dt.bugzilla.add_p4dti_bug(self.p4dti_bug, created)
 
+    def update_p4dti_jobname(self, jobname):
+        self.p4dti_bug['jobname'] = jobname
+        self.dt.bugzilla.update_p4dti_bug({'jobname': jobname}, self.bug['bug_id'])
+
+    def update_replication_jobname(self, jobname):
+        self.update_p4dti_jobname(jobname)
+
     def setup_for_replication(self, jobname):
         self.make_p4dti_bug(jobname, created=0)
 
@@ -1682,6 +1689,8 @@
 # bug in multiple groups; changed bug change permission rules; test
 # per-product group memberships when creating or editing bugs.
 #
+# 2005-03-17 JC Added update_p4dti_jobname() and update_replication_jobname()
+# for use when the job name changes
 #
 # C. COPYRIGHT AND LICENSE
 #
diff -Naur p4dti-bugzilla-2.2.1/replicator.py p4dti-bugzilla-2.2.1_jc/replicator.py
--- p4dti-bugzilla-2.2.1/replicator.py  2005-03-17 14:44:22.000000000 +0000
+++ p4dti-bugzilla-2.2.1_jc/replicator.py       2005-03-17 14:44:03.000000000 +0000
@@ -1420,21 +1420,55 @@
 
         # Only the defect tracker issue has changed.
         if changed == 'dt':
-            # "Replicating issue '%s' to job '%s'."
-            self.log(804, (issuename, jobname))
-            self.replicate_issue_dt_to_p4(issue, job)
-            if not issue.rid():
-                # If we started out with jobname == 'new', then by
-                # this time it must have been set to the new jobname
-                # by the update_job() method.
-                if job['Job'] == 'new':
-                    # "Replicated issue '%s' to Perforce, but didn't
-                    # get a jobname for it (the 'Job' field is still
-                    # 'new')."
-                    raise self.error, catalog.msg(904, (issue.id()))
-                issue.setup_for_replication(job['Job'])
-                # "Set up issue '%s' to replicate to job '%s'."
-                self.log(803, (issue.id(), job['Job']))
+
+           #check if the job name has changed
+           propername = issue.dt.config.jobname_function(issue)
+            if jobname != propername:
+                self.log(929, (issue.bug['bug_id'], jobname, propername))
+
+                #get the fixes for the old job
+                p4_old_fixes = self.job_fixes(job)
+                
+               #delete the original job in P4
+                self.p4.run('job -d %s' % (jobname))
+                self.record_job_update(job)
+
+                # Transform the issue into a new P4 job.
+               job['Job'] = propername
+                jobname = propername
+
+                changes = self.translate_issue_dt_to_p4(issue, {})
+                self.update_job(job, changes)
+
+                #add in the original fixes
+                for p4_fix in p4_old_fixes:
+                    self.p4.run('fix -s %s -c %s %s' % (job['Status'], p4_fix['Change'], propername))
+                    self.record_job_update(job)
+
+                # get all the fixes back into bugzilla
+                self.replicate_filespecs_p4_to_dt(issue, job)
+                self.replicate_fixes_p4_to_dt(issue, job)
+
+                issue.update_replication_jobname(jobname)
+
+            # otherwise a simple update
+            else:
+
+                # "Replicating issue '%s' to job '%s'."
+                self.log(804, (issuename, jobname))
+                self.replicate_issue_dt_to_p4(issue, job)
+                if not issue.rid():
+                    # If we started out with jobname == 'new', then by
+                    # this time it must have been set to the new jobname
+                    # by the update_job() method.
+                    if job['Job'] == 'new':
+                        # "Replicated issue '%s' to Perforce, but didn't
+                        # get a jobname for it (the 'Job' field is still
+                        # 'new')."
+                        raise self.error, catalog.msg(904, (issue.id()))
+                    issue.setup_for_replication(job['Job'])
+                    # "Set up issue '%s' to replicate to job '%s'."
+                    self.log(803, (issue.id(), job['Job']))
 
         # Only the Perforce job has changed.
         elif changed == 'p4':
@@ -2159,6 +2193,9 @@
 # 2003-12-12 NB Change jobspec-related functions to expose them to new
 # scripts.
 #
+# 2005-03-17 JC Added detection of job name change with deletion and
+# repropagation of job and transfer of fixes.
+#
 #
 # C. COPYRIGHT AND LICENSE
 #


More information about the P4DTI-discussion mailing list