This repository has been archived by the owner on Apr 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig_creator.rb
148 lines (124 loc) · 4.16 KB
/
config_creator.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#encoding: utf-8
require 'rubygems'
gem 'activeresource', '~> 3.2.12'
require 'active_resource'
require 'github_api'
require 'yaml'
config = YAML.load_file('config.yml')
REDMINE_SITE = config['REDMINE_SITE']
REDMINE_TOKEN = config['REDMINE_TOKEN']
ORGANIZATION = config['ORGANIZATION']
GITHUB_TOKEN = config['GITHUB_TOKEN']
REPOSITORY_FILTER = config['REPOSITORY_FILTER'] || []
github = Github.new do |config|
config.endpoint = 'https://api.github.com'
config.site = 'https://api.github.com'
config.oauth_token = GITHUB_TOKEN
#config.adapter = :net_http
config.ssl = {:verify => false}
config.auto_pagination = true
end
class User < ActiveResource::Base
self.format = :xml
self.site = REDMINE_SITE
self.user = REDMINE_TOKEN
self.password = 'nothing'
end
class IssueStatus < ActiveResource::Base
self.format = :xml
self.site = REDMINE_SITE
self.user = REDMINE_TOKEN
self.password = 'nothing'
end
class Tracker < ActiveResource::Base
self.format = :xml
self.site = REDMINE_SITE
self.user = REDMINE_TOKEN
self.password = 'nothing'
end
class IssuePriority < ActiveResource::Base
self.format = :xml
self.site = "#{REDMINE_SITE}/enumerations"
self.user = REDMINE_TOKEN
self.password = 'nothing'
end
class Role < ActiveResource::Base
self.format = :xml
self.site = REDMINE_SITE
self.user = REDMINE_TOKEN
self.password = 'nothing'
end
issue_statuses = IssueStatus.all
priorities = IssuePriority.all
issue_status_names = issue_statuses.collect { |is| is.name }
priority_names = priorities.collect { |p| p.name }
roles = Role.all
role_names = roles.collect { |r| r.name }
trackers = Tracker.all
tracker_names = trackers.collect {|t| t.name }
users = User.all
$user_names = users.collect { |u| u.login }
puts "Name of open issue status - #{issue_status_names}"
open_issue_status_name = gets.chomp
puts "Name of closed issue status - #{issue_status_names}"
closed_issue_status_name = gets.chomp
puts "Name of normal priority - #{priority_names}"
default_priority_name = gets.chomp
puts "Name of default role - #{role_names}"
default_role_name = gets.chomp
puts "Available trackers: #{tracker_names}"
puts "Select tracker:"
tracker_name = gets.chomp
puts "Import images? (true/false)"
import_images = gets.chomp
if import_images.upcase == 'TRUE'
import_images = true
else
import_images = false
end
repos = github.repos.list(org: ORGANIZATION)
$user_mapping = {}
def process_user(login)
user = nil
user = $user_mapping[login] if $user_mapping.has_key? login
if user.nil? || user == ''
puts "Select mapping of github user #{login} - 'skip' or blank for no mapping"
puts "Available users: #{$user_names}"
e_login = gets.chomp
$user_mapping[login] = e_login
end
end
repos.each do |repo|
next if REPOSITORY_FILTER.size > 0 && !REPOSITORY_FILTER.include?(repo.name)
puts "Processing repository: #{repo.name}"
issues = github.issues.list(user: ORGANIZATION, repo: repo.name).to_a
issues = issues | github.issues.list(user: ORGANIZATION, repo: repo.name, state: 'closed').to_a
issues.each do |is|
process_user is.user.login
process_user is.assignee.login unless is.assignee.nil?
github.issues.events.list(user: ORGANIZATION, repo: repo.name, issue_id: is.number).each do |event|
if ['closed', 'reopened'].include? event.event
process_user event.actor.login
end
end
github.issues.comments.list(user: ORGANIZATION, repo: repo.name, issue_id: is.number).each do |comment|
process_user comment.user.login
end
end
end
config = {
'REDMINE_SITE' => config['REDMINE_SITE'],
'REDMINE_TOKEN' => config['REDMINE_TOKEN'],
'ORGANIZATION' => config['ORGANIZATION'],
'GITHUB_TOKEN' => config['GITHUB_TOKEN'],
'OPEN_ISSUE_STATUS_NAME' => open_issue_status_name,
'CLOSED_ISSUE_STATUS_NAME' => closed_issue_status_name,
'DEFAULT_PRIORITY_NAME' => default_priority_name,
'DEFAULT_ROLE' => default_role_name,
'DEFAULT_TRACKER' => tracker_name,
'IMPORT_IMAGES' => import_images,
'USER_MAPPING' => $user_mapping,
'REPOSITORY_FILTER' => REPOSITORY_FILTER
}
File.open('generate.config.yml', 'w') {|f| f.write(config.to_yaml)}
puts 'Wrote to generate.config.yml'