From d7d04186e84b0c6e210f1d32e29a27aef09c6542 Mon Sep 17 00:00:00 2001 From: callumski Date: Wed, 20 Jun 2012 16:27:57 +0200 Subject: [PATCH 1/4] Update to describe adding of Trac Type and Priority. --- README.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.txt b/README.txt index 7b7661e..2f87c26 100644 --- a/README.txt +++ b/README.txt @@ -17,7 +17,9 @@ A sample program uses this to migrate Trac tickets into GitHub Issues. It creates and merges "Milestones". -It uses Trac "Components" as GitHub "Labels". +It uses Trac "Components", "Type" and "Priority"s as GitHub "Labels". + +N.B. It maps Trac "defect" to GitHub "bug". It cannot migrate ticket ownership to GitHub Issue "Assignee" since we have no way to map customer-specific Trac usernames into global GitHub From 0a7775cfaf4e3f95987b6602abee7f38c0063cd4 Mon Sep 17 00:00:00 2001 From: callumski Date: Wed, 20 Jun 2012 16:28:44 +0200 Subject: [PATCH 2/4] Added addlabel method. --- github.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/github.py b/github.py index 3804a7a..2a7c4c7 100644 --- a/github.py +++ b/github.py @@ -68,4 +68,19 @@ def milestones(self, query=None, data=None): There are many other attrs you can set in the API. """ return self.access('milestones', query=query, data=data) - + + def addlabel(self, label, labeldict, issue, logging): + """If label does not already exist then add it to GitHub. + Then append the label to the issue. + """ + if label and labeldict and issue: + if label not in labeldict: + # GitHub creates the 'url' and 'color' fields for us + self.labels(data={'name': label}) + labeldict[label] = 'CREATED' # keep track of it so we don't re-create it + logging.debug("adding label as new label=%s" % label) + if 'labels' in issue: + issue['labels'].append(label) + else: + issue['labels'] = [label] + From 2c0523cc199440c5c184655ba74d0464952c9508 Mon Sep 17 00:00:00 2001 From: callumski Date: Wed, 20 Jun 2012 16:29:53 +0200 Subject: [PATCH 3/4] Added use of github.addlabel() method to add Trac "Component", "Type" and "Priority" as GitHub labels. --- trac-tickets-to-gh.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/trac-tickets-to-gh.py b/trac-tickets-to-gh.py index a84a746..4393bf0 100755 --- a/trac-tickets-to-gh.py +++ b/trac-tickets-to-gh.py @@ -78,7 +78,7 @@ def close(self): logging.debug("Trac ticket owner: %s" % username) -# Get GitHub labels; we'll merge Trac components into them +# Get GitHub labels; we'll merge Trac components and other values into them logging.info("Getting existing GitHub labels...") labels = {} @@ -126,8 +126,8 @@ def close(self): # Copy Trac tickets to GitHub issues, keyed to milestones above -tickets = trac.sql('SELECT id, summary, description , owner, milestone, component, status FROM ticket ORDER BY id') # LIMIT 5 -for tid, summary, description, owner, milestone, component, status in tickets: +tickets = trac.sql('SELECT id, summary, description , owner, milestone, component, status, type, priority FROM ticket ORDER BY id') # LIMIT 5 +for tid, summary, description, owner, milestone, component, status, type, priority in tickets: logging.info("Ticket %d: %s" % (tid, summary)) if description: description = description.strip() @@ -139,14 +139,17 @@ def close(self): if milestone: m = milestone_id.get(milestone) if m: - issue['milestone'] = m + issue['milestone'] = m if component: - if component not in labels: - # GitHub creates the 'url' and 'color' fields for us - github.labels(data={'name': component}) - labels[component] = 'CREATED' # keep track of it so we don't re-create it - logging.debug("adding component as new label=%s" % component) - issue['labels'] = [component] + github.addlabel(component, labels, issue, logging) + if type: + # Map 'defect' to 'bug' + if type == 'defect': + type = 'bug' + github.addlabel(type, labels, issue, logging) + if priority: + github.addlabel(priority, labels, issue, logging) + # We have to create/map Trac users to GitHub usernames before we can assign # them to tickets; don't see how to do that conveniently now. # if owner.strip(): From e550cf676d3748b18b1033b6bfe8ceb8242b763f Mon Sep 17 00:00:00 2001 From: callumski Date: Wed, 20 Jun 2012 16:30:43 +0200 Subject: [PATCH 4/4] Update master --- README.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.txt b/README.txt index 2f87c26..5e41b0f 100644 --- a/README.txt +++ b/README.txt @@ -17,7 +17,7 @@ A sample program uses this to migrate Trac tickets into GitHub Issues. It creates and merges "Milestones". -It uses Trac "Components", "Type" and "Priority"s as GitHub "Labels". +It uses Trac "Component"s, "Type"s and "Priority"s as GitHub "Labels". N.B. It maps Trac "defect" to GitHub "bug".