tractive 1.0.8 → 1.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -0
- data/README.adoc +88 -16
- data/db/trac-test.db +0 -0
- data/exe/command_base.rb +11 -0
- data/exe/generate.rb +49 -0
- data/exe/tractive +25 -51
- data/lib/tractive/attachment_exporter.rb +4 -3
- data/lib/tractive/github_api/client/issues.rb +6 -6
- data/lib/tractive/github_api/client/labels.rb +2 -2
- data/lib/tractive/github_api/client/milestones.rb +2 -2
- data/lib/tractive/github_api/client.rb +2 -0
- data/lib/tractive/http/client/request.rb +59 -0
- data/lib/tractive/http/client.rb +3 -0
- data/lib/tractive/main.rb +5 -1
- data/lib/tractive/migrator/converter/trac_to_github.rb +27 -12
- data/lib/tractive/migrator/converter/twf_to_markdown.rb +228 -36
- data/lib/tractive/migrator/engine.rb +4 -3
- data/lib/tractive/migrator/wikis/migrate_from_db.rb +167 -0
- data/lib/tractive/migrator/wikis.rb +3 -0
- data/lib/tractive/migrator.rb +1 -0
- data/lib/tractive/models/attachment.rb +1 -0
- data/lib/tractive/models/ticket.rb +16 -8
- data/lib/tractive/models/wiki.rb +18 -0
- data/lib/tractive/trac.rb +2 -1
- data/lib/tractive/utilities.rb +18 -2
- data/lib/tractive/version.rb +1 -1
- data/lib/tractive.rb +1 -0
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07fb75035716d30de8f58206ad93cd0b932d74807646d5577d519d848eb2bfa0
|
4
|
+
data.tar.gz: c4e50252da3aaf67b919041cdc682e8559abb28163dd847671d30c91808d15e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efc63d0e9e8b08d3780cccd3877554c7a1df4408cd8db3c5bcf4fd11634eab73ac7f29fa300fb9191e77a892ba5d795c80e0d1a5a97283e6c541370372ef5725
|
7
|
+
data.tar.gz: b1dc726435943c2b0cf70f369c21ffd049d07e13147a5d88f162dc725fb1ad7d62a8a034b2adb05903cc9e393dd421497af457fbaf2ad8cf45684b783b63b5ba
|
data/.rubocop.yml
CHANGED
@@ -18,6 +18,7 @@ Metrics/ClassLength:
|
|
18
18
|
|
19
19
|
Metrics/BlockLength:
|
20
20
|
Max: 500
|
21
|
+
IgnoredMethods: ['describe']
|
21
22
|
|
22
23
|
Style/Documentation:
|
23
24
|
Enabled: false
|
@@ -34,6 +35,12 @@ Metrics/AbcSize:
|
|
34
35
|
Metrics/MethodLength:
|
35
36
|
Enabled: false
|
36
37
|
|
38
|
+
Metrics/ModuleLength:
|
39
|
+
Max: 150
|
40
|
+
|
41
|
+
Metrics/ParameterLists:
|
42
|
+
Max: 6
|
43
|
+
|
37
44
|
Security/Open:
|
38
45
|
Enabled: false
|
39
46
|
|
data/README.adoc
CHANGED
@@ -174,7 +174,7 @@ With this information you can now build the RevMap with:
|
|
174
174
|
|
175
175
|
[source,sh]
|
176
176
|
----
|
177
|
-
tractive generate
|
177
|
+
tractive generate revmap \
|
178
178
|
--svn-url <url of the SVN repository> \
|
179
179
|
--rev-timestamp-file <reposurgeon timestamp map, e.g. {name-of-repo}.fo> \
|
180
180
|
--git-local-repo-path <path to converted Git repository, e.g. {name-of-repo}-git> \
|
@@ -186,7 +186,7 @@ issues and commits will replace references to SVN revisions with the
|
|
186
186
|
corresponding Git commit SHA, enabling GitHub to expose those linkages in the
|
187
187
|
user interface.
|
188
188
|
|
189
|
-
.Options for `tractive generate
|
189
|
+
.Options for `tractive generate revmap` command
|
190
190
|
[cols="3a,5a,2a",options="header"]
|
191
191
|
|===
|
192
192
|
| Option | Description | Type
|
@@ -315,7 +315,7 @@ e.g. 'ghp_fpsc4de1f0c46e01576810740c9242097cba4619486'.
|
|
315
315
|
e.g. '/Users/user/repo-git'.
|
316
316
|
|
317
317
|
`revmap_path:`::: Local path to the RevMap file generated via the
|
318
|
-
`tractive generate
|
318
|
+
`tractive generate revmap` command.
|
319
319
|
|
320
320
|
|
321
321
|
EXAMPLE:
|
@@ -326,7 +326,8 @@ github:
|
|
326
326
|
repo: 'example-org/target-repository'
|
327
327
|
token: 'ghp_fpsc4de1f0c46e01576810740c9242097cba4619486'
|
328
328
|
local_repo_path: '/Users/user/repo-git'
|
329
|
-
|
329
|
+
|
330
|
+
revmap_path: ./example-revmap.txt
|
330
331
|
----
|
331
332
|
|
332
333
|
|
@@ -359,8 +360,12 @@ The pattern of a mapping is like:
|
|
359
360
|
+
|
360
361
|
[source,yaml]
|
361
362
|
----
|
362
|
-
configuration:
|
363
|
-
|
363
|
+
configuration:
|
364
|
+
name: conf
|
365
|
+
color: ff00ff
|
366
|
+
documentation:
|
367
|
+
name: doc
|
368
|
+
color: 00ff00
|
364
369
|
----
|
365
370
|
|
366
371
|
`resolution:`::: Resolution of the Trac ticket. e.g.
|
@@ -433,7 +438,7 @@ The pattern of a mapping is like:
|
|
433
438
|
----
|
434
439
|
|
435
440
|
|
436
|
-
NOTE: As `severity`, `priority` and `tracstate` are converted into `labels` on github so there is an option to specify the `color` for those labels.
|
441
|
+
NOTE: As `component`, `severity`, `priority` and `tracstate` are converted into `labels` on github so there is an option to specify the `color` for those labels.
|
437
442
|
|
438
443
|
|
439
444
|
==== User mapping
|
@@ -499,22 +504,32 @@ milestones:
|
|
499
504
|
|
500
505
|
|
501
506
|
==== Attachments migration configuration
|
507
|
+
`ticket | wiki:`:: specifies the options for the tickets or wikis
|
508
|
+
|
509
|
+
`attachments:`::: specifies method of obtaining attachments from Trac.
|
502
510
|
|
503
|
-
`
|
511
|
+
`url:`:::: URL to obtain Trac attachments from
|
504
512
|
|
505
|
-
`url
|
513
|
+
`hashed:`:::: Whether the url has hased or plain image names and ids
|
506
514
|
|
507
|
-
`export_folder
|
515
|
+
`export_folder:`:::: folder where the attachments will be downloaded to from Trac.
|
508
516
|
|
509
|
-
`export_script
|
510
|
-
all attachments from Trac.
|
517
|
+
`export_script:`:::: output of a script that utilizes `trac-admin` to download
|
518
|
+
all attachments from Trac.
|
511
519
|
|
512
520
|
[source,yaml]
|
513
521
|
----
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
522
|
+
ticket:
|
523
|
+
attachments:
|
524
|
+
url: https://abc.com/raw-attachment/ticket
|
525
|
+
hashed: true
|
526
|
+
export_folder: ./attachments
|
527
|
+
export_script: attachments.sh
|
528
|
+
|
529
|
+
wiki:
|
530
|
+
attachments:
|
531
|
+
url: https://abc.com/raw-attachment/wiki
|
532
|
+
hashed: true
|
518
533
|
----
|
519
534
|
|
520
535
|
By using the <<gather-info,`-i` option>>, you can easily produce a YAML file
|
@@ -682,6 +697,7 @@ The following options are allowed (at least one necessary):
|
|
682
697
|
* `column-name`
|
683
698
|
* `operator`
|
684
699
|
* `column-value`
|
700
|
+
* `include-null`
|
685
701
|
|
686
702
|
| Boolean
|
687
703
|
|
@@ -697,6 +713,10 @@ The following options are allowed (at least one necessary):
|
|
697
713
|
| Value of the column to filter.
|
698
714
|
| String
|
699
715
|
|
716
|
+
| `--include-null`
|
717
|
+
| Include rows having null value in filtered column.
|
718
|
+
| Boolean
|
719
|
+
|
700
720
|
| `-h`, `help`
|
701
721
|
| Display the Tractive help message, or you can provide a command to know more
|
702
722
|
about a single command via `tractive help {command}`.
|
@@ -741,6 +761,58 @@ The following options are allowed (at least one necessary):
|
|
741
761
|
|===
|
742
762
|
|
743
763
|
|
764
|
+
=== Migrating Wikis
|
765
|
+
|
766
|
+
You need the following for wiki migration
|
767
|
+
|
768
|
+
* Clone of the github wiki repo.
|
769
|
+
|
770
|
+
Then you can run the migration with:
|
771
|
+
|
772
|
+
[source,sh]
|
773
|
+
----
|
774
|
+
tractive migrate-wikis \
|
775
|
+
--attachment-base-url <url for the attachments> \
|
776
|
+
--trac-database-path <full path of trac database> \
|
777
|
+
--repo-path <path to cloned Git wiki repository, e.g. {name-of-repo}.wiki>
|
778
|
+
----
|
779
|
+
|
780
|
+
After that open a terminal in the git wiki folder and run `git push`
|
781
|
+
|
782
|
+
.Options for `tractive migrate-wikis` command
|
783
|
+
[cols="3a,5a,2a",options="header"]
|
784
|
+
|===
|
785
|
+
| Option | Description | Type
|
786
|
+
|
787
|
+
| `a`, `--attachment-base-url`
|
788
|
+
|
|
789
|
+
(required unless specified in config file)
|
790
|
+
If attachment files are reachable via a URL we reference this here.
|
791
|
+
| String
|
792
|
+
|
793
|
+
| `-d`, `--trac-database-path`
|
794
|
+
| (required unless specified in config file) Full path of the Trac sqlite3 database export file.
|
795
|
+
| String
|
796
|
+
|
797
|
+
| `-r`, `--repo-path`
|
798
|
+
| (required) Full path to the root of the git-repository that is our destination.
|
799
|
+
| String
|
800
|
+
|
801
|
+
| `-c`, `--config`
|
802
|
+
| Path to config file.
|
803
|
+
| String
|
804
|
+
|
805
|
+
| `-e`, `--wiki-extensions`
|
806
|
+
| Space separated list of extensions or filenames (if the file don't have an extension). This is required to convert file SVN source links to Github links. This is used to determine if a path belongs to a file or a directory.
|
807
|
+
| Array
|
808
|
+
|
809
|
+
| `-f`, `--source-folders`
|
810
|
+
| Space separated list of non standard folders in SVN that are used to find if a path is complete or partial.
|
811
|
+
| Array
|
812
|
+
|
813
|
+
|===
|
814
|
+
|
815
|
+
|
744
816
|
== Implementation details
|
745
817
|
|
746
818
|
=== Usage of GitHub Issue Import API
|
data/db/trac-test.db
CHANGED
Binary file
|
data/exe/command_base.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../lib/tractive"
|
4
|
+
|
5
|
+
class CommandBase < Thor
|
6
|
+
class_option "logfile", type: :string, aliases: ["-L", "--log-file"],
|
7
|
+
desc: "Name of the logfile to output logs to."
|
8
|
+
class_option "config", type: :string, default: "tractive.config.yaml", banner: "<PATH>", aliases: "-c",
|
9
|
+
desc: "Set the configuration file"
|
10
|
+
class_option "verbose", type: :boolean, aliases: ["-v", "--verbose"], desc: "Verbose mode"
|
11
|
+
end
|
data/exe/generate.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "./command_base"
|
4
|
+
|
5
|
+
class Generate < CommandBase
|
6
|
+
desc "revmap <OPTIONS>", "Generate a mapping from svn revision number to git sha hash."
|
7
|
+
method_option "svnurl", type: :string, aliases: ["--svn-url"],
|
8
|
+
desc: "Svn url that should be used in revmap generation"
|
9
|
+
method_option "svnlocalpath", type: :string, aliases: ["--svn-local-path"],
|
10
|
+
desc: "Local SVN repo path"
|
11
|
+
method_option "gitlocalrepopath", type: :string, aliases: ["--git-local-repo-path"],
|
12
|
+
desc: "Local git repo path that should be used in revmap generation"
|
13
|
+
method_option "revtimestampfile", type: :string, aliases: ["--rev-timestamp-file"],
|
14
|
+
desc: "File containing svn revision and timestamps that should be used in revmap generation"
|
15
|
+
method_option "revoutputfile", type: :string, aliases: ["--revmap-output-file"],
|
16
|
+
desc: "File to output the generated revmap"
|
17
|
+
def revmap
|
18
|
+
verify_revmap_generator_options!(options)
|
19
|
+
|
20
|
+
Tractive::Utilities.setup_logger(output_stream: options[:log_file] || $stderr, verbose: options[:verbose])
|
21
|
+
Tractive::RevmapGenerator.new(
|
22
|
+
options["revtimestampfile"],
|
23
|
+
options["svnurl"],
|
24
|
+
options["svnlocalpath"],
|
25
|
+
options["gitlocalrepopath"],
|
26
|
+
options["revoutputfile"]
|
27
|
+
).generate
|
28
|
+
end
|
29
|
+
|
30
|
+
no_commands do
|
31
|
+
def verify_revmap_generator_options!(options)
|
32
|
+
required_options = {}
|
33
|
+
required_options["--svn-url OR --svn-local-path"] = options["svnurl"] || options["svnlocalpath"]
|
34
|
+
required_options["--git-local-repo-path"] = options["gitlocalrepopath"]
|
35
|
+
required_options["--rev-timestamp-file"] = options["revtimestampfile"]
|
36
|
+
required_options["--revmap-output-file"] = options["revoutputfile"]
|
37
|
+
|
38
|
+
missing_options = {}
|
39
|
+
required_options.each do |key, value|
|
40
|
+
missing_options[key] = value if value.nil? || value.strip.empty?
|
41
|
+
end
|
42
|
+
|
43
|
+
return if missing_options.empty?
|
44
|
+
|
45
|
+
warn("missing revmap generator options (#{missing_options.keys}).\nRun with `--help` or `-h` to see available options")
|
46
|
+
exit 1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/exe/tractive
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require_relative "
|
4
|
+
require_relative "./command_base"
|
5
|
+
require_relative "./generate"
|
5
6
|
|
6
|
-
class TractiveCommand <
|
7
|
-
default_command :
|
8
|
-
|
9
|
-
|
7
|
+
class TractiveCommand < CommandBase
|
8
|
+
default_command :migrate_tickets
|
9
|
+
|
10
|
+
desc "generate", "Generate different files/scripts"
|
11
|
+
subcommand "generate", Generate
|
10
12
|
|
11
13
|
desc "<OPTIONS>", "Migrate Trac instances to modern Git management platforms like GitHub and GitLab"
|
12
14
|
method_option "attachmentexporter", type: :string, aliases: ["-A", "--attachment-exporter"],
|
13
15
|
desc: "Generate an attachment exporter script according to config.yaml"
|
14
16
|
method_option "attachurl", type: :string, aliases: ["-a", "--attachment-url"], banner: "<URL>",
|
15
17
|
desc: "If attachment files are reachable via a URL we reference this here"
|
16
|
-
method_option "config", type: :string, default: "tractive.config.yaml", banner: "<PATH>", aliases: "-c",
|
17
|
-
desc: "Set the configuration file"
|
18
18
|
method_option "dryrun", type: :boolean, aliases: ["-d", "--dry-run"],
|
19
19
|
desc: "Write data to a file instead of pushing it to github"
|
20
20
|
method_option "exportattachments", type: :string, aliases: ["-e", "--export-attachments"],
|
@@ -30,6 +30,8 @@ class TractiveCommand < Thor
|
|
30
30
|
desc: "Operator for filter."
|
31
31
|
method_option "columnvalue", type: :string, aliases: ["--column-value"],
|
32
32
|
desc: "Value of the column to filter."
|
33
|
+
method_option "includenull", type: :boolean, aliases: ["--include-null"],
|
34
|
+
desc: "Flag for including null values in the filter result."
|
33
35
|
|
34
36
|
method_option "importfromfile", type: :string, aliases: ["-I", "--import-from-file"],
|
35
37
|
desc: "Import issues from a json file"
|
@@ -45,33 +47,25 @@ class TractiveCommand < Thor
|
|
45
47
|
desc: "Put all issue comments in the first message."
|
46
48
|
method_option "start", type: :numeric, aliases: ["-s", "--start-at"], banner: "<ID>",
|
47
49
|
desc: "Start migration from ticket with number <ID>"
|
48
|
-
|
49
|
-
def migrate
|
50
|
+
def migrate_tickets
|
50
51
|
Tractive::Main.new(options).run
|
51
52
|
end
|
52
53
|
|
53
|
-
desc "
|
54
|
-
method_option "
|
55
|
-
|
56
|
-
method_option "
|
57
|
-
|
58
|
-
method_option "
|
59
|
-
|
60
|
-
method_option "
|
61
|
-
|
62
|
-
method_option "
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
Tractive::
|
68
|
-
Tractive::RevmapGenerator.new(
|
69
|
-
options["revtimestampfile"],
|
70
|
-
options["svnurl"],
|
71
|
-
options["svnlocalpath"],
|
72
|
-
options["gitlocalrepopath"],
|
73
|
-
options["revoutputfile"]
|
74
|
-
).generate
|
54
|
+
desc "migrate-wikis", "Migrate Trac wikis to a git repository, preserving history (including authors, dates, and comments)"
|
55
|
+
method_option "attachment-base-url", type: :string, aliases: ["-a"], banner: "http://<base-url>",
|
56
|
+
desc: "If attachment files are reachable via a URL we reference this here"
|
57
|
+
method_option "trac-database-path", type: :string, aliases: ["-d"], banner: "/PATH/TO/EXPORTFILE",
|
58
|
+
desc: "Full path of the Trac sqlite3 database export file"
|
59
|
+
method_option "repo-path", type: :string, aliases: ["-r"], banner: "/GIT/ROOT/DIR",
|
60
|
+
desc: "Full path to the root of the git-repository that is our destination"
|
61
|
+
method_option "home-page-name", type: :string, aliases: ["-h"], default: "WikiStart",
|
62
|
+
desc: "Name of the SVN wiki to map to the home page in Github wiki"
|
63
|
+
method_option "wiki-extensions", type: :array, aliases: ["-e"], default: [".py", "changelog", "expire-ids"],
|
64
|
+
desc: "Array of strings to determinte whether a given path is a file path or a directory in wiki"
|
65
|
+
method_option "source-folders", type: :array, aliases: ["-f"], default: ["personal", "attic", "sprint", "branch/hawk"],
|
66
|
+
desc: "Array of strings to figure out if a path is complete or partial"
|
67
|
+
def migrate_wikis
|
68
|
+
Tractive::Main.new(options).migrate_wikis
|
75
69
|
end
|
76
70
|
|
77
71
|
def self.exit_on_failure?
|
@@ -87,26 +81,6 @@ class TractiveCommand < Thor
|
|
87
81
|
def respond_to_missing?
|
88
82
|
true
|
89
83
|
end
|
90
|
-
|
91
|
-
no_commands do
|
92
|
-
def verify_revmap_generator_options!(options)
|
93
|
-
required_options = {}
|
94
|
-
required_options["--svn-url OR --svn-local-path"] = options["svnurl"] || options["svnlocalpath"]
|
95
|
-
required_options["--git-local-repo-path"] = options["gitlocalrepopath"]
|
96
|
-
required_options["--rev-timestamp-file"] = options["revtimestampfile"]
|
97
|
-
required_options["--revmap-output-file"] = options["revoutputfile"]
|
98
|
-
|
99
|
-
missing_options = {}
|
100
|
-
required_options.each do |key, value|
|
101
|
-
missing_options[key] = value if value.nil? || value.strip.empty?
|
102
|
-
end
|
103
|
-
|
104
|
-
return if missing_options.empty?
|
105
|
-
|
106
|
-
warn("missing revmap generator options (#{missing_options.keys}).\nRun with `--help` or `-h` to see available options")
|
107
|
-
exit 1
|
108
|
-
end
|
109
|
-
end
|
110
84
|
end
|
111
85
|
|
112
86
|
TractiveCommand.start(ARGV)
|
@@ -53,9 +53,10 @@ module Tractive
|
|
53
53
|
$logger.info "Saving attachments of ticket #{attachment.id}... "
|
54
54
|
FileUtils.mkdir_p "#{output_dir}/#{attachment.id}"
|
55
55
|
|
56
|
-
File.
|
57
|
-
|
58
|
-
|
56
|
+
File.binwrite(
|
57
|
+
"#{output_dir}/#{attachment.id}/#{attachment.filename}",
|
58
|
+
URI.open(uri_parser.escape("#{trac_url}/#{attachment.id}/#{attachment.filename}")).read
|
59
|
+
)
|
59
60
|
end
|
60
61
|
end
|
61
62
|
end
|
@@ -6,7 +6,7 @@ module GithubApi
|
|
6
6
|
module Issues
|
7
7
|
def create_issue(repo, params)
|
8
8
|
JSON.parse(
|
9
|
-
|
9
|
+
Http::Client::Request.post(
|
10
10
|
"https://api.github.com/repos/#{repo}/import/issues",
|
11
11
|
params.to_json,
|
12
12
|
{
|
@@ -20,7 +20,7 @@ module GithubApi
|
|
20
20
|
|
21
21
|
def list_issues(repo, params)
|
22
22
|
JSON.parse(
|
23
|
-
|
23
|
+
Http::Client::Request.get(
|
24
24
|
"https://api.github.com/repos/#{repo}/issues",
|
25
25
|
{
|
26
26
|
"Authorization" => "token #{@token}",
|
@@ -33,7 +33,7 @@ module GithubApi
|
|
33
33
|
|
34
34
|
def issue(repo, number)
|
35
35
|
JSON.parse(
|
36
|
-
|
36
|
+
Http::Client::Request.get(
|
37
37
|
"https://api.github.com/repos/#{repo}/issues/#{number}",
|
38
38
|
{ "Authorization" => "token #{@token}" }
|
39
39
|
)
|
@@ -42,7 +42,7 @@ module GithubApi
|
|
42
42
|
|
43
43
|
def issue_import_status(repo, id)
|
44
44
|
JSON.parse(
|
45
|
-
|
45
|
+
Http::Client::Request.get(
|
46
46
|
"https://api.github.com/repos/#{repo}/import/issues/#{id}",
|
47
47
|
{
|
48
48
|
"Authorization" => "token #{@token}",
|
@@ -54,7 +54,7 @@ module GithubApi
|
|
54
54
|
|
55
55
|
def issue_comments(repo, issue_id)
|
56
56
|
JSON.parse(
|
57
|
-
|
57
|
+
Http::Client::Request.get(
|
58
58
|
"https://api.github.com/repos/#{repo}/issues/#{issue_id}/comments",
|
59
59
|
{
|
60
60
|
"Authorization" => "token #{@token}",
|
@@ -66,7 +66,7 @@ module GithubApi
|
|
66
66
|
|
67
67
|
def update_issue_comment(repo, comment_id, comment_body)
|
68
68
|
JSON.parse(
|
69
|
-
|
69
|
+
Http::Client::Request.patch(
|
70
70
|
"https://api.github.com/repos/#{repo}/issues/comments/#{comment_id}",
|
71
71
|
{ body: comment_body }.to_json,
|
72
72
|
{ "Authorization" => "token #{@token}" }
|
@@ -5,7 +5,7 @@ module GithubApi
|
|
5
5
|
module Labels
|
6
6
|
def list_labels(repo, params = {})
|
7
7
|
JSON.parse(
|
8
|
-
|
8
|
+
Http::Client::Request.get(
|
9
9
|
"https://api.github.com/repos/#{repo}/labels",
|
10
10
|
{
|
11
11
|
"Authorization" => "token #{@token}",
|
@@ -18,7 +18,7 @@ module GithubApi
|
|
18
18
|
|
19
19
|
def create_label(repo, params)
|
20
20
|
JSON.parse(
|
21
|
-
|
21
|
+
Http::Client::Request.post(
|
22
22
|
"https://api.github.com/repos/#{repo}/labels",
|
23
23
|
params.to_json,
|
24
24
|
{
|
@@ -6,7 +6,7 @@ module GithubApi
|
|
6
6
|
module Milestones
|
7
7
|
def list_milestones(repo, params)
|
8
8
|
JSON.parse(
|
9
|
-
|
9
|
+
Http::Client::Request.get(
|
10
10
|
"https://api.github.com/repos/#{repo}/milestones?per_page=100",
|
11
11
|
{
|
12
12
|
"Authorization" => "token #{@token}",
|
@@ -19,7 +19,7 @@ module GithubApi
|
|
19
19
|
|
20
20
|
def create_milestone(repo, params)
|
21
21
|
JSON.parse(
|
22
|
-
|
22
|
+
Http::Client::Request.post(
|
23
23
|
"https://api.github.com/repos/#{repo}/milestones",
|
24
24
|
params.to_json,
|
25
25
|
{
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Http
|
4
|
+
module Client
|
5
|
+
class Request
|
6
|
+
def initialize(args)
|
7
|
+
@args = args
|
8
|
+
@max_retries = args[:max_retries] || 3
|
9
|
+
end
|
10
|
+
|
11
|
+
def execute(&block)
|
12
|
+
retries = 0
|
13
|
+
|
14
|
+
begin
|
15
|
+
retries += 1
|
16
|
+
RestClient::Request.execute(@args, &block)
|
17
|
+
rescue RestClient::Forbidden => e
|
18
|
+
retry_after = e.http_headers[:x_ratelimit_reset].to_i - Time.now.to_i
|
19
|
+
raise e if retry_after.negative? || retries > @max_retries
|
20
|
+
|
21
|
+
while retry_after.positive?
|
22
|
+
minutes = retry_after / 60
|
23
|
+
seconds = retry_after % 60
|
24
|
+
|
25
|
+
print "\rRate Limit Exceeded, Will retry in #{minutes} min #{seconds} sec"
|
26
|
+
sleep(1)
|
27
|
+
|
28
|
+
retry_after = e.http_headers[:x_ratelimit_reset].to_i - Time.now.to_i
|
29
|
+
end
|
30
|
+
retry if retries <= @max_retries
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
attr_reader :response
|
35
|
+
|
36
|
+
class << self
|
37
|
+
def get(url, headers = {}, &block)
|
38
|
+
execute(method: :get, url: url, headers: headers, &block)
|
39
|
+
end
|
40
|
+
|
41
|
+
def post(url, payload, headers = {}, &block)
|
42
|
+
execute(method: :post, url: url, payload: payload, headers: headers, &block)
|
43
|
+
end
|
44
|
+
|
45
|
+
def put(url, payload, headers = {}, &block)
|
46
|
+
execute(method: :put, url: url, payload: payload, headers: headers, &block)
|
47
|
+
end
|
48
|
+
|
49
|
+
def patch(url, payload, headers = {}, &block)
|
50
|
+
execute(method: :patch, url: url, payload: payload, headers: headers, &block)
|
51
|
+
end
|
52
|
+
|
53
|
+
def execute(args, &block)
|
54
|
+
new(args).execute(&block)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/tractive/main.rb
CHANGED
@@ -9,7 +9,7 @@ module Tractive
|
|
9
9
|
@cfg = YAML.load_file(@opts[:config])
|
10
10
|
|
11
11
|
Tractive::Utilities.setup_logger(output_stream: @opts[:logfile] || $stderr, verbose: @opts[:verbose])
|
12
|
-
@db = Tractive::Utilities.setup_db!(@cfg["trac"]["database"])
|
12
|
+
@db = Tractive::Utilities.setup_db!(@opts["trac-database-path"] || @cfg["trac"]["database"])
|
13
13
|
rescue Sequel::DatabaseConnectionError, Sequel::AdapterNotFound, URI::InvalidURIError, Sequel::DatabaseError => e
|
14
14
|
$logger.error e.message
|
15
15
|
exit 1
|
@@ -33,6 +33,10 @@ module Tractive
|
|
33
33
|
Migrator::Engine.new(opts: @opts, cfg: @cfg, db: @db).migrate
|
34
34
|
end
|
35
35
|
|
36
|
+
def migrate_wikis
|
37
|
+
Migrator::Wikis::MigrateFromDb.new(opts: @opts, cfg: @cfg).migrate_wikis
|
38
|
+
end
|
39
|
+
|
36
40
|
def info
|
37
41
|
Tractive::Info.new.print
|
38
42
|
end
|