Permalink
Browse files

Regenerate gemspec for version 0.4.0

  • Loading branch information...
1 parent 0fd1ae1 commit fbf53b579be0d1fd1d62bf3746293c976fcea4fa @nashby committed Mar 10, 2011
Showing with 78 additions and 71 deletions.
  1. +2 −0 README.rdoc
  2. +22 −21 bin/github_cloner
  3. +1 −1 github_cloner.gemspec
  4. +13 −11 lib/github_cloner.rb
  5. +31 −31 lib/github_cloner/github_helper.rb
  6. +9 −7 lib/github_cloner/version.rb
View
@@ -20,6 +20,8 @@ Common options:
$ github_cloner --username nashby --method http --path ~/Desktop/github_projects
+If you will not provide the username, `github_cloner` take it from `git config --global --get github.user`
+
== Contributing to github_cloner
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
View
@@ -6,34 +6,32 @@ require 'ostruct'
require 'github_cloner'
class OptionParser
- def self.parse(args)
- options = OpenStruct.new
- options.username = nil
- options.git_method = 'http'
- options.path = "."
- options.timeout = ""
- options.repos = []
+ def self.parse(args)
+ options = OpenStruct.new
+ options.username = nil
+ options.git_method = 'http'
+ options.path = "."
+ options.timeout = ""
+ options.repos = []
opts = OptionParser.new do |opts|
opts.banner = "Usage: github_cloner [options]"
opts.separator ""
opts.separator "Specific options:"
- # Mandatory argument.
opts.on("-u", "--username GITHUB_USERNAME",
- "Require the GITHUB_USERNAME before executing your script") do |username|
+ "Require the GITHUB_USERNAME before executing your script(default: username from git config --global --get github.user)") do |username|
options.username = username
end
- # Optional argument
opts.on("-p", "--path [PATH]",
"PATH to the new repos collection (default: current directory)") do |path|
options.path = path
end
opts.on("-t", "--timeout [TIMEOUT]",
- "Number of days from the last push befor repos will be placed in the inactive folder (default: disabled)") do |timeout|
+ "Number of days from the last push before repos will be placed in the inactive folder (default: disabled)") do |timeout|
options.timeout = timeout
end
@@ -42,7 +40,6 @@ class OptionParser
options.git_method = git_method
end
- # List of the repos.
opts.on("-r", "--repos x,y,z", Array, "List of needed repos (default: all)") do |repos|
options.repos = repos
end
@@ -57,19 +54,23 @@ class OptionParser
end
opts.parse!(args)
options
- end
+ end
end
options = OptionParser.parse(ARGV)
+if options.username.nil?
+ options.username = Github::git_config_name
+end
+
unless options.username.nil?
- opts = {:username => options.username.to_s,
- :method => options.git_method.to_s,
- :path => options.path.to_s,
- :timeout => options.timeout.to_s,
- :repos => options.repos}
- cloner = Cloner.new opts
- cloner.clone
+ opts = {:username => options.username.to_s.chomp,
+ :method => options.git_method.to_s,
+ :path => options.path.to_s,
+ :timeout => options.timeout.to_s,
+ :repos => options.repos}
+ cloner = Cloner.new opts
+ cloner.clone
else
- puts 'Sorry, bro. I need to know your github name'
+ puts 'Sorry, bro. I need to know your github name'
end
View
@@ -5,7 +5,7 @@
Gem::Specification.new do |s|
s.name = %q{github_cloner}
- s.version = "0.3.2"
+ s.version = "0.4.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Vasiliy Ermolovich"]
View
@@ -1,18 +1,20 @@
require 'github_cloner/github_helper'
class Cloner
- include Github
+
+ include Github
- def initialize(options)
- @github_uname = options[:username]
- @mode = options[:method]
- @path = options[:path]
- @timeout = options[:timeout]
- @repos = options[:repos]
- end
+ def initialize(options)
+ @github_uname = options[:username]
+ @mode = options[:method]
+ @path = options[:path]
+ @timeout = options[:timeout]
+ @repos = options[:repos]
+ end
- def clone
- 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? }
- end
+ def clone
+ 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? }
+ end
+
end
@@ -4,42 +4,42 @@
module Github
- GITHUB_URL_API = 'http://github.com/api/v2/json/repos/show/'
+ GITHUB_URL_API = 'http://github.com/api/v2/json/repos/show/'
- class << self
+ class << self
- def get_repos(username, mode, timeout)
- repos_json = JSON.parse(open(GITHUB_URL_API+username).read)
- repos = []
- repos_json['repositories'].each do |repo|
- if timeout != "" && inactive?(repo, timeout)
- repos << make_git_url(repo['name'], mode, username, "_inactive")
- else
- repos << make_git_url(repo['name'], mode, username, "")
- end
- end
- repos
- end
+ def get_repos(username, mode, timeout)
+ repos_json = JSON.parse(open(GITHUB_URL_API+username).read)
+ repos = []
+ repos_json['repositories'].each do |repo|
+ if timeout != "" && inactive?(repo, timeout)
+ repos << make_git_url(repo['name'], mode, username, "_inactive")
+ else
+ repos << make_git_url(repo['name'], mode, username, "")
+ end
+ end
+ repos
+ end
+
+ def make_git_url(repo_name, mode, username, inactive)
+ case mode
+ when 'ssh'
+ {:link => "git@github.com:#{username}/#{repo_name}.git", :name => repo_name, :inactive => inactive}
+ when 'http'
+ {:link => "https://#{username}@github.com/#{username}/#{repo_name}.git", :name => repo_name, :inactive => inactive}
+ when 'git'
+ {:link => "git://github.com/#{username}/#{repo_name}.git", :name => repo_name, :inactive => inactive}
+ end
+ end
- def make_git_url(repo_name, mode, username, inactive)
- case mode
- when 'ssh'
- {:link => "git@github.com:#{username}/#{repo_name}.git", :name => repo_name, :inactive => inactive}
- when 'http'
- {:link => "https://#{username}@github.com/#{username}/#{repo_name}.git", :name => repo_name, :inactive => inactive}
- when 'git'
- {:link => "git://github.com/#{username}/#{repo_name}.git", :name => repo_name, :inactive => inactive}
- end
- end
+ def inactive?(repo, timeout)
+ ((Time.now - Time.parse(repo["pushed_at"])).to_i / 86400) > timeout.to_i
+ end
- def inactive?(repo, timeout)
- if ((Time.now - Time.parse(repo["pushed_at"])).to_i / 86400) > timeout.to_i
- true
- else
- false
- end
+ def git_config_name
+ `git config --global --get github.user`
end
- end
+ end
end
@@ -1,10 +1,12 @@
class Cloner
- module Version
- MAJOR = 0
- MINOR = 3
- PATCH = 2
- BUILD = nil
+
+ module Version
+ MAJOR = 0
+ MINOR = 4
+ PATCH = 0
+ BUILD = nil
- STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
- end
+ STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
+ end
+
end

0 comments on commit fbf53b5

Please sign in to comment.