tractive 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db1fec86bca93ac81ac4ce8c4f1e6fb99f0983743c55fc3275a95188c8178e0e
4
- data.tar.gz: f2907430c9a64b4cd5e0004050c1d7eddf11a18f94a4a007bf5315706a73e23b
3
+ metadata.gz: fdbed889bbd1a1727140d2f1a537141b67199f956448952df2b6ac6ebf8976ca
4
+ data.tar.gz: 3e211800b03fc1b8eeeb268c9198de662e8ef3cba0a3301231b278bee15e400f
5
5
  SHA512:
6
- metadata.gz: 1828a51469e9418188cd72195b51b245bb47921b7fbc883287bd089f9b2da58d18fbf08411c9f5cc33ed4a4a92259e365931afe281e1cf810a16c97a0632fa1a
7
- data.tar.gz: f898f265b58c41ca3ae59ee20cf52ec50ced92045a1595f23ea50e66bb4b0bd911a8695cfdc34b3a41a248a8b11bcb3a20be70eb8193aba8a7867c3f9ba4cc1e
6
+ metadata.gz: fd5f9acbc163d4509d2b75a61d64071cfee00c6167e6c709710f66999ece41e3d343fa0664c192a427a85fde02666d41a14f9618557fac1781acf26d8dd11349
7
+ data.tar.gz: '081c6dc2373891c5190a6e43f93822174082990e37e253e110ccba0ed9801e13b425ec2e188ef512a75a0de0d955e96134946c7a6ae55f0331aa3f53cd88fdfd'
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ Gemfile.lock
data/.rubocop.yml CHANGED
@@ -25,6 +25,9 @@ Style/Documentation:
25
25
  Style/GlobalVars:
26
26
  Enabled: false
27
27
 
28
+ Style/HashTransformKeys:
29
+ Enabled: false
30
+
28
31
  Metrics/AbcSize:
29
32
  Enabled: false
30
33
 
data/README.adoc CHANGED
@@ -297,6 +297,8 @@ trac:
297
297
  ticketbaseurl: https://example.org/trac/foobar/ticket
298
298
  ----
299
299
 
300
+ `ticketbaseurl:`::: The Trac Url which will be added in Github issues. A link will be added in the footer of Github issue to link it to Trac ticket.
301
+
300
302
  [[config-github]]
301
303
  ==== GitHub configuration
302
304
 
data/lib/tractive/info.rb CHANGED
@@ -34,8 +34,8 @@ module Tractive
34
34
  "milestones" => milestones,
35
35
  "labels" => {
36
36
  "type" => Utilities.make_hash("type_", types),
37
- "component" => Utilities.make_hash("component_", components),
38
37
  "resolution" => Utilities.make_hash("resolution_", resolutions),
38
+ "component" => Utilities.make_each_hash(components, %w[name color], "component: "),
39
39
  "severity" => Utilities.make_each_hash(severity, %w[name color]),
40
40
  "priority" => Utilities.make_each_hash(priorities, %w[name color]),
41
41
  "tracstate" => Utilities.make_each_hash(tracstates, %w[name color])
data/lib/tractive/main.rb CHANGED
@@ -8,7 +8,7 @@ module Tractive
8
8
  @opts = opts
9
9
  @cfg = YAML.load_file(@opts[:config])
10
10
 
11
- Tractive::Utilities.setup_logger(output_stream: @opts[:log_file] || $stderr, verbose: @opts[:verbose])
11
+ Tractive::Utilities.setup_logger(output_stream: @opts[:logfile] || $stderr, verbose: @opts[:verbose])
12
12
  @db = Tractive::Utilities.setup_db!(@cfg["trac"]["database"])
13
13
  rescue Sequel::DatabaseConnectionError, Sequel::AdapterNotFound, URI::InvalidURIError, Sequel::DatabaseError => e
14
14
  $logger.error e.message
@@ -6,7 +6,7 @@ module Migrator
6
6
  def initialize(args)
7
7
  @tracticketbaseurl = args[:cfg]["trac"]["ticketbaseurl"]
8
8
  @attachurl = args[:opts][:attachurl] || args[:cfg].dig("attachments", "url")
9
- @changeset_base_url = args[:cfg]["trac"]["changeset_base_url"]
9
+ @changeset_base_url = args[:cfg]["trac"]["changeset_base_url"] || ""
10
10
  @singlepost = args[:opts][:singlepost]
11
11
  @labels_cfg = args[:cfg]["labels"].transform_values(&:to_h)
12
12
  @milestonesfromtrac = args[:cfg]["milestones"]
@@ -15,14 +15,16 @@ module Migrator
15
15
  @repo = args[:cfg]["github"]["repo"]
16
16
  @client = GithubApi::Client.new(access_token: args[:cfg]["github"]["token"])
17
17
  @wiki_attachments_url = args[:cfg]["trac"]["wiki_attachments_url"]
18
+ @revmap_file_path = args[:opts][:revmapfile] || args[:cfg]["revmap_path"]
18
19
 
19
20
  load_milestone_map
20
21
  create_labels_on_github(@labels_cfg["severity"].values)
21
22
  create_labels_on_github(@labels_cfg["priority"].values)
22
23
  create_labels_on_github(@labels_cfg["tracstate"].values)
24
+ create_labels_on_github(@labels_cfg["component"].values)
23
25
 
24
26
  @uri_parser = URI::Parser.new
25
- @twf_to_markdown = Migrator::Converter::TwfToMarkdown.new(@tracticketbaseurl, @attachurl, @changeset_base_url, @wiki_attachments_url)
27
+ @twf_to_markdown = Migrator::Converter::TwfToMarkdown.new(@tracticketbaseurl, @attachurl, @changeset_base_url, @wiki_attachments_url, @revmap_file_path)
26
28
  end
27
29
 
28
30
  def compose(ticket)
@@ -77,7 +79,6 @@ module Migrator
77
79
 
78
80
  badges = Set[]
79
81
 
80
- badges.add(@labels_cfg.fetch("component", {})[ticket[:component]])
81
82
  badges.add(@labels_cfg.fetch("type", {})[ticket[:type]])
82
83
  badges.add(@labels_cfg.fetch("resolution", {})[ticket[:resolution]])
83
84
  badges.add(@labels_cfg.fetch("version", {})[ticket[:version]])
@@ -85,6 +86,8 @@ module Migrator
85
86
  labels.add(@labels_cfg.fetch("severity", {})[ticket[:severity]])
86
87
  labels.add(@labels_cfg.fetch("priority", {})[ticket[:priority]])
87
88
  labels.add(@labels_cfg.fetch("tracstate", {})[ticket[:status]])
89
+ labels.add(@labels_cfg.fetch("component", {})[ticket[:component]])
90
+
88
91
  labels.delete(nil)
89
92
 
90
93
  keywords = ticket[:keywords]
@@ -100,7 +103,7 @@ module Migrator
100
103
  milestone = @milestonemap[ticket[:milestone]]
101
104
 
102
105
  # compute footer
103
- footer = "_Issue migrated from trac:#{ticket[:id]} at #{Time.now}_"
106
+ footer = "_Issue migrated from #{trac_ticket_link(ticket)} at #{Time.now}_"
104
107
 
105
108
  # compute badgetabe
106
109
  #
@@ -202,7 +205,7 @@ module Migrator
202
205
  return if labels.nil? || labels.empty?
203
206
 
204
207
  existing_labels = @client.labels(@repo, per_page: 100).map { |label| label["name"] }
205
- new_labels = labels.reject { |label| existing_labels.include?(label["name"]) }
208
+ new_labels = labels.reject { |label| existing_labels.include?(label["name"]&.strip) }
206
209
 
207
210
  new_labels.each do |label|
208
211
  params = { name: label["name"] }
@@ -262,7 +265,7 @@ module Migrator
262
265
  changeset = body.match(/In \[changeset:"(\d+)/).to_a[1]
263
266
  text += if changeset
264
267
  # changesethash = @revmap[changeset]
265
- "_committed #{Tractive::Utilities.map_changeset(changeset)}_"
268
+ "_committed #{Tractive::Utilities.map_changeset(changeset, @revmap, @changeset_base_url)}_"
266
269
  else
267
270
  "_commented_\n\n"
268
271
  end
@@ -321,6 +324,12 @@ module Migrator
321
324
  !(%w[keywords cc reporter version].include?(kind) ||
322
325
  (kind == "comment" && (newvalue.nil? || newvalue.lstrip.empty?)))
323
326
  end
327
+
328
+ def trac_ticket_link(ticket)
329
+ return "trac:#{ticket[:id]}" unless @tracticketbaseurl
330
+
331
+ "[trac:#{ticket[:id]}](#{@tracticketbaseurl}/#{ticket[:id]})"
332
+ end
324
333
  end
325
334
  end
326
335
  end
@@ -4,11 +4,12 @@ module Migrator
4
4
  module Converter
5
5
  # twf => Trac wiki format
6
6
  class TwfToMarkdown
7
- def initialize(base_url, attach_url, changeset_base_url, wiki_attachments_url)
7
+ def initialize(base_url, attach_url, changeset_base_url, wiki_attachments_url, revmap_file_path)
8
8
  @base_url = base_url
9
9
  @attach_url = attach_url
10
10
  @changeset_base_url = changeset_base_url
11
11
  @wiki_attachments_url = wiki_attachments_url
12
+ @revmap = load_revmap_file(revmap_file_path)
12
13
  end
13
14
 
14
15
  def convert(str)
@@ -26,6 +27,24 @@ module Migrator
26
27
 
27
28
  private
28
29
 
30
+ def load_revmap_file(revmapfile)
31
+ # load revision mapping file and convert it to a hash.
32
+ # This revmap file allows to map between SVN revisions (rXXXX)
33
+ # and git commit sha1 hashes.
34
+ revmap = nil
35
+ if revmapfile
36
+ File.open(revmapfile, "r:UTF-8") do |f|
37
+ $logger.info("loading revision map #{revmapfile}")
38
+
39
+ revmap = f.each_line
40
+ .map { |line| line.split(/\s+\|\s+/) }
41
+ .map { |rev, sha| [rev.gsub(/^r/, ""), sha] }.to_h # remove leading "r" if present
42
+ end
43
+ end
44
+
45
+ revmap
46
+ end
47
+
29
48
  # CommitTicketReference
30
49
  def convert_ticket_reference(str)
31
50
  str.gsub!(/\{\{\{\n(#!CommitTicketReference .+?)\}\}\}/m, '\1')
@@ -72,9 +91,10 @@ module Migrator
72
91
  str.gsub!(%r{#{Regexp.quote(changeset_base_url)}/(\d+)/?}, '[changeset:\1]') if changeset_base_url
73
92
  str.gsub!(/\[changeset:"r(\d+)".*\]/, '[changeset:\1]')
74
93
  str.gsub!(/\[changeset:r(\d+)\]/, '[changeset:\1]')
75
- str.gsub!(/\br(\d+)\b/) { Tractive::Utilities.map_changeset(Regexp.last_match[1]) }
76
- str.gsub!(/\[changeset:"(\d+)".*\]/) { Tractive::Utilities.map_changeset(Regexp.last_match[1]) }
77
- str.gsub!(/\[changeset:"(\d+).*\]/) { Tractive::Utilities.map_changeset(Regexp.last_match[1]) }
94
+ str.gsub!(/\br(\d+)\b/) { Tractive::Utilities.map_changeset(Regexp.last_match[1], @revmap, changeset_base_url) }
95
+ str.gsub!(/\[changeset:"(\d+)".*\]/) { Tractive::Utilities.map_changeset(Regexp.last_match[1], @revmap, changeset_base_url) }
96
+ str.gsub!(/\[changeset:(\d+).*\]/) { Tractive::Utilities.map_changeset(Regexp.last_match[1], @revmap, changeset_base_url) }
97
+ str.gsub!(/\[(\d+)\]/) { Tractive::Utilities.map_changeset(Regexp.last_match[1], @revmap, changeset_base_url) }
78
98
  end
79
99
 
80
100
  # Font styles
@@ -87,7 +87,7 @@ module Migrator
87
87
 
88
88
  revmap = f.each_line
89
89
  .map { |line| line.split(/\s+\|\s+/) }
90
- .map { |rev, sha, _| [rev.gsub(/^r/, ""), sha] }.to_h # remove leading "r" if present
90
+ .map { |rev, sha| [rev.gsub(/^r/, ""), sha] }.to_h # remove leading "r" if present
91
91
  end
92
92
  end
93
93
 
@@ -7,10 +7,10 @@ module Tractive
7
7
  array.map { |i| [i, "#{prefix}#{i}"] }.to_h
8
8
  end
9
9
 
10
- def make_each_hash(values, keys)
10
+ def make_each_hash(values, keys, prefix = "")
11
11
  values.map do |value|
12
12
  value = [value] unless value.is_a?(Array)
13
- [value[0], keys.zip(value).to_h]
13
+ [value[0], keys.zip(value.map { |v| "#{prefix}#{v}" }).to_h]
14
14
  end.to_h
15
15
  end
16
16
 
@@ -45,11 +45,13 @@ module Tractive
45
45
  end
46
46
 
47
47
  # returns the git commit hash for a specified revision (using revmap hash)
48
- def map_changeset(str)
49
- if @revmap&.key?(str)
50
- "[r#{str}](../commit/#{@revmap[str]}) #{@revmap[str]}"
48
+ def map_changeset(str, revmap, changeset_base_url = "")
49
+ if revmap&.key?(str)
50
+ base_url = changeset_base_url
51
+ base_url += "/" if base_url[-1] && base_url[-1] != "/"
52
+ "#{base_url}#{revmap[str].strip}"
51
53
  else
52
- str
54
+ "[#{str}]"
53
55
  end
54
56
  end
55
57
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tractive
4
- VERSION = "1.0.5"
4
+ VERSION = "1.0.6"
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.5
4
+ version: 1.0.6
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-21 00:00:00.000000000 Z
11
+ date: 2021-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mysql2
@@ -124,7 +124,6 @@ files:
124
124
  - ".ruby-version"
125
125
  - CODE_OF_CONDUCT.md
126
126
  - Gemfile
127
- - Gemfile.lock
128
127
  - LICENSE.md
129
128
  - README.adoc
130
129
  - Rakefile
data/Gemfile.lock DELETED
@@ -1,100 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- tractive (1.0.5)
5
- mysql2
6
- ox
7
- rest-client
8
- sequel
9
- sqlite3
10
- thor
11
-
12
- GEM
13
- remote: https://rubygems.org/
14
- specs:
15
- addressable (2.8.0)
16
- public_suffix (>= 2.0.2, < 5.0)
17
- ast (2.4.2)
18
- coderay (1.1.3)
19
- crack (0.4.5)
20
- rexml
21
- diff-lcs (1.4.4)
22
- domain_name (0.5.20190701)
23
- unf (>= 0.0.5, < 1.0.0)
24
- hashdiff (1.0.1)
25
- http-accept (1.7.0)
26
- http-cookie (1.0.4)
27
- domain_name (~> 0.5)
28
- method_source (1.0.0)
29
- mime-types (3.3.1)
30
- mime-types-data (~> 3.2015)
31
- mime-types-data (3.2021.0901)
32
- mysql2 (0.5.3)
33
- netrc (0.11.0)
34
- ox (2.14.5)
35
- parallel (1.21.0)
36
- parser (3.0.2.0)
37
- ast (~> 2.4.1)
38
- pry (0.14.1)
39
- coderay (~> 1.1)
40
- method_source (~> 1.0)
41
- public_suffix (4.0.6)
42
- rainbow (3.0.0)
43
- rake (13.0.6)
44
- regexp_parser (2.1.1)
45
- rest-client (2.1.0)
46
- http-accept (>= 1.7.0, < 2.0)
47
- http-cookie (>= 1.0.2, < 2.0)
48
- mime-types (>= 1.16, < 4.0)
49
- netrc (~> 0.8)
50
- rexml (3.2.5)
51
- rspec (3.10.0)
52
- rspec-core (~> 3.10.0)
53
- rspec-expectations (~> 3.10.0)
54
- rspec-mocks (~> 3.10.0)
55
- rspec-core (3.10.1)
56
- rspec-support (~> 3.10.0)
57
- rspec-expectations (3.10.1)
58
- diff-lcs (>= 1.2.0, < 2.0)
59
- rspec-support (~> 3.10.0)
60
- rspec-mocks (3.10.2)
61
- diff-lcs (>= 1.2.0, < 2.0)
62
- rspec-support (~> 3.10.0)
63
- rspec-support (3.10.2)
64
- rubocop (1.22.1)
65
- parallel (~> 1.10)
66
- parser (>= 3.0.0.0)
67
- rainbow (>= 2.2.2, < 4.0)
68
- regexp_parser (>= 1.8, < 3.0)
69
- rexml
70
- rubocop-ast (>= 1.12.0, < 2.0)
71
- ruby-progressbar (~> 1.7)
72
- unicode-display_width (>= 1.4.0, < 3.0)
73
- rubocop-ast (1.12.0)
74
- parser (>= 3.0.1.1)
75
- ruby-progressbar (1.11.0)
76
- sequel (5.49.0)
77
- sqlite3 (1.4.2)
78
- thor (1.1.0)
79
- unf (0.1.4)
80
- unf_ext
81
- unf_ext (0.0.8)
82
- unicode-display_width (2.1.0)
83
- webmock (3.14.0)
84
- addressable (>= 2.8.0)
85
- crack (>= 0.3.2)
86
- hashdiff (>= 0.4.0, < 2.0.0)
87
-
88
- PLATFORMS
89
- ruby
90
-
91
- DEPENDENCIES
92
- pry
93
- rake (~> 13.0)
94
- rspec (~> 3.0)
95
- rubocop (~> 1.7)
96
- tractive!
97
- webmock (~> 3.14)
98
-
99
- BUNDLED WITH
100
- 2.1.2