github_cloner 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,6 +20,8 @@ Common options:
20
20
 
21
21
  $ github_cloner --username nashby --method http --path ~/Desktop/github_projects
22
22
 
23
+ If you will not provide the username, `github_cloner` take it from `git config --global --get github.user`
24
+
23
25
  == Contributing to github_cloner
24
26
 
25
27
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
data/Rakefile CHANGED
@@ -26,6 +26,7 @@ Jeweler::Tasks.new do |gem|
26
26
  gem.email = "younash@gmail.com"
27
27
  gem.authors = ["Vasiliy Ermolovich"]
28
28
  gem.files.include Dir.glob('lib/**/*.rb')
29
+ gem.files.exclude 'pkg'
29
30
  end
30
31
  Jeweler::RubygemsDotOrgTasks.new
31
32
 
@@ -6,13 +6,13 @@ require 'ostruct'
6
6
  require 'github_cloner'
7
7
 
8
8
  class OptionParser
9
- def self.parse(args)
10
- options = OpenStruct.new
11
- options.username = nil
12
- options.git_method = 'http'
13
- options.path = "."
14
- options.timeout = ""
15
- options.repos = []
9
+ def self.parse(args)
10
+ options = OpenStruct.new
11
+ options.username = nil
12
+ options.git_method = 'http'
13
+ options.path = "."
14
+ options.timeout = ""
15
+ options.repos = []
16
16
 
17
17
  opts = OptionParser.new do |opts|
18
18
  opts.banner = "Usage: github_cloner [options]"
@@ -20,20 +20,18 @@ class OptionParser
20
20
  opts.separator ""
21
21
  opts.separator "Specific options:"
22
22
 
23
- # Mandatory argument.
24
23
  opts.on("-u", "--username GITHUB_USERNAME",
25
- "Require the GITHUB_USERNAME before executing your script") do |username|
24
+ "Require the GITHUB_USERNAME before executing your script(default: username from git config --global --get github.user)") do |username|
26
25
  options.username = username
27
26
  end
28
27
 
29
- # Optional argument
30
28
  opts.on("-p", "--path [PATH]",
31
29
  "PATH to the new repos collection (default: current directory)") do |path|
32
30
  options.path = path
33
31
  end
34
32
 
35
33
  opts.on("-t", "--timeout [TIMEOUT]",
36
- "Number of days from the last push befor repos will be placed in the inactive folder (default: disabled)") do |timeout|
34
+ "Number of days from the last push before repos will be placed in the inactive folder (default: disabled)") do |timeout|
37
35
  options.timeout = timeout
38
36
  end
39
37
 
@@ -42,7 +40,6 @@ class OptionParser
42
40
  options.git_method = git_method
43
41
  end
44
42
 
45
- # List of the repos.
46
43
  opts.on("-r", "--repos x,y,z", Array, "List of needed repos (default: all)") do |repos|
47
44
  options.repos = repos
48
45
  end
@@ -57,19 +54,23 @@ class OptionParser
57
54
  end
58
55
  opts.parse!(args)
59
56
  options
60
- end
57
+ end
61
58
  end
62
59
 
63
60
  options = OptionParser.parse(ARGV)
64
61
 
62
+ if options.username.nil?
63
+ options.username = Github::git_config_name
64
+ end
65
+
65
66
  unless options.username.nil?
66
- opts = {:username => options.username.to_s,
67
- :method => options.git_method.to_s,
68
- :path => options.path.to_s,
69
- :timeout => options.timeout.to_s,
70
- :repos => options.repos}
71
- cloner = Cloner.new opts
72
- cloner.clone
67
+ opts = {:username => options.username.to_s.chomp,
68
+ :method => options.git_method.to_s,
69
+ :path => options.path.to_s,
70
+ :timeout => options.timeout.to_s,
71
+ :repos => options.repos}
72
+ cloner = Cloner.new opts
73
+ cloner.clone
73
74
  else
74
- puts 'Sorry, bro. I need to know your github name'
75
+ puts 'Sorry, bro. I need to know your github name'
75
76
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{github_cloner}
8
- s.version = "0.3.2"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Vasiliy Ermolovich"]
12
- s.date = %q{2011-03-09}
12
+ s.date = %q{2011-03-10}
13
13
  s.default_executable = %q{github_cloner}
14
14
  s.description = %q{an easy way to clone all your projects from github}
15
15
  s.email = %q{younash@gmail.com}
@@ -29,10 +29,6 @@ Gem::Specification.new do |s|
29
29
  "lib/github_cloner.rb",
30
30
  "lib/github_cloner/github_helper.rb",
31
31
  "lib/github_cloner/version.rb",
32
- "pkg/github_cloner-0.1.gem",
33
- "pkg/github_cloner-0.2.gem",
34
- "pkg/github_cloner-0.3.0.gem",
35
- "pkg/github_cloner-0.3.1.gem",
36
32
  "test/helper.rb",
37
33
  "test/test_github_cloner.rb"
38
34
  ]
@@ -1,18 +1,20 @@
1
1
  require 'github_cloner/github_helper'
2
2
 
3
3
  class Cloner
4
- include Github
4
+
5
+ include Github
5
6
 
6
- def initialize(options)
7
- @github_uname = options[:username]
8
- @mode = options[:method]
9
- @path = options[:path]
10
- @timeout = options[:timeout]
11
- @repos = options[:repos]
12
- end
7
+ def initialize(options)
8
+ @github_uname = options[:username]
9
+ @mode = options[:method]
10
+ @path = options[:path]
11
+ @timeout = options[:timeout]
12
+ @repos = options[:repos]
13
+ end
13
14
 
14
- def clone
15
- Github::get_repos(@github_uname, @mode, @timeout).each {|repo| system("git clone #{repo[:link]} #{@path}#{repo[:inactive]}/#{repo[:name]}") if @repos.include? repo[:name] or @repos.empty? }
16
- end
15
+ def clone
16
+ Github::get_repos(@github_uname, @mode, @timeout).each {|repo| system("git clone #{repo[:link]} #{@path}/#{repo[:inactive]}/#{repo[:name]}") if @repos.include? repo[:name] or @repos.empty? }
17
+ end
18
+
17
19
  end
18
20
 
@@ -4,42 +4,42 @@ require 'time'
4
4
 
5
5
  module Github
6
6
 
7
- GITHUB_URL_API = 'http://github.com/api/v2/json/repos/show/'
7
+ GITHUB_URL_API = 'http://github.com/api/v2/json/repos/show/'
8
8
 
9
- class << self
9
+ class << self
10
10
 
11
- def get_repos(username, mode, timeout)
12
- repos_json = JSON.parse(open(GITHUB_URL_API+username).read)
13
- repos = []
14
- repos_json['repositories'].each do |repo|
15
- if timeout != "" && inactive?(repo, timeout)
16
- repos << make_git_url(repo['name'], mode, username, "_inactive")
17
- else
18
- repos << make_git_url(repo['name'], mode, username, "")
19
- end
20
- end
21
- repos
22
- end
11
+ def get_repos(username, mode, timeout)
12
+ repos_json = JSON.parse(open(GITHUB_URL_API+username).read)
13
+ repos = []
14
+ repos_json['repositories'].each do |repo|
15
+ if timeout != "" && inactive?(repo, timeout)
16
+ repos << make_git_url(repo['name'], mode, username, "_inactive")
17
+ else
18
+ repos << make_git_url(repo['name'], mode, username, "")
19
+ end
20
+ end
21
+ repos
22
+ end
23
+
24
+ def make_git_url(repo_name, mode, username, inactive)
25
+ case mode
26
+ when 'ssh'
27
+ {:link => "git@github.com:#{username}/#{repo_name}.git", :name => repo_name, :inactive => inactive}
28
+ when 'http'
29
+ {:link => "https://#{username}@github.com/#{username}/#{repo_name}.git", :name => repo_name, :inactive => inactive}
30
+ when 'git'
31
+ {:link => "git://github.com/#{username}/#{repo_name}.git", :name => repo_name, :inactive => inactive}
32
+ end
33
+ end
23
34
 
24
- def make_git_url(repo_name, mode, username, inactive)
25
- case mode
26
- when 'ssh'
27
- {:link => "git@github.com:#{username}/#{repo_name}.git", :name => repo_name, :inactive => inactive}
28
- when 'http'
29
- {:link => "https://#{username}@github.com/#{username}/#{repo_name}.git", :name => repo_name, :inactive => inactive}
30
- when 'git'
31
- {:link => "git://github.com/#{username}/#{repo_name}.git", :name => repo_name, :inactive => inactive}
32
- end
33
- end
35
+ def inactive?(repo, timeout)
36
+ ((Time.now - Time.parse(repo["pushed_at"])).to_i / 86400) > timeout.to_i
37
+ end
34
38
 
35
- def inactive?(repo, timeout)
36
- if ((Time.now - Time.parse(repo["pushed_at"])).to_i / 86400) > timeout.to_i
37
- true
38
- else
39
- false
40
- end
39
+ def git_config_name
40
+ `git config --global --get github.user`
41
41
  end
42
42
 
43
- end
43
+ end
44
44
 
45
45
  end
@@ -1,10 +1,12 @@
1
1
  class Cloner
2
- module Version
3
- MAJOR = 0
4
- MINOR = 3
5
- PATCH = 2
6
- BUILD = nil
2
+
3
+ module Version
4
+ MAJOR = 0
5
+ MINOR = 4
6
+ PATCH = 0
7
+ BUILD = nil
7
8
 
8
- STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
9
- end
9
+ STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
10
+ end
11
+
10
12
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: github_cloner
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.2
5
+ version: 0.4.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Vasiliy Ermolovich
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-09 00:00:00 +02:00
13
+ date: 2011-03-10 00:00:00 +02:00
14
14
  default_executable: github_cloner
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -77,10 +77,6 @@ files:
77
77
  - lib/github_cloner.rb
78
78
  - lib/github_cloner/github_helper.rb
79
79
  - lib/github_cloner/version.rb
80
- - pkg/github_cloner-0.1.gem
81
- - pkg/github_cloner-0.2.gem
82
- - pkg/github_cloner-0.3.0.gem
83
- - pkg/github_cloner-0.3.1.gem
84
80
  - test/helper.rb
85
81
  - test/test_github_cloner.rb
86
82
  has_rdoc: true
@@ -97,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
93
  requirements:
98
94
  - - ">="
99
95
  - !ruby/object:Gem::Version
100
- hash: 941243155
96
+ hash: -881534509
101
97
  segments:
102
98
  - 0
103
99
  version: "0"
Binary file
Binary file
Binary file
Binary file