Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Trac Type and Priority as GitHub Labels #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "Component"s, "Type"s 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
Expand Down
17 changes: 16 additions & 1 deletion github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

23 changes: 13 additions & 10 deletions trac-tickets-to-gh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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()
Expand All @@ -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():
Expand Down