-
Notifications
You must be signed in to change notification settings - Fork 1
/
migrate.rb
119 lines (89 loc) · 2.52 KB
/
migrate.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/local/bin/ruby
require 'rubygems'
require 'gitlab'
require 'mysql2'
require 'yaml'
### Load configuration
c = Hash.new
c['gitlab_client_endpoint'] = \
'https://your.gitlab.server.addr/api/v4'
c['gitlab_client_privatetoekn'] = \
'YOUR-PRIVATE-GITLAB-TOKEN'
c['gitlab_project'] = \
'your-name/your-project-name'
c['gitlab_assigneeid'] = \
0
c['gitlab_milestoneid'] = \
0
c['gitlab_labels'] = \
'osticket'
c['mysql_client_host'] = \
'your.mysql.server.addr'
c['mysql_client_port'] = \
'3306'
c['mysql_client_username'] = \
'osticket'
c['mysql_client_password'] = \
'OSTICKET-USER-PASSWORD'
c['mysql_client_database'] = \
'osticket'
begin
c = YAML.load_file('./config/config.yml')
rescue Errno::ENOENT
puts 'WARNING: Config file not found. The default config settings used.'
end
### Pass the configurations
gitlab_project = c.fetch('gitlab_project')
gitlab_issue_opts_tmpl = Hash.new
if c.fetch('gitlab_assigneeid') > 0 then
gitlab_issue_opts_tmpl['assignee_id'] = c.fetch('gitlab_assigneeid')
end
if c.fetch('gitlab_milestoneid') > 0 then
gitlab_issue_opts_tmpl['milestone_id'] = c.fetch('gitlab_milestoneid')
end
if c.fetch('gitlab_labels') != '' then
gitlab_issue_opts_tmpl['labels'] = c.fetch('gitlab_labels')
end
### Define SQLs
sql_tickets = \
'SELECT * FROM ost_all_descriptions
ORDER BY created'
sql_comments = \
'SELECT * FROM ost_comments
WHERE thread_id = ?
ORDER BY id'
### Set up clients
Gitlab.configure do |config|
config.endpoint = c.fetch('gitlab_client_endpoint')
config.private_token = c.fetch('gitlab_client_privatetoken')
end
glc = Gitlab.client()
myc = Mysql2::Client.new( \
host: c.fetch('mysql_client_host') , \
port: c.fetch('mysql_client_port') , \
username: c.fetch('mysql_client_username') , \
password: c.fetch('mysql_client_password') , \
database: c.fetch('mysql_client_database') )
### Main
q_tickets = myc.prepare(sql_tickets)
r_tickets = q_tickets.execute()
q_comments = myc.prepare(sql_comments)
r_tickets.each do |t|
puts
print "INFO: Migrate ticket ID ", t['ticket_id'], ', subject "', t['subject'], '"'
gitlab_issue_opts = gitlab_issue_opts_tmpl
gitlab_issue_opts['description'] = t['description']
mig_issue = \
glc.create_issue( \
gitlab_project , \
t['subject'] , \
gitlab_issue_opts )
r_comments = q_comments.execute(t['thread_id'])
r_comments.each do |comment|
mig_comment = \
glc.create_issue_note( \
mig_issue.project_id, \
mig_issue.iid, \
comment['comment'] )
end
end