lazy_fork 0.0.1 → 0.0.2

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: 40f12ef820c5cd5d1e7e496765a2aa7312a4d0fd
4
- data.tar.gz: a45d6177b1ce78f6a31037a71e0a8ed7a5496750
3
+ metadata.gz: a286c3b1c88148a44039dc4835764dc93a0abb03
4
+ data.tar.gz: 767054827dcb0d458bdb7ee9f9151397209089eb
5
5
  SHA512:
6
- metadata.gz: 35724883ad89ffd04d6c7a034a7e3f4cd6205ece17ab3dcef37e86ae899f292c5765900978919e6c86e02c62b76aff0b40d091444aa2b5501fc6b92367238a15
7
- data.tar.gz: 20537b72f8aebc6057b9451f35eb58e844b19663d0cfa39a722f97918aaa6be67b136ea768b2d2158cab011e0ddf37e1d01f1a8cec74d9a5fe38a6a46331facf
6
+ metadata.gz: 44c31400dbc4d995a8a46908647dc522ad12c82ca45341e9ec82acc70d98230ec2700d2da0008957f6c5ded8d00d36de6a13aef88837ba359992a73f1c4f90ba
7
+ data.tar.gz: 5b8aeeda9578b061f115a3001e03ae02214c3e6db39402ec1b74672c55681d3550b6c4c4b2e3bf13237142c0296888c128f08abe0e7d1ebf449a75d111bbab1b
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ [![Gem Version](https://badge.fury.io/rb/lazy_fork.svg)](https://badge.fury.io/rb/lazy_fork)
1
2
  # LazyFork - a command line utility for all the lazy forkers out there
2
3
 
3
4
  Who really wants to go through a web interface to fork a repo, just to head back to the command line to clone it?
data/bin/lazy_fork CHANGED
@@ -3,65 +3,9 @@
3
3
  require 'lazy_fork'
4
4
  require 'optparse'
5
5
  require 'octokit'
6
- require 'io/console'
7
- require 'fileutils'
8
-
9
- HOME = File.expand_path("~")
10
-
11
- FileUtils.mkdir_p "#{HOME}/.lazy_forker"
12
-
13
- puts "You lazy forker..."
14
6
 
15
7
  options = {}
16
- OptionParser.new do |opt|
17
- opt.on('--repo user/repo', '-r user/repo', 'GitHub user/repo to be forked & cloned') { |o| options[:repo] = o }
18
- end.parse!
19
-
20
- if options[:repo].nil?
21
- puts "repo must be specified!"
22
- abort
23
- end
24
-
25
- if File.exists?("#{HOME}/.lazy_forker/oauth")
26
- puts "OAuth key found..."
27
- token = File.open("#{HOME}/.lazy_forker/oauth", "r").read
28
- client = Octokit::Client.new access_token: token
29
- else
30
- puts "Basic Authentication"
31
- print "username: "
32
- user = gets.chomp
33
- print "password: "
34
- pass = STDIN.noecho(&:gets).chomp
35
- puts ""
36
- client = Octokit::Client.new \
37
- login: user,
38
- password: pass
39
- puts "Creating OAuth Token..."
40
- token = client.create_authorization(:scopes => ["user","repo"], :note => "Lazy Forker Access Token")
41
- File.open("#{HOME}/.lazy_forker/oauth",'w') do |s|
42
- s.puts token[:token]
43
- end
44
- puts "Token created!"
45
- end
46
-
47
- begin
48
- repo = Octokit::Repository.new(options[:repo])
49
- rescue Octokit::InvalidRepository
50
- puts "Invalid Repository: use owner/name format!"
51
- abort
52
- end
53
-
54
- unless Octokit.repository?(repo)
55
- puts "Repo #{repo.to_s} could not be found."
56
- abort
57
- end
58
-
59
- puts "Repo #{repo.to_s} found."
60
-
61
- fork_repo = client.fork(repo)
62
-
63
- puts "Forked #{repo.to_s} to #{fork_repo[:full_name]}"
64
-
65
- puts "Cloning Fork..."
8
+ op = OptionParser.new
9
+ op.parse!
66
10
 
67
- `git clone #{fork_repo[:html_url]}`
11
+ LazyFork::LazyForker.new(options).be_lazy
@@ -1,3 +1,4 @@
1
1
  module LazyFork
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
+ LAZY_FORK_HOME = File.expand_path("~/.lazy_fork")
3
4
  end
data/lib/lazy_fork.rb CHANGED
@@ -1,9 +1,89 @@
1
1
  require "lazy_fork/version"
2
2
 
3
3
  require "optparse"
4
+ require "io/console"
4
5
 
5
6
  module LazyFork
6
- def lazy_fork
7
+ class LazyForker
8
+ def initialize(options)
9
+ @options = options
10
+ @client = nil
11
+
12
+ # tell the user their being a lazy fork
13
+ puts "You lazy forker... v#{LazyFork::VERSION}"
14
+
15
+ unless Dir.exist? LAZY_FORK_HOME
16
+ puts "Creating #{LAZY_FORK_HOME}..."
17
+ Dir.mkdir LAZY_FORK_HOME
18
+ end
19
+ end
20
+
21
+ def be_lazy
22
+ authenticate_client
23
+ get_repo(ARGV.first)
24
+ fork_repo
25
+ clone_repo
26
+ end
27
+
28
+ private
29
+
30
+ def fork_repo
31
+ puts "Forking..."
32
+ fork_repo = @client.fork(@repo)
33
+ @forked_repo = Octokit::Repository.new(fork_repo[:full_name])
34
+ end
35
+
36
+ def clone_repo
37
+ puts "Cloning fork (#{@forked_repo.to_s})..."
38
+ `git clone #{@forked_repo.url} #{ARGV[1]}`
39
+ end
40
+
41
+ def get_repo(repo)
42
+ begin
43
+ @repo = Octokit::Repository.new(repo)
44
+ rescue Octokit::InvalidRepository
45
+ puts "Invalid Repository: use owner/name format!"
46
+ abort
47
+ end
48
+
49
+ unless @client.repository?(@repo)
50
+ puts "Repo #{@repo.to_s} could not be found."
51
+ abort
52
+ end
53
+ end
54
+
55
+ def authenticate_client
56
+ if File.exists?("#{LAZY_FORK_HOME}/oauth")
57
+ puts "OAuth key found..."
58
+ token = File.open("#{LAZY_FORK_HOME}/oauth", "r").read
59
+ client = Octokit::Client.new(access_token: token)
60
+ else
61
+ puts "Basic Authentication"
62
+ print "username: "
63
+ user = gets.chomp
64
+ print "password: "
65
+ pass = STDIN.noecho(&:gets).chomp
66
+ puts ""
67
+
68
+ begin
69
+ client = Octokit::Client.new(login: user, password: pass)
70
+ rescue Octokit::Unauthorized
71
+ puts "Bad Credentials!"
72
+ abort
73
+ end
74
+
75
+ puts "Creating OAuth Token..."
76
+ token = client.create_authorization(
77
+ scopes: ["user","repo"],
78
+ note: "Lazy Forker Access Token - #{('a'..'z').to_a.shuffle[0,8].join}")
79
+ File.open("#{LAZY_FORK_HOME}/oauth",'w') do |s|
80
+ s.puts token[:token]
81
+ end
82
+
83
+ puts "Token created in #{LAZY_FORK_HOME}/oauth"
84
+ end
85
+
86
+ @client = client
87
+ end
7
88
  end
8
- module_function :lazy_fork
9
89
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazy_fork
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Gregg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-30 00:00:00.000000000 Z
11
+ date: 2017-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler