pr_migrator 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/pr_migrator.rb +21 -0
- data/lib/pr_migrator/configuration.rb +16 -0
- data/lib/pr_migrator/create.rb +89 -0
- data/lib/pr_migrator/export.rb +40 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9536fd6ca517fb83f6eca295351614df33304dec
|
4
|
+
data.tar.gz: 93c66a592e071378e6429cb2cab989ad142f7fa3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6d95ee84cd377e734f57107ad59d9b7dbb1c9e9900ffe105e2dfab1e91ca96358a5d27fde0bc484ca5e55b148a3c3b47728caff0bb677eb22dcd2e54a47f13f3
|
7
|
+
data.tar.gz: 4c1ba74683d81ce2055004d10a73a471c70931ae95a032c440d6f5348b3dc3432e6566dd2aa3dcf68f568864f990c54bb5efe1c5d5ca18806bd350c5703cf8d2
|
data/lib/pr_migrator.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'octokit'
|
2
|
+
require 'json'
|
3
|
+
require 'parallel'
|
4
|
+
require 'securerandom'
|
5
|
+
require 'pr_migrator/configuration'
|
6
|
+
require 'pr_migrator/export'
|
7
|
+
require 'pr_migrator/create'
|
8
|
+
|
9
|
+
module PrMigrator
|
10
|
+
class << self
|
11
|
+
attr_writer :configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configuration
|
15
|
+
@configuration ||= Configuration.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.configure
|
19
|
+
yield(configuration)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module PrMigrator
|
2
|
+
|
3
|
+
class Configuration
|
4
|
+
|
5
|
+
attr_accessor :source_access_token
|
6
|
+
attr_accessor :destination_access_token
|
7
|
+
attr_accessor :github_enterprise_endpoint
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@source_access_token = 12345
|
11
|
+
@destination_access_token = 56789
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module PrMigrator
|
2
|
+
class Create
|
3
|
+
|
4
|
+
attr_accessor :client
|
5
|
+
attr_accessor :repo_name
|
6
|
+
attr_accessor :exported_pr_dir
|
7
|
+
attr_accessor :migration_branch
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
initialize_api_endpoint
|
11
|
+
@client = Octokit::Client.new(access_token: PrMigrator.configuration.destination_access_token)
|
12
|
+
@repo_name = options[:repo_name]
|
13
|
+
@exported_pr_dir = options[:exported_pr_dir]
|
14
|
+
@migration_branch = options[:migration_branch]
|
15
|
+
end
|
16
|
+
|
17
|
+
# Start the process of exporting
|
18
|
+
# The exported files will be json files
|
19
|
+
def start
|
20
|
+
#Parallel.each_with_index(files.take(3), in_processes: 10) do |file_name, index|
|
21
|
+
files.each_with_index do |file_name, index|
|
22
|
+
begin
|
23
|
+
content = JSON.parse(File.read(file_name), symbolize_names: true)
|
24
|
+
pr_number_to_be_migrated = content[:number]
|
25
|
+
response_temp_file_creation = create_temp_file(file_name, pr_number_to_be_migrated)
|
26
|
+
create_ref_to_temp_file(pr_number_to_be_migrated, response_temp_file_creation[:commit][:sha])
|
27
|
+
response_pull_request_creation = create_pull_request(pr_number_to_be_migrated)
|
28
|
+
update_pull_request(response_pull_request_creation[:number], content)
|
29
|
+
delete_ref_to_temp_file(pr_number_to_be_migrated)
|
30
|
+
puts '*'
|
31
|
+
rescue Exception => e
|
32
|
+
puts "Error: #{e.message}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Files generated from migration
|
38
|
+
def files
|
39
|
+
@exported_pr_dir ? Dir.glob(@exported_pr_dir) : []
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_temp_file(file_name, pr_number)
|
43
|
+
@client.create_contents(@repo_name,
|
44
|
+
"pull_request_#{Time.now.to_i}_#{SecureRandom.hex}.md",
|
45
|
+
"Migrating pull request #{pr_number}",
|
46
|
+
"This Includes a temporary content for the PR migration of #{file_name} #{Time.now.to_i}_#{SecureRandom.hex}" ,
|
47
|
+
branch: @migration_branch)
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_pull_request(pr_number)
|
51
|
+
@client.create_pull_request(@repo_name,
|
52
|
+
'master',
|
53
|
+
"pr_#{pr_number}",
|
54
|
+
"Title",
|
55
|
+
"Body")
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_ref_to_temp_file(pr_number, sha)
|
59
|
+
@client.create_ref(@repo_name, "heads/pr_#{pr_number}", sha)
|
60
|
+
end
|
61
|
+
|
62
|
+
def update_pull_request(new_pr_number, content)
|
63
|
+
str = content.to_s
|
64
|
+
@client.update_pull_request(@repo_name,
|
65
|
+
new_pr_number,
|
66
|
+
{ title: content[:title],
|
67
|
+
body: "#{content[:body]}\r\n\n <h5>The JSON format of the PR can be copied from below</h5> \r\n ```ruby\r\n#{str}\r\n```",
|
68
|
+
state: 'closed' }
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
def delete_ref_to_temp_file(pr_number)
|
73
|
+
@client.delete_ref(@repo_name, "heads/pr_#{pr_number}")
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
# Initialize the Github Endpoint if Set
|
81
|
+
def initialize_api_endpoint
|
82
|
+
if PrMigrator.configuration.github_enterprise_endpoint
|
83
|
+
Octokit.configure do |c|
|
84
|
+
c.api_endpoint = PrMigrator.configuration.github_enterprise_endpoint
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module PrMigrator
|
2
|
+
class Export
|
3
|
+
|
4
|
+
attr_accessor :client
|
5
|
+
attr_accessor :repo_name
|
6
|
+
attr_accessor :pr_numbers
|
7
|
+
attr_accessor :folder_name_for_exported_files
|
8
|
+
attr_accessor :exported_prs
|
9
|
+
attr_accessor :failed_prs
|
10
|
+
|
11
|
+
def initialize(options = {})
|
12
|
+
@client = Octokit::Client.new(access_token: PrMigrator.configuration.source_access_token)
|
13
|
+
@repo_name = options[:repo_name]
|
14
|
+
@pr_numbers = options[:pr_numbers]
|
15
|
+
@folder_name_for_exported_files = "export_#{SecureRandom.urlsafe_base64(5)}"
|
16
|
+
@failed_prs = []
|
17
|
+
@exported_prs = []
|
18
|
+
end
|
19
|
+
|
20
|
+
# Start the process of exporting
|
21
|
+
# The exported files will be json files
|
22
|
+
def start
|
23
|
+
Dir.mkdir(File.join(Dir.getwd, @folder_name_for_exported_files))
|
24
|
+
Parallel.map(@pr_numbers, in_processes: 10 ) do |pr_number|
|
25
|
+
begin
|
26
|
+
response = @client.pull_request(@repo_name, pr_number)
|
27
|
+
File.open("#{@folder_name_for_exported_files}/pr-#{pr_number}.json","w") do |f|
|
28
|
+
f.write(JSON.pretty_generate(response.to_attrs))
|
29
|
+
end
|
30
|
+
@exported_prs << pr_number
|
31
|
+
rescue
|
32
|
+
@failed_prs << pr_number
|
33
|
+
end
|
34
|
+
sleep 2
|
35
|
+
end
|
36
|
+
puts "PR's exported were: #{@exported_prs}"
|
37
|
+
puts "PR's Not exported were :#{@failed_prs}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pr_migrator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ankit Gupta
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: octokit
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: parallel
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.4'
|
55
|
+
description: Migrate Pull requests from one repo to other
|
56
|
+
email: ankit.gupta8898@gmail.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- lib/pr_migrator.rb
|
62
|
+
- lib/pr_migrator/configuration.rb
|
63
|
+
- lib/pr_migrator/create.rb
|
64
|
+
- lib/pr_migrator/export.rb
|
65
|
+
homepage: https://github.com/ankit8898/pr_migrator
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.4.7
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Github Pull request migrator
|
89
|
+
test_files: []
|