learn_duplicate 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/learn_duplicate.rb +24 -12
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 266556086de7e42a49f18dfbc79d114dc8eebd13c654ce8c47b98bf3c3ad3114
4
- data.tar.gz: 0501e81825b21b26081cf4a0832105709aef7fd9792ee980b3ee42b3cf6a06e4
3
+ metadata.gz: 3cfdd59991a706b75c64d8de8e3cee1fc0e1ad16ee5dfb979fd5cb3da6464dd5
4
+ data.tar.gz: 146a1bb4d4dff291886cb16d95c2766a3ed3dafe38a111ee2a0bbbc003561b17
5
5
  SHA512:
6
- metadata.gz: c73c0a5fda1bd889cb80bc7d5c3bfbfd1a2eb0791e1f3e7cd7039b41b0339cfd6c2cd3715ede1f81fcbf3d3671eef1afdc42e94c0963f3554c437e7b356fd352
7
- data.tar.gz: fa202db6205cc4e5c52d1183baca77ae7a46e05f12722c8fb39552355566d8173d8edc3250cd37ee04aa56d4ca3ded59c02076af8470f002d122a950b588465a
6
+ metadata.gz: e5d4fc1256d1807abb555ecf4e7bb0aeb2f4c88d9448131bec80bf7f41ad06eded366dc94d2380dc5f5d0324557445a0b55aafc7bc4a7255c8877f78df4ca90c
7
+ data.tar.gz: 29f2ed91e97f14997d816322a96a81b657117ecd23aa6cb79890bfa893b49fe31d1de1aa9c8bb7867a2d1f6e7b3bc8178ea40043424b03408057fc37d83392ad
@@ -8,16 +8,21 @@ class LearnDuplicate
8
8
  def initialize(opts={})
9
9
  # For non-interactive mode
10
10
  if opts[:ni]
11
- validate_repo = ->(url) do
11
+ validate_repo = ->(repo_name) do
12
+ url = GITHUB_ORG + repo_name
12
13
  encoded_url = URI.encode(url).slice(0, url.length)
13
14
  check_existing = Faraday.get URI.parse(encoded_url)
14
15
  if check_existing.body.include? '"Not Found"'
15
16
  raise IOError, "Could not connect to #{url}"
16
17
  end
17
- url
18
+ repo_name
18
19
  end
19
20
 
20
- @old_repo = validate_repo.call(GITHUB_ORG + opts[:source_name])
21
+ de_apiify_url = ->(api_url) do
22
+ api_url.gsub(/(api\.|repos\/)/, '')
23
+ end
24
+
25
+ @old_repo = validate_repo.call(opts[:source_name])
21
26
 
22
27
  if opts[:destination].length >= 100
23
28
  raise ArgumentError, 'Repository names must be shorter than 100 characters'
@@ -30,12 +35,12 @@ class LearnDuplicate
30
35
  create_new_repo
31
36
  puts ''
32
37
  puts 'To access local folder, change directory into ' + @repo_name + '/'
33
- puts "Repository available at #{GITHUB_ORG}" + @repo_name
38
+ puts "Repository available at #{de_apiify_url.call(GITHUB_ORG + @repo_name)}"
34
39
  rescue => e
35
40
  STDERR.puts(e.message)
36
41
  end
37
42
  else
38
- puts "DRY RUN: Would execute copy of: #{@old_repo} to #{@repo_name}"
43
+ puts "DRY RUN: Would execute copy of: #{de_apiify_url.call(@old_repo)} to #{@repo_name}"
39
44
  end
40
45
 
41
46
  exit
@@ -124,10 +129,12 @@ class LearnDuplicate
124
129
 
125
130
  def rename_repo
126
131
  cmd = "mv -f #{@old_repo} #{@repo_name}"
132
+ cd_into_and("git remote rename origin origin-old")
127
133
  `#{cmd}`
128
134
  end
129
135
 
130
- def git_create
136
+ def git_create_and_set_new_origin
137
+ # Creates repo **and** assigns new remote to 'origin' shortname
131
138
  cmd = cd_into_and("hub create learn-co-curriculum/#{@repo_name}")
132
139
  `#{cmd}`
133
140
  end
@@ -139,8 +146,13 @@ class LearnDuplicate
139
146
  end
140
147
 
141
148
  def git_push
142
- cmd = cd_into_and('git push -u origin master')
143
- `#{cmd}`
149
+ # Copy `master`, attempt to copy `solution`, but if it's not there, no
150
+ # complaints
151
+ cmds = [
152
+ %q|git push origin 'refs/remotes/origin/master:refs/heads/master' > /dev/null 2>&1|,
153
+ %q|git push origin 'refs/remotes/origin/solution:refs/heads/solution' > /dev/null 2>&1|
154
+ ]
155
+ cmds.each { |cmd| `#{cd_into_and(cmd)}` }
144
156
  end
145
157
 
146
158
  def check_ssh_config
@@ -152,16 +164,16 @@ class LearnDuplicate
152
164
  # 'cd' doesn't work the way it would in the shell, must be used before every command
153
165
  puts 'Cloning old repository'
154
166
  git_clone
155
- puts 'Renaming old repository with new name'
167
+ puts "Renaming old directory with new name: #{@repo_name}"
156
168
  rename_repo
157
169
  puts ''
158
170
  puts 'Creating new remote learn-co-curriculum repository'
159
- git_create
171
+ git_create_and_set_new_origin
160
172
  puts ''
161
- puts 'Setting new git remote'
173
+ puts 'Setting new git remote based on SSH settings'
162
174
  git_set_remote
163
175
  puts ''
164
- puts 'Pushing to new remote'
176
+ puts 'Pushing all old-remote branches to new remote'
165
177
  git_push
166
178
  end
167
179
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: learn_duplicate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - flatironschool