Skip to content

Commit 8bff008

Browse files
committed
fixed milestones issue: now adds milestones to gitlab
1 parent 9bc449c commit 8bff008

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
What
22
=====
33

4-
This script migrates issues from trac to gitlab.
4+
This script migrates trac tickets to gitlab issues.
55

66
Features
77
--------
88
* Component & Issue-Type are converted to labels
9-
* Milestones are ignored (or: I did not get the script to set my one single milestone, so I set it manually)
9+
* Milestones are created in Gitlab from fixture data manualy grabbed from trac (copy/paste)
1010
* Comments to issues are copied over
1111
* Wiki Syntax in comments/descriptions is sanitized for my basic usage
1212

@@ -28,11 +28,12 @@ Target
2828
* ```gitlab_access_token``` - the access token of the user creating all the issues. Found on the account page, e.g. ```secretsecretsecret```
2929
* ```dest_project_name``` - the destination project including the paths to it. Basically the rest of the clone url minus the ".git". E.g. ```jens.neuhalfen/task-ninja```.
3030
* ```milestone_map``` - Maps milestones from trac to gitlab. Milestones have to exist in gitlab prior to running the script (_CAVE_: Assigning milestones does not work.)
31+
* ```milestone_list``` - Lists milestones from trac with associated metadata. Manually populated at this point by copy/paste out of trac milestone admin page
3132

3233
License
3334
========
3435

35-
License: http://www.wtfpl.net/
36+
License: MIT
3637

3738
Requirements
3839
==============

gitlab/Connection.py

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import requests
3+
import sys
34

45
__author__ = 'jens'
56

@@ -67,6 +68,14 @@ def post_json(self, url_postfix, data, **keywords):
6768
def create_issue(self, dest_project_id, new_ticket):
6869
return self.post_json("/projects/:id/issues", new_ticket, id=dest_project_id)
6970

71+
def create_milestone(self, dest_project_id, milestone_info):
72+
new_milestone_data = {
73+
"title" : milestone_info['title'],
74+
"description" : milestone_info['description'],
75+
"due_date" : milestone_info['due_date']
76+
}
77+
self.post_json("/projects/:id/milestones", new_milestone_data, id=dest_project_id)
78+
7079
def comment_issue(self,project_id,ticket_id, body):
7180
new_note_data = {
7281
"id" : project_id,
@@ -78,6 +87,7 @@ def comment_issue(self,project_id,ticket_id, body):
7887

7988
def set_issue_milestone(self,project_id,ticket_id,milestone_id):
8089
new_note_data = {"milestone" : milestone_id}
90+
print >>sys.stderr, "\nSetting issue milestone for: %s\n" % (milestone_id)
8191
self.put("/projects/:project_id/issues/:issue_id", new_note_data, project_id=project_id, issue_id=ticket_id)
8292

8393
def close_issue(self,project_id,ticket_id):

migrate.py

+31-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import re
22
from re import MULTILINE
3+
import sys
34
import xmlrpclib
45
import gitlab
56
"""
@@ -30,6 +31,7 @@
3031
* ```gitlab_access_token``` - the access token of the user creating all the issues. Found on the account page, e.g. ```secretsecretsecret```
3132
* ```dest_project_name``` - the destination project including the paths to it. Basically the rest of the clone url minus the ".git". E.g. ```jens.neuhalfen/task-ninja```.
3233
* ```milestone_map``` - Maps milestones from trac to gitlab. Milestones have to exist in gitlab prior to running the script (_CAVE_: Assigning milestones does not work.)
34+
* ```milestone_list``` - Lists milestones from trac with associated metadata. Manually populated at this point by copy/paste out of trac milestone admin page
3335
3436
License
3537
========
@@ -52,7 +54,24 @@
5254

5355

5456
dest_project_name ="jens.neuhalfen/task-ninja"
55-
milestone_map = {"M1 - build and tests":"M1 - build and tests" }
57+
milestone_map = {
58+
"Sprint 001":"Sprint 001","Sprint 002":"Sprint 002","Sprint 003":"Sprint 003","Sprint 004":"Sprint 004",
59+
"Sprint 005":"Sprint 005","Sprint 006":"Sprint 006","Sprint 007":"Sprint 007","Sprint 008":"Sprint 008",
60+
"Sprint 009":"Sprint 009","Sprint 010":"Sprint 010"
61+
}
62+
63+
milestone_list = {
64+
"Sprint 001":{"title":"Sprint 001","description":"your description here","due_date":"2013-02-11"},
65+
"Sprint 002":{"title":"Sprint 002","description":"etcetera","due_date":"2013-05-06"},
66+
"Sprint 003":{"title":"Sprint 003","description":"","due_date":"2013-05-20"},
67+
"Sprint 004":{"title":"Sprint 004","description":"","due_date":"2013-06-03"},
68+
"Sprint 005":{"title":"Sprint 005","description":"","due_date":"2013-06-10"},
69+
"Sprint 006":{"title":"Sprint 006","description":"","due_date":"2013-06-14"},
70+
"Sprint 007":{"title":"Sprint 007","description":"","due_date":"2013-06-21"},
71+
"Sprint 008":{"title":"Sprint 008","description":"","due_date":"2013-08-15"},
72+
"Sprint 009":{"title":"Sprint 009","description":"","due_date":"2013-08-25"},
73+
"Sprint 010":{"title":"Sprint 010","description":"","due_date":"2013-09-10"}
74+
}
5675
"------"
5776

5877

@@ -66,7 +85,7 @@ def fix_wiki_syntax(markup):
6685

6786
# [changeset:"afsd38..2fs/taskninja"] or [changeset:"afsd38..2fs"]
6887
markup = re.sub(r'\[changeset:"([^"/]+?)(?:/[^"]+)?"]',r"changeset \1",markup)
69-
88+
print >>sys.stderr, "\nProcessing comment markup..."
7089
return markup
7190

7291
def get_dest_project_id(dest_project_name):
@@ -76,7 +95,13 @@ def get_dest_project_id(dest_project_name):
7695

7796
def get_dest_milestone_id(dest_project_id,milestone_name):
7897
dest_milestone_id = dest.milestone_by_name(dest_project_id,milestone_name )
79-
if not dest_milestone_id: raise ValueError("Milestone '%s' of project '%s' not found under '%s'" % (milestone_name,dest_project_name, gitlab_url))
98+
99+
if not dest_milestone_id:
100+
print >>sys.stderr, "\nGitLab milestone not found, creating one for\n %s" % (milestone_list[milestone_name])
101+
dest.create_milestone(dest_project_id,milestone_list[milestone_name])
102+
dest_milestone_id = dest.milestone_by_name(dest_project_id,milestone_name )
103+
# print >>sys.stderr, "\nGitLab milestone id: %s\n" % (dest_milestone_id["id"])
104+
80105
return dest_milestone_id["id"]
81106

82107

@@ -116,20 +141,21 @@ def get_dest_milestone_id(dest_project_id,milestone_name):
116141

117142
milestone = src_ticket_data['milestone']
118143
if milestone and milestone_map_id[milestone]:
119-
new_ticket_data["milestone"] = milestone_map_id[milestone]
144+
new_ticket_data["milestone_id"] = milestone_map_id[milestone]
120145

121146
new_ticket = dest.create_issue(dest_project_id, new_ticket_data)
122147
new_ticket_id = new_ticket["id"]
123148
# setting closed in create does not work -- bug in gitlab
124149
if is_closed: dest.close_issue(dest_project_id,new_ticket_id)
125150

126151
# same for milestone
127-
if new_ticket_data.has_key("milestone"): dest.set_issue_milestone(dest_project_id,new_ticket_id,new_ticket_data["milestone"])
152+
if new_ticket_data.has_key("milestone_id"): dest.set_issue_milestone(dest_project_id,new_ticket_id,new_ticket_data["milestone_id"])
128153

129154

130155
changelog = source.ticket.changeLog(src_ticket_id)
131156
for change in changelog:
132157
change_type = change[2]
158+
print >>sys.stderr, "\nProcessing changelog: '%s'" % (change_type)
133159
if (change_type == "comment"):
134160
comment = fix_wiki_syntax( change[4])
135161
dest.comment_issue(dest_project_id,new_ticket_id,comment)

0 commit comments

Comments
 (0)