Merge "Handle Branches from Launchpad in Migration"
This commit is contained in:
commit
7fa5ac5e08
|
@ -52,7 +52,7 @@ def main():
|
||||||
# requested one.
|
# requested one.
|
||||||
auto_increment = CONF.auto_increment
|
auto_increment = CONF.auto_increment
|
||||||
if auto_increment:
|
if auto_increment:
|
||||||
print 'Setting stories.AUTO_INCREMENT to %d' % (auto_increment,)
|
print('Setting stories.AUTO_INCREMENT to %d' % (auto_increment,))
|
||||||
session = db_api.get_session(in_request=False)
|
session = db_api.get_session(in_request=False)
|
||||||
session.execute('ALTER TABLE stories AUTO_INCREMENT = %d;'
|
session.execute('ALTER TABLE stories AUTO_INCREMENT = %d;'
|
||||||
% (auto_increment,))
|
% (auto_increment,))
|
||||||
|
@ -61,5 +61,5 @@ def main():
|
||||||
loader = LaunchpadLoader(CONF.from_project, CONF.to_project)
|
loader = LaunchpadLoader(CONF.from_project, CONF.to_project)
|
||||||
loader.run()
|
loader.run()
|
||||||
else:
|
else:
|
||||||
print 'Unsupported import origin: %s' % CONF.origin
|
print('Unsupported import origin: %s' % CONF.origin)
|
||||||
return
|
return
|
||||||
|
|
|
@ -43,7 +43,25 @@ class LaunchpadLoader(object):
|
||||||
for message in bug.messages:
|
for message in bug.messages:
|
||||||
self.writer.write_user(message.owner)
|
self.writer.write_user(message.owner)
|
||||||
|
|
||||||
# Write the bug.
|
links = [task.target_link for task in bug.bug_tasks]
|
||||||
|
releases = ['kilo', 'liberty', 'mitaka', 'newton', 'ocata',
|
||||||
|
'pike', 'queens']
|
||||||
|
branches = []
|
||||||
|
|
||||||
|
#Strip ugliness off of links to bugs
|
||||||
|
for branch in links:
|
||||||
|
split_branch = branch.split('launchpad.net')
|
||||||
|
url_parts = split_branch[1].split('/')
|
||||||
|
branch_name = url_parts[-1].lower()
|
||||||
|
project_name = url_parts[-2]
|
||||||
|
|
||||||
|
if (branch_name in releases and
|
||||||
|
project_name == self.reader.project_name):
|
||||||
|
branches.append(branch_name)
|
||||||
|
elif branch_name == self.reader.project_name:
|
||||||
|
branches.append('master')
|
||||||
|
|
||||||
|
# Write the bug
|
||||||
priority = map_lp_priority(lp_bug.importance)
|
priority = map_lp_priority(lp_bug.importance)
|
||||||
status = map_lp_status(lp_bug.status)
|
status = map_lp_status(lp_bug.status)
|
||||||
self.writer.write_bug(bug=bug,
|
self.writer.write_bug(bug=bug,
|
||||||
|
@ -51,7 +69,8 @@ class LaunchpadLoader(object):
|
||||||
assignee=assignee,
|
assignee=assignee,
|
||||||
priority=priority,
|
priority=priority,
|
||||||
status=status,
|
status=status,
|
||||||
tags=tags)
|
tags=tags,
|
||||||
|
branches=branches)
|
||||||
|
|
||||||
|
|
||||||
def map_lp_priority(lp_priority):
|
def map_lp_priority(lp_priority):
|
||||||
|
|
|
@ -52,16 +52,16 @@ class LaunchpadWriter(object):
|
||||||
.filter_by(name=project_name) \
|
.filter_by(name=project_name) \
|
||||||
.first()
|
.first()
|
||||||
if not self.project:
|
if not self.project:
|
||||||
print "Local project %s not found in storyboard, please create " \
|
print("Local project %s not found in storyboard, please create \
|
||||||
"it first." % (project_name)
|
it first." % (project_name))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
self.branch = db_api.model_query(Branch, self.session) \
|
self.branch = db_api.model_query(Branch, self.session) \
|
||||||
.filter_by(project_id=self.project.id, name='master') \
|
.filter_by(project_id=self.project.id, name='master') \
|
||||||
.first()
|
.first()
|
||||||
if not self.branch:
|
if not self.branch:
|
||||||
print "No master branch found for project %s, please create " \
|
print("No master branch found for project %s, please create \
|
||||||
"one first." % (project_name)
|
one first." % (project_name))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def write_tags(self, bug):
|
def write_tags(self, bug):
|
||||||
|
@ -93,7 +93,7 @@ class LaunchpadWriter(object):
|
||||||
|
|
||||||
if not tag:
|
if not tag:
|
||||||
# Go ahead and create it.
|
# Go ahead and create it.
|
||||||
print "Importing tag '%s'" % (tag_name)
|
print("Importing tag '%s'" % tag_name)
|
||||||
tag = db_api.entity_create(StoryTag, {
|
tag = db_api.entity_create(StoryTag, {
|
||||||
'name': tag_name
|
'name': tag_name
|
||||||
}, session=self.session)
|
}, session=self.session)
|
||||||
|
@ -129,8 +129,8 @@ class LaunchpadWriter(object):
|
||||||
except DiscoveryFailure:
|
except DiscoveryFailure:
|
||||||
# If we encounter a launchpad maintenance user,
|
# If we encounter a launchpad maintenance user,
|
||||||
# give it an invalid openid.
|
# give it an invalid openid.
|
||||||
print "WARNING: Invalid OpenID for user \'%s\'" \
|
print("WARNING: Invalid OpenID for user \'%s\'"
|
||||||
% (display_name,)
|
% (display_name,))
|
||||||
self._openid_map[user_link] = \
|
self._openid_map[user_link] = \
|
||||||
'http://example.com/invalid/~%s' % (display_name,)
|
'http://example.com/invalid/~%s' % (display_name,)
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ class LaunchpadWriter(object):
|
||||||
.filter_by(openid=openid) \
|
.filter_by(openid=openid) \
|
||||||
.first()
|
.first()
|
||||||
if not user:
|
if not user:
|
||||||
print "Importing user '%s'" % (user_link)
|
print("Importing user '%s'" % (user_link))
|
||||||
|
|
||||||
# Use a temporary email address, since LP won't give this to
|
# Use a temporary email address, since LP won't give this to
|
||||||
# us and it'll be updated on first login anyway.
|
# us and it'll be updated on first login anyway.
|
||||||
|
@ -158,13 +158,39 @@ class LaunchpadWriter(object):
|
||||||
|
|
||||||
return self._user_map[openid]
|
return self._user_map[openid]
|
||||||
|
|
||||||
def write_bug(self, owner, assignee, priority, status, tags, bug):
|
def check_branch(self, branch):
|
||||||
|
|
||||||
|
#Look in db for branches that are in project
|
||||||
|
#if branch is in project return True
|
||||||
|
exists = (db_api.model_query(Branch, self.session)
|
||||||
|
.filter_by(project_id=self.project.id)
|
||||||
|
.filter_by(name=branch).all())
|
||||||
|
return exists
|
||||||
|
|
||||||
|
def get_branch(self, branch):
|
||||||
|
result = (db_api.model_query(Branch, self.session)
|
||||||
|
.filter_by(project_id=self.project.id)
|
||||||
|
.filter_by(name=branch)
|
||||||
|
.first())
|
||||||
|
return result
|
||||||
|
|
||||||
|
def write_bug(self, owner, assignee, priority, status, tags, bug,
|
||||||
|
branches):
|
||||||
"""Writes the story, task, task history, and conversation.
|
"""Writes the story, task, task history, and conversation.
|
||||||
|
|
||||||
:param owner: The bug owner SQLAlchemy entity.
|
:param owner: The bug owner SQLAlchemy entity.
|
||||||
:param tags: The tag SQLAlchemy entities.
|
:param tags: The tag SQLAlchemy entities.
|
||||||
:param bug: The Launchpad Bug record.
|
:param bug: The Launchpad Bug record.
|
||||||
"""
|
"""
|
||||||
|
#Checks to make sure that the branch for the bug exists
|
||||||
|
for branch in branches:
|
||||||
|
if not self.check_branch(branch):
|
||||||
|
print('No %s branch found for %s project. Creating one now.' %
|
||||||
|
(branch, self.project.name))
|
||||||
|
db_api.entity_create(Branch, {
|
||||||
|
'name': branch,
|
||||||
|
'project_id': self.project.id
|
||||||
|
}, session=self.session)
|
||||||
|
|
||||||
if hasattr(bug, 'date_created'):
|
if hasattr(bug, 'date_created'):
|
||||||
created_at = bug.date_created
|
created_at = bug.date_created
|
||||||
|
@ -180,9 +206,9 @@ class LaunchpadWriter(object):
|
||||||
# example url: https://api.launchpad.net/1.0/bugs/1057477
|
# example url: https://api.launchpad.net/1.0/bugs/1057477
|
||||||
url_match = re.search("([0-9]+)$", str(bug.self_link))
|
url_match = re.search("([0-9]+)$", str(bug.self_link))
|
||||||
if not url_match:
|
if not url_match:
|
||||||
print 'ERROR: Unable to extract launchpad ID from %s.' \
|
print('ERROR: Unable to extract launchpad ID from %s.'
|
||||||
% (bug.self_link,)
|
% (bug.self_link,))
|
||||||
print 'ERROR: Please file a ticket.'
|
print('ERROR: Please file a ticket.')
|
||||||
return
|
return
|
||||||
launchpad_id = int(url_match.groups()[0])
|
launchpad_id = int(url_match.groups()[0])
|
||||||
|
|
||||||
|
@ -209,10 +235,10 @@ class LaunchpadWriter(object):
|
||||||
duplicate = db_api.entity_get(Story, launchpad_id,
|
duplicate = db_api.entity_get(Story, launchpad_id,
|
||||||
session=self.session)
|
session=self.session)
|
||||||
if not duplicate:
|
if not duplicate:
|
||||||
print "Importing Story: %s" % (bug.self_link,)
|
print("Importing Story: %s" % (bug.self_link,))
|
||||||
story = db_api.entity_create(Story, story, session=self.session)
|
story = db_api.entity_create(Story, story, session=self.session)
|
||||||
else:
|
else:
|
||||||
print "Existing Story: %s" % (bug.self_link,)
|
print("Existing Story: %s" % (bug.self_link,))
|
||||||
story = duplicate
|
story = duplicate
|
||||||
|
|
||||||
# Duplicate check- launchpad import creates one task per story,
|
# Duplicate check- launchpad import creates one task per story,
|
||||||
|
@ -224,20 +250,22 @@ class LaunchpadWriter(object):
|
||||||
.filter(Task.project_id == self.project.id) \
|
.filter(Task.project_id == self.project.id) \
|
||||||
.first()
|
.first()
|
||||||
if not existing_task:
|
if not existing_task:
|
||||||
print "- Adding task in project %s" % (self.project.name,)
|
print("- Adding task in project %s" % (self.project.name,))
|
||||||
task = db_api.entity_create(Task, {
|
|
||||||
'title': title,
|
for branch in branches:
|
||||||
'assignee_id': assignee.id if assignee else None,
|
task = db_api.entity_create(Task, {
|
||||||
'project_id': self.project.id,
|
'title': title,
|
||||||
'branch_id': self.branch.id,
|
'assignee_id': assignee.id if assignee else None,
|
||||||
'story_id': launchpad_id,
|
'project_id': self.project.id,
|
||||||
'created_at': created_at,
|
'branch_id': self.get_branch(branch).id,
|
||||||
'updated_at': updated_at,
|
'story_id': launchpad_id,
|
||||||
'priority': priority,
|
'created_at': created_at,
|
||||||
'status': status
|
'updated_at': updated_at,
|
||||||
}, session=self.session)
|
'priority': priority,
|
||||||
|
'status': status
|
||||||
|
}, session=self.session)
|
||||||
else:
|
else:
|
||||||
print "- Existing task in %s" % (self.project.name,)
|
print("- Existing task in %s" % (self.project.name,))
|
||||||
task = existing_task
|
task = existing_task
|
||||||
|
|
||||||
# Duplication Check - If this story already has a creation event,
|
# Duplication Check - If this story already has a creation event,
|
||||||
|
@ -249,7 +277,7 @@ class LaunchpadWriter(object):
|
||||||
.filter(TimeLineEvent.event_type == event_types.STORY_CREATED) \
|
.filter(TimeLineEvent.event_type == event_types.STORY_CREATED) \
|
||||||
.first()
|
.first()
|
||||||
if not story_created_event:
|
if not story_created_event:
|
||||||
print "- Generating story creation event"
|
print("- Generating story creation event")
|
||||||
db_api.entity_create(TimeLineEvent, {
|
db_api.entity_create(TimeLineEvent, {
|
||||||
'story_id': launchpad_id,
|
'story_id': launchpad_id,
|
||||||
'author_id': owner.id,
|
'author_id': owner.id,
|
||||||
|
@ -260,7 +288,7 @@ class LaunchpadWriter(object):
|
||||||
# Create the creation event for the task, but only if we just created
|
# Create the creation event for the task, but only if we just created
|
||||||
# a new task.
|
# a new task.
|
||||||
if not existing_task:
|
if not existing_task:
|
||||||
print "- Generating task creation event"
|
print("- Generating task creation event")
|
||||||
db_api.entity_create(TimeLineEvent, {
|
db_api.entity_create(TimeLineEvent, {
|
||||||
'story_id': launchpad_id,
|
'story_id': launchpad_id,
|
||||||
'author_id': owner.id,
|
'author_id': owner.id,
|
||||||
|
@ -279,10 +307,10 @@ class LaunchpadWriter(object):
|
||||||
.filter(TimeLineEvent.event_type == event_types.USER_COMMENT) \
|
.filter(TimeLineEvent.event_type == event_types.USER_COMMENT) \
|
||||||
.count()
|
.count()
|
||||||
desired_count = len(bug.messages)
|
desired_count = len(bug.messages)
|
||||||
print "- %s of %s comments already imported." % (current_count,
|
print("- %s of %s comments already imported." % (current_count,
|
||||||
desired_count)
|
desired_count))
|
||||||
for i in range(current_count, desired_count):
|
for i in range(current_count, desired_count):
|
||||||
print '- Importing comment %s of %s' % (i + 1, desired_count)
|
print('- Importing comment %s of %s' % (i + 1, desired_count))
|
||||||
message = bug.messages[i]
|
message = bug.messages[i]
|
||||||
message_created_at = message.date_created
|
message_created_at = message.date_created
|
||||||
message_owner = self.write_user(message.owner)
|
message_owner = self.write_user(message.owner)
|
||||||
|
|
Loading…
Reference in New Issue