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.
- checksums.yaml +4 -4
- data/bin/gitFlone +2 -1
- data/lib/gitFlone.rb +50 -40
- data/lib/netrc.rb +40 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: daf29f186bd7cdcf54bdd5462e51130fca0db814
|
4
|
+
data.tar.gz: e1d12fcf0522a9e347b1cfb0dc1e5fdf4c74daae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46b39976e6df555908c15c5e3e57d7bd3432c7cd48c422c1cfe65394b6428572ebd89fa85a239d2635adf58dc465fa8f4027add2ffeaa7dcdd5a1f663e4ce831
|
7
|
+
data.tar.gz: 9e69c4eee5e15d2d2a94d1f0148fa142fdd27fe6514383e984620169e502534d0c8e026284da114c42a8cbd14ac64300b308263f43401097221e807e3ec89402
|
data/bin/gitFlone
CHANGED
data/lib/gitFlone.rb
CHANGED
@@ -1,49 +1,59 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require_relative 'netrc'
|
2
|
+
class GitFlone
|
3
|
+
def initialize
|
4
|
+
@netrc = NetRC.new
|
5
|
+
end
|
4
6
|
|
5
|
-
def
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
13
|
-
|
14
|
-
|
15
|
-
shell %Q[git
|
16
|
-
shell %Q[git
|
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
|
23
|
-
|
24
|
-
|
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
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
41
|
-
|
50
|
+
fork(@user,@source,@repoName)
|
51
|
+
clone(@user,@repoName,@branch)
|
42
52
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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.
|
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-
|
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
|