hackpad-migration 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: eb98deb53e9023cf28e9fa815598194d89750dd6
4
- data.tar.gz: 88731023ca6dd3e3735a58c87d8757cad700626a
3
+ metadata.gz: 9d2870b9b566dbef04958ffc5a2bd9d4852f2354
4
+ data.tar.gz: 822a025cc17f26e9ba6f2f68fc442e1573f442b6
5
5
  SHA512:
6
- metadata.gz: 21c3370ca12d23e39907a4da7194a9d44adc4638969dfa2d10362db6769f4daabd30808e746cd8b984c7a8ddf081a653f4dce221c9f389cd448e253a4be43da7
7
- data.tar.gz: 325c58de13b44ec4fad89ca60f99cc53afd898c3d16aa10b7b3e6d2f1ee80612ff8210d715b79f9c648adac33061442e217561492a1c18ee3d010153b80c9afc
6
+ metadata.gz: bc3977bbc0e17b3b4c729162e17557ebac1ec4d58c2342eed19bcf69485fe1fb352ea39da4602a9ac1bffdd5b1d6e4a8a9f13f7aa904c07efb914e818d83c1c2
7
+ data.tar.gz: beb5a7aba13a2ad4b0635617d95ee51d2d5dce625070fd0172e6f79a41de41fee9b6aff6c1b986bcf3189dde6de7574ee12ac443e1bd4ee247ec81b2bfdd14d2
data/README.md CHANGED
@@ -2,15 +2,31 @@
2
2
 
3
3
  A tool for migrate Hackpad from one Hackpad site to other Hackpad site via Hackpad's APIs.
4
4
 
5
+ ## WARNING
6
+
7
+ This tool can't make sure all the data can be migrated perfectly, It just use Hackpad API to do this migration, the data that extract from Hackpad is not the origin data from DB, so some data will be lose, please make sure you understand before you use it.
8
+
9
+ Here is the data that will lose as I know
10
+
11
+ - Pad modified info from users.
12
+ - Checkbox in the pad (fixed by change css name in this migration tool)
13
+ - Header 1 in the pad (fixed by change ellement h2 to hackpad style)
14
+ - All link tag in the pad
15
+ - All comments from users in the pad
16
+
5
17
  ## Installation
6
18
 
7
19
  $ gem install hackpad-migration
8
20
 
9
21
  ## Usage
10
22
 
11
- After installed, Please use command below then follow the note to use it.
23
+ hackpad-migrate migrate
24
+
25
+ Options:
26
+ [--output=OUTPUT] # file path for the result, default is result.json in current path.
27
+
28
+ Do migration with the config in the result, it will create a new config when you execute it at first time.
12
29
 
13
- $ hackpad-migrate
14
30
 
15
31
  The migration can execute multiple times as you want, it will store the result in the disk after the migrateion is done for each pad, So the next time to be executed, this tool will update all the pad from source site.
16
32
 
@@ -33,6 +33,7 @@ module Hackpad
33
33
  def fix_data_missing(body)
34
34
  body.gsub!('class="taskdone"', 'class="listtype-taskdone listindent2 list-taskdone2"')
35
35
  body.gsub!('class="task"', 'class="listtype-task listindent2 list-task2"')
36
+ body.gsub!(/<h2>(.*?)<\/h2>/, '<ul class="listtype-hone listindent1 list-hone1"><li><span>\1</span></li></ul>')
36
37
  end
37
38
  end
38
39
  end
@@ -10,21 +10,35 @@ module Hackpad
10
10
  end
11
11
 
12
12
  def migrate
13
- source.list.each do |source_pid|
13
+ pad_list = source.list
14
+ exit_if_error(pad_list, 'Get error when fetching pad list from source site')
15
+ pad_list.each do |source_pid|
14
16
  body = source.get(source_pid)
15
- # pad {"padId"=>"RAtutOXxMGF1", "globalPadId"=>"2$RAtutOXxMGF1"}
17
+ unless body[/You'll need to turn on JavaScript to use Hackpad in all of its/].nil?
18
+ puts "WARNING: the pad from source #{source_pid} seems not found."
19
+ end
16
20
  target_pid = result.source_and_target_map[source_pid]
17
21
  if target_pid.nil?
18
22
  pad = target.create(body)
23
+ exit_if_error(pad, 'Got error when creating pad for target site')
24
+ # pad {"padId"=>"RAtutOXxMGF1", "globalPadId"=>"2$RAtutOXxMGF1"}
19
25
  result.add_source_and_target(source_pid, pad['padId'])
20
26
  puts "created pad #{pad['padId']} from source pad #{source_pid}"
21
27
  result.write!
22
28
  else
23
29
  puts "Updating pad #{target_pid} from source pad #{source_pid}"
24
30
  pad = target.update(target_pid, body)
31
+ exit_if_error(pad, 'Got error when update pad for target site')
25
32
  end
26
33
  end
27
34
  end
35
+
36
+ def exit_if_error(result, msg)
37
+ if result.is_a?(Hash) && !result['success']
38
+ puts "#{msg}, #{result['error']}"
39
+ exit(1)
40
+ end
41
+ end
28
42
  end
29
43
  end
30
44
  end
@@ -4,14 +4,14 @@ module Hackpad
4
4
  include Thor::Actions
5
5
 
6
6
  default_task :migrate
7
- desc 'migrate', 'start migration with output file'
7
+ desc 'migrate', 'Do migration with the config in the result, it will create a new config when you execute it at first time.'
8
8
  # method_option :source_site, desc: 'The source site for migration', required: true
9
9
  # method_option :source_client_id, desc: 'Hackpad client id for source site', required: true
10
10
  # method_option :source_secret, desc: 'Hackpad secret key for source site', required: true
11
11
  # method_option :target_site, desc: 'The target site for migration', required: true
12
12
  # method_option :target_client_id, desc: 'Hackpad client id for target site', required: true
13
13
  # method_option :target_secret, desc: 'Hackpad secret key for target site', required: true
14
- method_option :output, desc: 'file path for the result'
14
+ method_option :output, desc: 'file path for the result, default is result.json in current path.'
15
15
  def migrate
16
16
  out_file = options['output'].nil? ? 'result.json' : options['output']
17
17
  last_result = Result.new(out_file)
@@ -39,7 +39,11 @@ module Hackpad
39
39
  last_result.user_options['target_secret'] = ask 'Please entry the secret that you want to migrate (example: XsDYswLE1QogALkdFgsfvhRW4YJUvGre): '
40
40
  last_result.write!
41
41
  end
42
- Hackpad::Migration::Migrator.new(last_result).migrate
42
+ begin
43
+ Hackpad::Migration::Migrator.new(last_result).migrate
44
+ rescue Errno::ECONNREFUSED => e
45
+ puts e
46
+ end
43
47
  end
44
48
  end
45
49
  end
@@ -1,5 +1,5 @@
1
1
  module Hackpad
2
2
  module Migration
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hackpad-migration
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doni Leung
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-16 00:00:00.000000000 Z
11
+ date: 2016-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth