learn_duplicate 0.0.14 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/learn_duplicate.rb +24 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cfdd59991a706b75c64d8de8e3cee1fc0e1ad16ee5dfb979fd5cb3da6464dd5
|
4
|
+
data.tar.gz: 146a1bb4d4dff291886cb16d95c2766a3ed3dafe38a111ee2a0bbbc003561b17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5d4fc1256d1807abb555ecf4e7bb0aeb2f4c88d9448131bec80bf7f41ad06eded366dc94d2380dc5f5d0324557445a0b55aafc7bc4a7255c8877f78df4ca90c
|
7
|
+
data.tar.gz: 29f2ed91e97f14997d816322a96a81b657117ecd23aa6cb79890bfa893b49fe31d1de1aa9c8bb7867a2d1f6e7b3bc8178ea40043424b03408057fc37d83392ad
|
data/lib/learn_duplicate.rb
CHANGED
@@ -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 = ->(
|
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
|
-
|
18
|
+
repo_name
|
18
19
|
end
|
19
20
|
|
20
|
-
|
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
|
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
|
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
|
-
|
143
|
-
|
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
|
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
|
-
|
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
|