GitFlone 0.0.4 → 0.1.0

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: daf29f186bd7cdcf54bdd5462e51130fca0db814
4
- data.tar.gz: e1d12fcf0522a9e347b1cfb0dc1e5fdf4c74daae
3
+ metadata.gz: 94a41f10129d7e8adcc0db4f579a0f6e3099d6de
4
+ data.tar.gz: fc48de712e8e6fff38492cb399e6b8e11dbd0aff
5
5
  SHA512:
6
- metadata.gz: 46b39976e6df555908c15c5e3e57d7bd3432c7cd48c422c1cfe65394b6428572ebd89fa85a239d2635adf58dc465fa8f4027add2ffeaa7dcdd5a1f663e4ce831
7
- data.tar.gz: 9e69c4eee5e15d2d2a94d1f0148fa142fdd27fe6514383e984620169e502534d0c8e026284da114c42a8cbd14ac64300b308263f43401097221e807e3ec89402
6
+ metadata.gz: 872675c055e2e0481d69850df2d47567cc9747c6daec14d571d9523a26810850c32dd69394083922f55111632c32aa3a24a1bbe11d9cdd832b756cecaaa320f9
7
+ data.tar.gz: d8eaa5099b7b3f7f18de4d67aa410a42cb4d0a3bf0bb8fd626a7e81c62a4935379465ce27793ab52b0c22224111efa9260035bf15a77482a108724c1ce06e306
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
- require 'gitFlone'
3
- require 'netrc'
2
+ require_relative '../config/environment'
3
+ GitFlone.new.run
@@ -0,0 +1,2 @@
1
+ require_relative '../lib/gitFlone'
2
+ require_relative '../lib/netrc'
@@ -1,20 +1,21 @@
1
1
  require_relative 'netrc'
2
+
2
3
  class GitFlone
3
4
  def initialize
4
5
  @netrc = NetRC.new
5
6
  end
6
7
 
7
- def fork(user, source,repoName)
8
+ def fork(source,repoName)
8
9
  if @netrc.has_token?
9
10
  shell %Q[curl -H 'Authorization: token #{@netrc.token}' https://api.github.com/repos/#{source}/#{repoName}/forks -d '{}']
10
11
  else
11
- shell %Q[curl -u '#{user}' https://api.github.com/repos/#{source}/#{repoName}/forks -d '{}']
12
+ shell %Q[curl -u '#{@netrc.user}' https://api.github.com/repos/#{source}/#{repoName}/forks -d '{}']
12
13
  end
13
14
  sleep(1) #ensure fork is there
14
15
  end
15
16
 
16
- def clone (user,repoName, branch="Feature")
17
- shell %Q[git clone git@github.com:#{user}/#{repoName}.git]
17
+ def clone (repoName, branch="Feature")
18
+ shell %Q[git clone git@github.com:#{@netrc.user}/#{repoName}.git]
18
19
  Dir.chdir("#{repoName}")
19
20
  shell %Q[git checkout -b #{branch}]
20
21
  shell %Q[git push origin #{branch}]
@@ -27,11 +28,11 @@ class GitFlone
27
28
  shell %Q[git commit -am "Initial #{@branch} commit"]
28
29
  shell %Q[git push origin #{@branch}]
29
30
  end
30
- shell %Q[open https://github.com/#{@user}/#{@repoName}/compare/#{@branch}?expand=1]
31
+ shell %Q[open https://github.com/#{@netrc.user}/#{@repoName}/compare/#{@branch}?expand=1]
31
32
  end
32
33
 
33
34
  def shell (command)
34
- puts `#{command}`
35
+ `#{command}`
35
36
  end
36
37
 
37
38
  def checkArg (pattern, string)
@@ -41,14 +42,12 @@ class GitFlone
41
42
  end
42
43
 
43
44
  def run
44
- @user = ARGV[0]
45
- @gitdirectory = ARGV[1].split(":").last
46
- @branch = ARGV[2].nil? ? "Feature" : ARGV[2]
47
- @source = checkArg(%r[(?<=:)(\S+)(?=\/)], ARGV[1])
48
- @repoName = checkArg(%r[(?<=\/)(\S+)(?=\.)],ARGV[1])
49
-
50
- fork(@user,@source,@repoName)
51
- clone(@user,@repoName,@branch)
45
+ @gitdirectory = ARGV[0].split(":").last
46
+ @branch = ARGV[1].nil? ? "Feature" : ARGV[1]
47
+ @source = checkArg(%r[(?<=:)(\S+)(?=\/)], ARGV[0])
48
+ @repoName = checkArg(%r[(?<=\/)(\S+)(?=\.)],ARGV[0])
49
+ fork(@source,@repoName)
50
+ clone(@repoName,@branch)
52
51
 
53
52
  puts "Create an initial commit for pull request?"
54
53
  puts "If so, provide a value for dummy pull request or leave blank to skip:"
@@ -56,4 +55,4 @@ class GitFlone
56
55
  pull(dummy)
57
56
  end
58
57
  end
59
- GitFlone.new.run
58
+
@@ -1,16 +1,17 @@
1
1
  class NetRC
2
2
 
3
- attr_accessor :token
3
+ attr_accessor :token, :user, :path
4
4
  def initialize
5
+ @path = "#{ENV['HOME']}/.netrc"
5
6
  #Check if there is a .netrc file to read from
6
- if File.exists?("#{ENV['HOME']}/.netrc")
7
+ if File.exists?(path)
7
8
  puts "Success? #{parseToken("#{ENV['HOME']}/.netrc")}"
8
- puts @token
9
9
  else
10
10
  #create the .netrc file in home directory
11
- # new_file = File.new("#{ENV['HOME']}/.netrc", "w")
12
- # generateToken(new_file)
13
- # new_file.close
11
+ puts "Creating a .netrc file for you in #{ENV['HOME']}"
12
+ new_file = File.new("#{ENV['HOME']}/.netrc", "a")
13
+ generateToken(new_file)
14
+ new_file.close
14
15
  end
15
16
 
16
17
  end
@@ -18,10 +19,12 @@ class NetRC
18
19
  def parseToken (path)
19
20
  begin
20
21
  f = File.open("#{path}", "r")
21
- netRCPattern = %r[(machine github.com login).+]
22
- tokenPattern = %r[(?<=login ).{40}]
22
+ netRCPattern = %r[(machine github.com) (\S+) (\S+)]
23
+ tokenPattern = %r[.{40}]
23
24
  githubLine = f.each_line.select{|line|line.match(netRCPattern)}
24
- @token = githubLine.first.scan(tokenPattern).first
25
+ values = githubLine.first.split(" ")
26
+ @user = values[2]
27
+ @token = values[3] if (values[3].index(tokenPattern))
25
28
  f.close
26
29
  true
27
30
  rescue
@@ -29,9 +32,26 @@ class NetRC
29
32
  end
30
33
  end
31
34
 
35
+ #need to prompt for user
32
36
  def generateToken (file)
37
+ puts "Generating token..."
38
+ puts "Please provide username:"
39
+ @user = STDIN.gets.chomp
33
40
 
34
- file.puts("machine github.com login ")
41
+ puts "Need to generate token automatically"
42
+ response = shell %Q[curl -i -u #{@user} -d '{"scopes": ["repo"],"note": "gitFlone"}' https://api.github.com/authorizations]
43
+ @token = checkArg(%r[(?<="token": ")(.{40})(?=")],response)
44
+ file.puts("machine github.com #{@user} #{@token}")
45
+ end
46
+
47
+ def shell (command)
48
+ `#{command}`
49
+ end
50
+
51
+ def checkArg (pattern, string)
52
+ values = string.scan(pattern).flatten.uniq
53
+ raise ArgumentError, "Argument is invalid: #{string}" unless values.length==1
54
+ return values.first
35
55
  end
36
56
 
37
57
  def has_token?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: GitFlone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Chang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-17 00:00:00.000000000 Z
11
+ date: 2014-02-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Fork a github repository, the clone it locally with a new branch
14
14
  email: kevin.w.chang@gmail.com
@@ -18,6 +18,7 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - bin/gitFlone
21
+ - config/environment.rb
21
22
  - lib/gitFlone.rb
22
23
  - lib/netrc.rb
23
24
  homepage: http://rubygems.org/gems/GitFlone