GitFlone 0.0.2 → 0.0.4

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/gitFlone +2 -1
  3. data/lib/gitFlone.rb +50 -40
  4. data/lib/netrc.rb +40 -0
  5. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa82c1cba7ab4d31a6226af89b167365f387d195
4
- data.tar.gz: 1c19b6ad04d384413177df0b1db4fd99838aef8c
3
+ metadata.gz: daf29f186bd7cdcf54bdd5462e51130fca0db814
4
+ data.tar.gz: e1d12fcf0522a9e347b1cfb0dc1e5fdf4c74daae
5
5
  SHA512:
6
- metadata.gz: d863493660fcb0e689cb472e0cdfdf99fd779a7b9e6254e2cfd6d2bb72f56c29595f58965241ab25ef953ff5338cd559013c059ae58b6949151591648f99b54a
7
- data.tar.gz: 1641145da8c6c635d3d2215a0d1e610312829aef79dc954a9d4368b4360058d8fa96441b2fd8f2b133a4411eca118ad706a75a7e5a0f7e0316fda89266f1c51a
6
+ metadata.gz: 46b39976e6df555908c15c5e3e57d7bd3432c7cd48c422c1cfe65394b6428572ebd89fa85a239d2635adf58dc465fa8f4027add2ffeaa7dcdd5a1f663e4ce831
7
+ data.tar.gz: 9e69c4eee5e15d2d2a94d1f0148fa142fdd27fe6514383e984620169e502534d0c8e026284da114c42a8cbd14ac64300b308263f43401097221e807e3ec89402
data/bin/gitFlone CHANGED
@@ -1,2 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
- require 'gitFlone'
2
+ require 'gitFlone'
3
+ require 'netrc'
data/lib/gitFlone.rb CHANGED
@@ -1,49 +1,59 @@
1
- def fork(user, source,repoName)
2
- shell %Q[curl -u '#{user}' https://api.github.com/repos/#{source}/#{repoName}/forks -d '{}']
3
- end
1
+ require_relative 'netrc'
2
+ class GitFlone
3
+ def initialize
4
+ @netrc = NetRC.new
5
+ end
4
6
 
5
- def clone (user,repoName, branch="Feature")
6
- shell"git clone git@github.com:#{user}/#{repoName}.git"
7
- Dir.chdir("#{repoName}")
8
- shell %Q[git checkout -b #{branch}]
9
- shell %Q[git push origin #{branch}]
10
- end
7
+ def fork(user, source,repoName)
8
+ if @netrc.has_token?
9
+ shell %Q[curl -H 'Authorization: token #{@netrc.token}' https://api.github.com/repos/#{source}/#{repoName}/forks -d '{}']
10
+ else
11
+ shell %Q[curl -u '#{user}' https://api.github.com/repos/#{source}/#{repoName}/forks -d '{}']
12
+ end
13
+ sleep(1) #ensure fork is there
14
+ end
11
15
 
12
- def pull (dummycommit="")
13
- if dummycommit.length > 0
14
- shell %Q[touch #{dummycommit}]
15
- shell %Q[git add #{dummycommit}]
16
- shell %Q[git commit -am "Initial #{@branch} commit"]
17
- shell %Q[git push origin #{@branch}]
16
+ def clone (user,repoName, branch="Feature")
17
+ shell %Q[git clone git@github.com:#{user}/#{repoName}.git]
18
+ Dir.chdir("#{repoName}")
19
+ shell %Q[git checkout -b #{branch}]
20
+ shell %Q[git push origin #{branch}]
18
21
  end
19
- shell %Q[open https://github.com/#{@user}/#{@repoName}/compare/#{@branch}?expand=1]
20
- end
21
22
 
22
- def shell (command)
23
- puts `#{command}`
24
- end
23
+ def pull (dummycommit="")
24
+ if dummycommit.length > 0
25
+ shell %Q[touch #{dummycommit}]
26
+ shell %Q[git add #{dummycommit}]
27
+ shell %Q[git commit -am "Initial #{@branch} commit"]
28
+ shell %Q[git push origin #{@branch}]
29
+ end
30
+ shell %Q[open https://github.com/#{@user}/#{@repoName}/compare/#{@branch}?expand=1]
31
+ end
25
32
 
26
- def checkArg (pattern, string)
27
- values = string.scan(pattern).flatten.uniq
28
- raise ArgumentError, "Argument is invalid: #{string}" unless values.length==1
29
- #puts "Found #{values.first}"
30
- return values.first
31
- end
33
+ def shell (command)
34
+ puts `#{command}`
35
+ end
36
+
37
+ def checkArg (pattern, string)
38
+ values = string.scan(pattern).flatten.uniq
39
+ raise ArgumentError, "Argument is invalid: #{string}" unless values.length==1
40
+ return values.first
41
+ end
32
42
 
33
- def run
34
- @user = ARGV[0]
35
- @gitdirectory = ARGV[1].split(":").last
36
- @branch = ARGV[2].nil? ? "Feature" : ARGV[2]
37
- @source = checkArg(%r[(?<=:)(\S+)(?=\/)], ARGV[1])
38
- @repoName = checkArg(%r[(?<=\/)(\S+)(?=\.)],ARGV[1])
43
+ 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])
39
49
 
40
- fork(@user,@source,@repoName)
41
- clone(@user,@repoName,@branch)
50
+ fork(@user,@source,@repoName)
51
+ clone(@user,@repoName,@branch)
42
52
 
43
- puts "Create an initial commit for pull request?"
44
- puts "If so, provide a value for dummy pull request or leave blank to skip:"
45
- dummy = STDIN.gets.chomp
46
- pull(dummy)
53
+ puts "Create an initial commit for pull request?"
54
+ puts "If so, provide a value for dummy pull request or leave blank to skip:"
55
+ dummy = STDIN.gets.chomp
56
+ pull(dummy)
57
+ end
47
58
  end
48
-
49
- run
59
+ GitFlone.new.run
data/lib/netrc.rb ADDED
@@ -0,0 +1,40 @@
1
+ class NetRC
2
+
3
+ attr_accessor :token
4
+ def initialize
5
+ #Check if there is a .netrc file to read from
6
+ if File.exists?("#{ENV['HOME']}/.netrc")
7
+ puts "Success? #{parseToken("#{ENV['HOME']}/.netrc")}"
8
+ puts @token
9
+ else
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
14
+ end
15
+
16
+ end
17
+
18
+ def parseToken (path)
19
+ begin
20
+ f = File.open("#{path}", "r")
21
+ netRCPattern = %r[(machine github.com login).+]
22
+ tokenPattern = %r[(?<=login ).{40}]
23
+ githubLine = f.each_line.select{|line|line.match(netRCPattern)}
24
+ @token = githubLine.first.scan(tokenPattern).first
25
+ f.close
26
+ true
27
+ rescue
28
+ false
29
+ end
30
+ end
31
+
32
+ def generateToken (file)
33
+
34
+ file.puts("machine github.com login ")
35
+ end
36
+
37
+ def has_token?
38
+ return !@token.nil? && @token.length==40
39
+ end
40
+ end
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.2
4
+ version: 0.0.4
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-14 00:00:00.000000000 Z
11
+ date: 2014-02-17 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
@@ -19,6 +19,7 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - bin/gitFlone
21
21
  - lib/gitFlone.rb
22
+ - lib/netrc.rb
22
23
  homepage: http://rubygems.org/gems/GitFlone
23
24
  licenses:
24
25
  - MIT