tractive 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d01e25bb5de4180b95349f37e698b9717900155092fe35e43b293d9192bef63
4
- data.tar.gz: 0a7fe333d0b26b440ddd5c0e9b2e6728a58da011080a33094ae0c7cf4e2254fe
3
+ metadata.gz: 73d210f072099b2362c1b39ebb5dfd7d6096fcb76b5096e9fc3db14dec34f14e
4
+ data.tar.gz: 39b0716034e7ddd0604bc7390f8a4332c2bb5c0664ba88834d7381761dd759aa
5
5
  SHA512:
6
- metadata.gz: 1be7e6bf606c4482e7f04ae4b752ebaa483618a7831326e0862ddc70919c5480963860468691981a7a0c562569b18071c4c4b977b1ca2cdf83543ae898181aa1
7
- data.tar.gz: 9afb81d65732dac50a9285823ab68305811e4a081af14119eb2f93fc9fb3554a0cef45d1342354decdb56a60d755caa97445030fbbe3545bced627ede70b9ae3
6
+ metadata.gz: c765fe77b184c12c4e161691df30181eea49b0ebd757893b28718b13cb8ccd89f25eec0e7037398bdabe1fa84e9a0df513706ddcc8cef21b27bc0c37812b9d62
7
+ data.tar.gz: 88eb6e7049f269feab229e39ab0de8ff9835648cf92f300b64ff07b94ad25e8274991bf9106f0c2050b75fceef430965b98d7ba493690965a7306b4e0932bc25
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tractive (1.0.3)
4
+ tractive (1.0.4)
5
5
  mysql2
6
6
  ox
7
7
  rest-client
data/README.adoc CHANGED
@@ -385,25 +385,55 @@ The pattern of a mapping is like:
385
385
  +
386
386
  [source,yaml]
387
387
  ----
388
- blocker: '#blocker'
389
- critical: '#critical'
390
- major: '#major'
391
- medium: '#medium'
392
- minor: '#minor'
393
- trivial: '#easy'
394
- waiting: '#pending'
395
- n/a:
388
+ trivial:
389
+ name: trivial
390
+ color: ff0000
391
+ major:
392
+ name: major
393
+ color: b44647
394
+ minor:
395
+ name: minor
396
+ color: f7347a
397
+ medium:
398
+ name: medium
399
+ color: f3c77c
396
400
  ----
397
401
 
398
402
  `priority:`::: Priority of the Trac ticket.
399
403
  +
400
404
  [source,yaml]
401
405
  ----
402
- Low: '@low'
403
- High: '@high'
406
+ Low:
407
+ name: low
408
+ color: 22dd00
409
+ High:
410
+ name: high
411
+ color: ff0000
404
412
  ----
405
413
 
406
414
 
415
+ `tracstate:`::: Status of the Trac ticket.
416
+ +
417
+ [source,yaml]
418
+ ----
419
+ accepted:
420
+ name: accepted
421
+ color: 22dd00
422
+ assigned:
423
+ name: assigned
424
+ color: aadd88
425
+ closed:
426
+ name: closed
427
+ color: ee00aa
428
+ new:
429
+ name: new
430
+ color:
431
+ ----
432
+
433
+
434
+ NOTE: As `severity`, `priority` and `tracstate` are converted into `labels` on github so there is an option to specify the `color` for those labels.
435
+
436
+
407
437
  ==== User mapping
408
438
 
409
439
  `users:`:: a one-to-one mapping between Trac usernames or email addresses to
@@ -412,7 +442,8 @@ GitHub usernames for users, in the following pattern:
412
442
  [source,yaml]
413
443
  ----
414
444
  users:
415
- - email: {Trac email or username}
445
+ {Trac email or username}:
446
+ email: {Github email}
416
447
  name: {name of the person}
417
448
  username: {username on GitHub}
418
449
  ...
@@ -423,10 +454,12 @@ EXAMPLE:
423
454
  [source,yaml]
424
455
  ----
425
456
  users:
426
- - email: matthew@example.org
457
+ matthew@gmail.org:
458
+ email: matthew@example.org
427
459
  name: Matthew
428
460
  username: example-matt
429
- - email: valencia
461
+ valencia:
462
+ email: valencia
430
463
  name: Valencia
431
464
  username: example-vale
432
465
  ----
@@ -434,7 +467,8 @@ users:
434
467
  If you don't want to map a user, you can just leave the `username` empty like below:
435
468
  ----
436
469
  users:
437
- - email: matthew@example.org
470
+ matthew@gmail.org:
471
+ email: matthew@example.org
438
472
  name: Matthew
439
473
  username:
440
474
  ----
data/config.example.yaml CHANGED
@@ -54,14 +54,38 @@ labels:
54
54
 
55
55
  # less useful, but also possible:
56
56
  priority:
57
- Low: '@low'
58
- High: '@high'
57
+ Low:
58
+ name: low
59
+ color: 22dd00
60
+ High:
61
+ name: high
62
+ color: ff0000
59
63
  severity:
60
- blocker: '#high'
61
- critical: '#critical'
62
- major: '#major'
63
- minor: '#minor'
64
- trivial: '#trivial'
64
+ trivial:
65
+ name: trivial
66
+ color: ff0000
67
+ major:
68
+ name: major
69
+ color: b44647
70
+ minor:
71
+ name: minor
72
+ color: f7347a
73
+ medium:
74
+ name: medium
75
+ color: f3c77c
76
+ tracstate:
77
+ accepted:
78
+ name: accepted
79
+ color: 22dd00
80
+ assigned:
81
+ name: assigned
82
+ color: aadd88
83
+ closed:
84
+ name: closed
85
+ color: ee00aa
86
+ new:
87
+ name: new
88
+ color:
65
89
  version:
66
90
  '1.3': v1.3
67
91
  '1.4': v1.4
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GithubApi
4
+ class Client
5
+ module Labels
6
+ def list_labels(repo, params = {})
7
+ JSON.parse(
8
+ RestClient.get(
9
+ "https://api.github.com/repos/#{repo}/labels",
10
+ {
11
+ "Authorization" => "token #{@token}",
12
+ params: params
13
+ }
14
+ )
15
+ )
16
+ end
17
+ alias labels list_labels
18
+
19
+ def create_label(repo, params)
20
+ JSON.parse(
21
+ RestClient.post(
22
+ "https://api.github.com/repos/#{repo}/labels",
23
+ params.to_json,
24
+ {
25
+ "Authorization" => "token #{@token}",
26
+ "Accept" => "application/vnd.github.v3+json"
27
+ }
28
+ )
29
+ )
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "client/issues"
4
+ require_relative "client/labels"
4
5
  require_relative "client/milestones"
5
6
 
6
7
  # Service to perform github actions
7
8
  module GithubApi
8
9
  class Client
9
10
  include GithubApi::Client::Issues
11
+ include GithubApi::Client::Labels
10
12
  include GithubApi::Client::Milestones
11
13
 
12
14
  def initialize(options = {})
data/lib/tractive/info.rb CHANGED
@@ -36,9 +36,9 @@ module Tractive
36
36
  "type" => Utilities.make_hash("type_", types),
37
37
  "component" => Utilities.make_hash("component_", components),
38
38
  "resolution" => Utilities.make_hash("resolution_", resolutions),
39
- "severity" => Utilities.make_hash("severity", severity),
40
- "priority" => Utilities.make_hash("priority_", priorities),
41
- "tracstate" => Utilities.make_hash("tracstate_", tracstates)
39
+ "severity" => Utilities.make_each_hash(severity, %w[name color]),
40
+ "priority" => Utilities.make_each_hash(priorities, %w[name color]),
41
+ "tracstate" => Utilities.make_each_hash(tracstates, %w[name color])
42
42
  }
43
43
  }
44
44
  end
data/lib/tractive/main.rb CHANGED
@@ -8,8 +8,6 @@ module Tractive
8
8
  @opts = opts
9
9
  @cfg = YAML.load_file(@opts[:config])
10
10
 
11
- @cfg["users"] = @cfg["users"].map { |user| [user["email"], user["username"]] }.to_h
12
-
13
11
  Tractive::Utilities.setup_logger(output_stream: @opts[:log_file] || $stderr, verbose: @opts[:verbose])
14
12
  @db = Tractive::Utilities.setup_db!(@cfg["trac"]["database"])
15
13
  rescue Sequel::DatabaseConnectionError, Sequel::AdapterNotFound, URI::InvalidURIError, Sequel::DatabaseError => e
@@ -17,6 +17,9 @@ module Migrator
17
17
  @wiki_attachments_url = args[:cfg]["trac"]["wiki_attachments_url"]
18
18
 
19
19
  load_milestone_map
20
+ create_labels_on_github(@labels_cfg["severity"].values)
21
+ create_labels_on_github(@labels_cfg["priority"].values)
22
+ create_labels_on_github(@labels_cfg["tracstate"].values)
20
23
 
21
24
  @uri_parser = URI::Parser.new
22
25
  @twf_to_markdown = Migrator::Converter::TwfToMarkdown.new(@tracticketbaseurl, @attachurl, @changeset_base_url, @wiki_attachments_url)
@@ -116,7 +119,8 @@ module Migrator
116
119
  # compose body
117
120
  body = [badgetable, body, footer].join("\n\n___\n")
118
121
 
119
- labels.add("owner:#{github_assignee}")
122
+ labels.add("name" => "owner:#{github_assignee}") unless github_assignee.nil? || github_assignee.empty?
123
+ labels = labels.map { |label| label["name"] }
120
124
 
121
125
  issue = {
122
126
  "title" => ticket[:summary],
@@ -129,7 +133,7 @@ module Migrator
129
133
 
130
134
  if @users.key?(ticket[:owner])
131
135
  owner = trac_mail(ticket[:owner])
132
- github_owner = @users[owner]
136
+ github_owner = @users[owner]["username"]
133
137
  $logger.debug("..owner in trac: #{owner}")
134
138
  $logger.debug("..assignee in GitHub: #{github_owner}")
135
139
  issue["assignee"] = github_owner
@@ -155,11 +159,11 @@ module Migrator
155
159
  private
156
160
 
157
161
  def map_user(user)
158
- @users[user] || user
162
+ @users.fetch(user, {})["email"] || user
159
163
  end
160
164
 
161
165
  def map_assignee(user)
162
- @users[user]
166
+ @users.fetch(user, {})["email"]
163
167
  end
164
168
 
165
169
  def load_milestone_map
@@ -168,9 +172,9 @@ module Migrator
168
172
  newmilestonekeys = @milestonesfromtrac.keys - @milestonemap.keys
169
173
 
170
174
  newmilestonekeys.each do |milestonelabel|
171
- milestone = {
175
+ milestone = {
172
176
  "title" => milestonelabel.to_s,
173
- "state" => @milestonesfromtrac[milestonelabel][:completed].nil? ? "open" : "closed",
177
+ "state" => @milestonesfromtrac[milestonelabel][:completed].to_i.zero? ? "open" : "closed",
174
178
  "description" => @milestonesfromtrac[milestonelabel][:description] || "no description in trac",
175
179
  "due_on" => "2012-10-09T23:39:01Z"
176
180
  }
@@ -194,6 +198,21 @@ module Migrator
194
198
  nil
195
199
  end
196
200
 
201
+ def create_labels_on_github(labels)
202
+ return if labels.nil? || labels.empty?
203
+
204
+ existing_labels = @client.labels(@repo).map { |label| label["name"] }
205
+ new_labels = labels.reject { |label| existing_labels.include?(label["name"]) }
206
+
207
+ new_labels.each do |label|
208
+ params = { name: label["name"] }
209
+ params["color"] = label["color"] unless label["color"].nil?
210
+
211
+ @client.create_label(@repo, params)
212
+ $logger.info("Created label: #{label["name"]}")
213
+ end
214
+ end
215
+
197
216
  def ticket_change(append, meta)
198
217
  # kind
199
218
  kind = if meta[:ticket]
@@ -19,8 +19,11 @@ module Tractive
19
19
  def filter_column(options)
20
20
  return self if options.nil? || options.values.compact.empty?
21
21
 
22
- if options[:operator].downcase == "like"
22
+ case options[:operator].downcase
23
+ when "like"
23
24
  where { Sequel.like(options[:column_name].to_sym, options[:column_value]) }
25
+ when "not like"
26
+ where { ~Sequel.like(options[:column_name].to_sym, options[:column_value]) }
24
27
  else
25
28
  where { Sequel.lit("#{options[:column_name]} #{options[:operator]} '#{options[:column_value]}'") }
26
29
  end
@@ -10,8 +10,8 @@ module Tractive
10
10
  def make_each_hash(values, keys)
11
11
  values.map do |value|
12
12
  value = [value] unless value.is_a?(Array)
13
- keys.zip(value).to_h
14
- end
13
+ [value[0], keys.zip(value).to_h]
14
+ end.to_h
15
15
  end
16
16
 
17
17
  def setup_db!(db_url)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tractive
4
- VERSION = "1.0.3"
4
+ VERSION = "1.0.4"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tractive
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-15 00:00:00.000000000 Z
11
+ date: 2021-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mysql2
@@ -140,6 +140,7 @@ files:
140
140
  - lib/tractive/github_api.rb
141
141
  - lib/tractive/github_api/client.rb
142
142
  - lib/tractive/github_api/client/issues.rb
143
+ - lib/tractive/github_api/client/labels.rb
143
144
  - lib/tractive/github_api/client/milestones.rb
144
145
  - lib/tractive/graceful_quit.rb
145
146
  - lib/tractive/info.rb