learn_duplicate 0.0.12 → 0.0.13

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
  SHA256:
3
- metadata.gz: 956233a1edac2d47b513190d8e4ca6ed1f86af5b52044dfdaa5eee7f949d61ce
4
- data.tar.gz: '0924ace0ecdeb4c3f92bc245dc314f38341e49e06a4b4200288514ec067aab78'
3
+ metadata.gz: e4acf7ecc2189dbae649d6fff2ef038252fd117d1c699cc2990b803b7a27b9ac
4
+ data.tar.gz: b1d1b110111b4dab13e98d9bfb1f61bba0770bbe89bc1d9e0665f85f042638d4
5
5
  SHA512:
6
- metadata.gz: 0fb7c4936ba0f180fb88a987db8f1f08d4c6447cfa0a883fb41be43fb11458f86ab181de720e6b152d740fad072e19178323bf952bf53622f4a0d6cc4304cd38
7
- data.tar.gz: e29277782845f376760c1ab81b7232e1f9bb0d77fe76367f0ca0797d1d43e197fb08cf4de5ce88a9c664999385d670bfa6eb79d6d348d3a5b5b117d61d8795b5
6
+ metadata.gz: 3774b275fa0a9f8bd34b00ce63bd5b77f4f79396a1334496d0087404a557b06f2ccc0246f83ba87475bdae59272cc170730ca2a2bcaafb67538c589e216a3273
7
+ data.tar.gz: 3d6d86ee2c4638fe7f4fbb8f43b752791c02a19e22e9df24817e010f9dce4243b08be912533118c7349eacec150d9f086a73a78ac5022df04172490fc2f3df6b
data/bin/learn_duplicate CHANGED
@@ -1,4 +1,94 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'optparse'
3
4
  require 'learn_duplicate'
4
- LearnDuplicate.new
5
+
6
+ options = {}
7
+ OptionParser.new do |opts|
8
+ opts.banner = <<-EOBANNER
9
+ learn_duplicate (for interactive sssion)
10
+ learn_duplicate --script [opt...optN] <source>
11
+
12
+ INTERACTIVE CONTEXTS
13
+ ====================
14
+
15
+ A tool for cloning repositories. You will want the canonical name of a
16
+ repository e.g.:
17
+
18
+ ruby-enumerables-enumerable-family-tree
19
+
20
+ You will also want to know the clone name e.g
21
+
22
+ snapshot-clone-enumerable-family-tree
23
+
24
+ NON-INTERACTIVE CONTEXTS
25
+ ========================
26
+
27
+ learn_duplicate --script --trimprefix "ruby-enumerables-" --newprefix "snapshot-clone-" <source>
28
+
29
+ DEFINITION OF SOURCE
30
+ ====================
31
+
32
+ <source> can be anything delimited by / that results in a final identifier
33
+ at the end. The `.git` substring, if present at the end, will be removed.
34
+
35
+ As such:
36
+
37
+ https://github.com/learn-co-curriculum/ruby-enumerables-enumerable-family-tree
38
+
39
+ git@github.com:learn-co-curriculum/ruby-enumerables-enumerable-family-tree.git
40
+
41
+ Both use, as a base: ruby-enumerables-enumerable-family-tree
42
+
43
+ Thus the reader can infer what --trimprefix and --newprefix will do.
44
+
45
+ EXAMPLE
46
+ =======
47
+
48
+ learn_duplicate\
49
+ --trimprefix="ruby-enumerables-"\
50
+ --newprefix="uci-mod-2-"\
51
+ https://github.com/learn-co-curriculum/ruby-enumerables-enumerable-family-tree [--dry-run]
52
+
53
+ EOBANNER
54
+
55
+ opts.on("--script", "Run in non-interactive mode") { |v| options[:ni] = true }
56
+ opts.on("-v", "--verbose", "Run in verbose mode"){ |v| options[:verbose] = true }
57
+ opts.on("--trimprefix[=OPTIONAL]", "Prefix to remove from <source>; implies --script") { |t| options[:trimprefix] = t }
58
+ opts.on("--newprefix[=OPTIONAL]", "Prefix to prepent to new destination repo name; implies --script") { |n| options[:newprefix] = n }
59
+ opts.on("--dry-run", "Do not actually make calls, print info out"){ options[:dryrun] = true }
60
+ end.parse!
61
+
62
+ # Prefixes imply non-interactivity
63
+ options[:ni] = !!(options[:trimprefix] || options[:newprefix])
64
+
65
+ REPO_SOURCE = ARGV[0]
66
+ VERBOSE_FLAG = options[:verbose]
67
+
68
+ if options[:ni]
69
+ source_name = REPO_SOURCE.split('/').last.sub(/^(.*).*$/, "\\1")
70
+ if source_name.index(options[:trimprefix]) == 0
71
+ puts "Trim prefix is valid " if VERBOSE_FLAG
72
+ else
73
+ raise ArgumentError, "The --trimprefix is not left-anchored on the <source>"
74
+ end
75
+
76
+ unless (options[:trimprefix] && options[:newprefix])
77
+ raise ArgumentError, "If you have trimprefix you want newprefix as well"
78
+ end
79
+
80
+ trimmed_base = source_name.slice(options[:trimprefix].length...)
81
+ destination = String(options[:newprefix]) + trimmed_base
82
+
83
+ puts "Trimmed base: #{trimmed_base}" if VERBOSE_FLAG
84
+ puts "Destination: #{destination}" if VERBOSE_FLAG
85
+
86
+ LearnDuplicate.new(options.merge({
87
+ source_name: source_name,
88
+ base: trimmed_base.downcase,
89
+ destination: destination.downcase
90
+ }))
91
+ else
92
+ LearnDuplicate.new
93
+ end
94
+
@@ -1,14 +1,48 @@
1
- require 'require_all'
2
1
  require 'faraday'
3
2
  require 'uri'
4
3
  require 'open3'
5
4
 
6
5
  class LearnDuplicate
7
- def initialize()
6
+ GITHUB_ORG = 'https://api.github.com/repos/learn-co-curriculum/'
7
+
8
+ def initialize(opts={})
9
+ # For non-interactive mode
10
+ if opts[:ni]
11
+ validate_repo = ->(url) do
12
+ encoded_url = URI.encode(url).slice(0, url.length)
13
+ check_existing = Faraday.get URI.parse(encoded_url)
14
+ if check_existing.body.include? '"Not Found"'
15
+ raise IOError, "Could not connect to #{url}"
16
+ end
17
+ url
18
+ end
19
+
20
+ @old_repo = validate_repo.call(GITHUB_ORG + opts[:source_name])
21
+
22
+ if opts[:destination].length >= 100
23
+ raise ArgumentError, 'Repository names must be shorter than 100 characters'
24
+ end
25
+
26
+ @repo_name = opts[:destination]
27
+
28
+ if (!opts[:dryrun])
29
+ begin
30
+ create_new_repo
31
+ puts ''
32
+ puts 'To access local folder, change directory into ' + @repo_name + '/'
33
+ puts "Repository available at #{GITHUB_ORG}" + @repo_name
34
+ rescue => e
35
+ STDERR.puts(e.message)
36
+ end
37
+ else
38
+ puts "DRY RUN: Would execute copy of: #{@old_repo} to #{@repo_name}"
39
+ end
40
+
41
+ exit
42
+ end
8
43
 
9
44
  @repo_name = ''
10
45
  @old_repo = ''
11
- @ssh_configured = check_ssh_config
12
46
 
13
47
  puts 'Note: You must have write access to the learn-co-curriculum org on GitHub to use this tool'
14
48
 
@@ -16,7 +50,7 @@ class LearnDuplicate
16
50
  puts 'What is the name of the repository you would like to copy? Paste exactly as is shown in the URL (i.e. advanced-hashes-hashketball)'
17
51
  @old_repo = gets.strip
18
52
 
19
- url = 'https://api.github.com/repos/learn-co-curriculum/' + @old_repo
53
+ url = GITHUB_ORG + @old_repo
20
54
  encoded_url = URI.encode(url).slice(0, url.length)
21
55
  check_existing = Faraday.get URI.parse(encoded_url)
22
56
 
@@ -37,7 +71,7 @@ class LearnDuplicate
37
71
  if @repo_name.length >= 100
38
72
  puts 'Repository names must be shorter than 100 characters'
39
73
  else
40
- url = 'https://api.github.com/repos/learn-co-curriculum/' + @repo_name
74
+ url = GITHUB_ORG + @repo_name
41
75
  encoded_url = URI.encode(url).slice(0, url.length)
42
76
  check_existing = Faraday.get URI.parse(encoded_url)
43
77
 
@@ -46,22 +80,16 @@ class LearnDuplicate
46
80
  break
47
81
  else
48
82
  puts 'A repository with that name already exists or you may have hit a rate limit'
49
- puts 'https://github.com/learn-co-curriculum/' + @repo_name
83
+ puts GITHUB_ORG + @repo_name
50
84
  puts ''
51
85
  end
52
86
  end
53
-
54
-
55
-
56
87
  end
57
88
 
58
-
59
-
60
89
  create_new_repo
61
90
  puts ''
62
91
  puts 'To access local folder, change directory into ' + @repo_name + '/'
63
- puts 'Repository available at https://github.com/learn-co-curriculum/' + @repo_name
64
-
92
+ puts "Repository available at #{GITHUB_ORG}" + @repo_name
65
93
  end
66
94
 
67
95
  private
@@ -105,7 +133,7 @@ class LearnDuplicate
105
133
  end
106
134
 
107
135
  def git_set_remote
108
- remote = @ssh_configured ? "git@github.com:learn-co-curriculum/#{@repo_name}.git" : "https://github.com/learn-co-curriculum/#{@repo_name}"
136
+ remote = check_ssh_config ? "git@github.com:learn-co-curriculum/#{@repo_name}.git" : "https://github.com/learn-co-curriculum/#{@repo_name}"
109
137
  cmd = cd_into_and("git remote set-url origin #{remote}")
110
138
  `#{cmd}`
111
139
  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.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - flatironschool
@@ -90,7 +90,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  requirements: []
93
- rubygems_version: 3.0.3
93
+ rubyforge_project:
94
+ rubygems_version: 2.7.6
94
95
  signing_key:
95
96
  specification_version: 4
96
97
  summary: learn_duplicate is a tool for duplicating learn.co lessons on github