gitlab_clone 0.10.2 → 0.11.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ada24d4740084e2c900b9390c3ff9b65c99c49cf
4
- data.tar.gz: 5126d67d5c464c1bebe3e515b1d89ad3868f257d
3
+ metadata.gz: b686f239af7b5d292a611131cde594fcf4023847
4
+ data.tar.gz: 69d2bc76b3ce7ff94a8def56b53d56b2ad15c35a
5
5
  SHA512:
6
- metadata.gz: 6eabc4e4728ea79cdd9c414d01f15b64d5d2d5cd61479a5d972a68469b9befb6fe625d388e13c22e6c34c4d327b1aa1ac2ee858f63ce9d3a74f8bb08a36e575d
7
- data.tar.gz: 378936fa856481a5ae14389770f0a2eabb031d833d86dfe8e04c06adcecd3f1a6a7b924e6d31f711f453d48d81ea68fa211813beec00cef286a455b3254803fd
6
+ metadata.gz: 4d63b56b63a9670eb9b8a1bdf284d5cf32bf0bfe2d8b19e0e33a480a0bc98c11e5d4a5e391cbdf25e4ed6a8e463b610c2b4e910469b3e32593e6a73394284b34
7
+ data.tar.gz: de38d3fbb917d5cacddad5a67892c93effeddc4a1e9d8aaa5e0887dc5915fa478f49d3ecf7ec5fb91a958eac3b7ce40d87259b37fd5e22c8d23c0075f3ecd87b
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
- # gitlab_clone
1
+ # gitlab_clone [![Gem Version](https://badge.fury.io/rb/gitlab_clone.png)](http://badge.fury.io/rb/gitlab_clone)
2
2
 
3
3
  ## Description
4
- gitlab_clone allows you to clone repositories from a gitlab servers group using the gitlab api. The itch I was scratching by writing this was that I was writing cookbooks for home and work. I wanted an easier way to download all of my cookbooks so that I could work with all of them at once. Anyone that has worked with chef knows that you can have a lot of repos comporising all of your cookbooks...
4
+ gitlab_clone allows you to clone repositories from a gitlab server's group using the gitlab api.
5
+
6
+ The itch I was scratching by writing this was that I was writing cookbooks for home and work. I wanted an easier way to download all of my cookbooks so that I could work with all of them at once and not have to break my flow by having to download depended cookbooks later. Anyone that has worked with chef knows that you can have a lot of repos comporising all of your cookbooks...
5
7
 
6
8
  ## Features
7
9
  gitlab_clone currently features the following:
@@ -10,13 +12,13 @@ gitlab_clone currently features the following:
10
12
  * Can pick what group you can download all the repos in that group from.
11
13
  * Will do a git pull if an existing repo has been detected.
12
14
  * Support for using either ssh or the web url to download.
13
- * List the repos in a group.
15
+ * List the repos in a group before cloning them.
14
16
 
15
17
  ## Examples
16
18
  ### Get a list of repos in a group named Home:
17
- gitlab_clone -l -g Home
19
+ gitlab-clone -l -g Home
18
20
 
19
- \-------------------------------------------------------------------
21
+ \-------------------------------------------------------------------
20
22
 
21
23
 
22
24
  The following 3 repo(s) were found in the group Home.
@@ -28,14 +30,14 @@ gitlab_clone currently features the following:
28
30
  \-------------------------------------------------------------------
29
31
 
30
32
  ### Clone the repos in the group named Home:
31
- gitlab_clone -w -g Home
33
+ gitlab-clone -w -g Home
32
34
 
33
35
  \-------------------------------------------------------------------
34
36
 
35
37
 
36
38
  ### Starting Web Clone Process Of The Group Home ###
37
39
 
38
- Downloading 3 repo(s) into [HOME_DIR]/projects/Work
40
+ Downloading 3 repo(s) into [HOME_DIR]/projects/Home
39
41
 
40
42
  Repo1 directory exists, doing a git pull instead.
41
43
  Cloning Repo2...
@@ -46,4 +48,5 @@ gitlab_clone currently features the following:
46
48
 
47
49
  ## Installation
48
50
 
49
- gem install gitlab_clone
51
+ gem install gitlab_clone
52
+ Will give you a command named gitlab-clone to use.
data/bin/gitlab-clone CHANGED
@@ -5,30 +5,44 @@ require "json"
5
5
  require "fileutils"
6
6
  require "git"
7
7
  require "jtc"
8
+ require "github"
8
9
  require "version"
9
10
  require "slop"
10
11
  require "httparty"
11
12
 
12
- # Check to see if we have vars set in envs and alert if we don't have them set...
13
13
 
14
+ opts = Slop.parse do
15
+ on :h, :help, 'help'
16
+ on :c, :clone, 'clone'
17
+ on :w, :web, 'web'
18
+ on :l, :list, 'list'
19
+ on :v, :version, 'version'
20
+ on :g, :group=, 'group'
21
+ on :o, :github, 'github'
22
+ end
23
+
24
+ if (opts[:v] && !ENV['gitlab_server'] && !ENV['gitlab_token']) || (opts[:o] && opts[:v] && !ENV['github_token'])
25
+ Jtc.version
26
+ end
14
27
 
28
+ # Check to see if we have vars set in envs and alert if we don't have them set...
15
29
  unless ENV['gitlab_server'] && ENV['gitlab_token']
16
30
  puts "-----------------------------------------------------------\n\n"
17
- puts "You need to set the environment vars first before proceeding"
18
- puts "for gitlab_token and gitlab_server in order to run gitlab-clone.\n\n"
31
+ puts "You need to set the environment vars first before proceeding."
32
+ puts "For gitlab_token and gitlab_server in order to run gitlab-clone.\n\n"
19
33
  puts " example: export gitlab_server=\"http[s]://[server_name]/api/v3\""
20
34
  puts " export gitlab_token=\"secret_token\"\n\n"
21
35
  puts "-----------------------------------------------------------\n"
22
36
  exit
23
37
  end
24
38
 
25
- opts = Slop.parse do
26
- on :h, :help, 'help'
27
- on :c, :clone, 'clone'
28
- on :w, :web, 'web'
29
- on :l, :list, 'list'
30
- on :v, :version, 'version'
31
- on :g, :group=, 'group'
39
+ if opts[:o] && !ENV['github_token']
40
+ puts "-----------------------------------------------------------\n\n"
41
+ puts "You need to set the environment vars first before proceeding"
42
+ puts "For Github support you need to add your Github token.\n\n"
43
+ puts " example: export github_token=\"secret_token\"\n\n"
44
+ puts "-----------------------------------------------------------\n"
45
+ exit
32
46
  end
33
47
 
34
48
  if ARGV[0].nil?
@@ -47,19 +61,29 @@ else
47
61
 
48
62
  if opts[:g]
49
63
  clone_group = opts[:g]
50
- else
64
+ elsif opts[:l] || opts[:o] || opts[:w] || opts[:c]
65
+ puts "No organizational or group name was given using default of \"Cookbooks\"\n\n"
51
66
  clone_group = "Cookbooks"
52
67
  end
53
68
 
54
- if opts[:h]
55
- Jtc.printhelp
56
- elsif opts[:c]
57
- Jtc.clone(0, clone_group)
58
- elsif opts[:w]
59
- Jtc.clone(1, clone_group)
60
- elsif opts[:v]
61
- Jtc.version
62
- elsif opts[:l]
63
- Jtc.list_repos(clone_group)
69
+
70
+ if opts[:o]
71
+ class_to_use = Github
72
+ else
73
+ class_to_use = Jtc
74
+ end
75
+
76
+ if opts[:h]
77
+ Jtc.printhelp
78
+ elsif opts[:c]
79
+ class_to_use.clone(0, clone_group)
80
+ elsif opts[:w]
81
+ class_to_use.clone(1, clone_group)
82
+ elsif opts[:v]
83
+ Jtc.version
84
+ elsif opts[:l]
85
+ class_to_use.list_repos(clone_group)
64
86
  end
65
87
  end
88
+
89
+
data/changelog ADDED
@@ -0,0 +1,6 @@
1
+ v 11.0
2
+ - Added support for github
3
+
4
+ v 10.2
5
+ - Initial release
6
+
data/gitlab_clone.gemspec CHANGED
@@ -5,9 +5,9 @@ require 'version'
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'gitlab_clone'
7
7
  s.version = Version::VERSION
8
- s.date = '2015-01-15'
9
- s.summary = "Pulls down the latest repos from a group in gitlab."
10
- s.description = "Clones All Repos In A Gitlab Group."
8
+ s.date = '2015-01-24'
9
+ s.summary = "Pulls down the latest repos from a group in gitlab or a organization group in Github."
10
+ s.description = "Clones All Repos In A Gitlab Group Or Github Org."
11
11
  s.authors = ["Nestor N. Camacho III"]
12
12
  s.email = 'ncamacho@nnc3.com.to'
13
13
  s.files = `git ls-files`.split($/)
@@ -16,6 +16,6 @@ Gem::Specification.new do |s|
16
16
  s.add_dependency("slop", "~> 3.5.0")
17
17
  s.add_dependency("httparty", "~> 0.13.1")
18
18
  s.homepage =
19
- 'https://bird.nnc3.com/home/clonejtc/wikis/home'
19
+ 'https://github.com/ncamacho/gitlab_clone'
20
20
  s.license = 'MIT'
21
21
  end
data/lib/github.rb ADDED
@@ -0,0 +1,60 @@
1
+ class Github
2
+ TOKEN=ENV['github_token']
3
+ SERVER="https://api.github.com"
4
+ HOME=ENV['HOME']
5
+
6
+
7
+ def self.list_repos(group_name)
8
+ repos_list = get_repos(group_name)
9
+ puts "-------------------------------------------------------------------\n"
10
+ puts "\tThe following #{repos_list.count} repo(s) were found in the Org #{group_name}.\n\n"
11
+ repos_list.each do |get|
12
+ puts "\t\t#{get["name"]}"
13
+ end
14
+ puts "\n-------------------------------------------------------------------"
15
+ end
16
+
17
+
18
+ def self.clone(web, group_name)
19
+ repos_list = get_repos(group_name)
20
+ repos_dir = "#{HOME}/projects/#{group_name}"
21
+
22
+ if File.directory?("#{repos_dir}")
23
+ FileUtils::mkdir_p repos_dir
24
+ end
25
+
26
+ if web == 1
27
+ repo_location = 'clone_url'
28
+ message = "Web"
29
+ else
30
+ repo_location = 'ssh_url'
31
+ message = "Ssh"
32
+ end
33
+ puts "-------------------------------------------------------------------\n"
34
+ puts "\t### Starting #{message} Clone Process Of The Org #{group_name} ###\n\n"
35
+ puts "\tDownloading #{repos_list.count} repo(s) into #{repos_dir}\n\n"
36
+
37
+ repos_list.each do |get|
38
+ repo_name = get["name"]
39
+ repo = get["#{repo_location}"]
40
+ dir = get["name"]
41
+ repo_dir = "#{repos_dir}/#{dir}"
42
+
43
+ if File.directory?("#{repo_dir}")
44
+ puts "\t#{repo_name} directory exists, doing a git pull instead."
45
+ Dir.chdir("#{repo_dir}")
46
+ g = Git.init
47
+ g.pull
48
+ else
49
+ puts "\tCloning #{repo_name}..."
50
+ Git.clone("#{repo}", "#{repo_dir}")
51
+ end
52
+ end
53
+ puts "-------------------------------------------------------------------\n"
54
+ end
55
+
56
+ def self.get_repos(group_name)
57
+ string = HTTParty.get("#{SERVER}/orgs/#{group_name}/repos", :headers => {"Authorization" => "token #{TOKEN}", 'User-Agent' => 'HTTParty'}, :verify => false).to_json
58
+ rep = JSON.parse(string)
59
+ end
60
+ end
data/lib/jtc.rb CHANGED
@@ -13,10 +13,12 @@ class Jtc
13
13
  puts "\t-g, --group: will let you choose which gitlab group to look for repos in"
14
14
  puts "\t-l, --list: will give you a list of repos in git\n\n"
15
15
  puts "\t-w, --web: will clone using web protocol instead of ssh"
16
+ puts "\t-o, --github: will use Github instead of Gitlab for git server."
16
17
 
17
- puts "\t NOTE: You need to set gitlab_server and gitlab_token for this to work."
18
+ puts "\t NOTE: You need to set gitlab_server and gitlab_token or github_token for this to work."
18
19
  puts "\t\texample: export gitlab_server=\"http[s]://[server_name]/api/v3\""
19
20
  puts "\t\t\t export gitlab_token=\"secret_token\""
21
+ puts "\t\t\t export github_token=\"secret_token\""
20
22
  puts "-------------------------------------------------------------------\n\n"
21
23
  end
22
24
 
data/lib/version CHANGED
@@ -1 +1 @@
1
- 0.10.2
1
+ 0.11.0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab_clone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.2
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nestor N. Camacho III
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-15 00:00:00.000000000 Z
11
+ date: 2015-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.13.1
55
- description: Clones All Repos In A Gitlab Group.
55
+ description: Clones All Repos In A Gitlab Group Or Github Org.
56
56
  email: ncamacho@nnc3.com.to
57
57
  executables:
58
58
  - gitlab-clone
@@ -61,11 +61,13 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - README.md
63
63
  - bin/gitlab-clone
64
+ - changelog
64
65
  - gitlab_clone.gemspec
66
+ - lib/github.rb
65
67
  - lib/jtc.rb
66
68
  - lib/version
67
69
  - lib/version.rb
68
- homepage: https://bird.nnc3.com/home/clonejtc/wikis/home
70
+ homepage: https://github.com/ncamacho/gitlab_clone
69
71
  licenses:
70
72
  - MIT
71
73
  metadata: {}
@@ -88,5 +90,6 @@ rubyforge_project:
88
90
  rubygems_version: 2.2.2
89
91
  signing_key:
90
92
  specification_version: 4
91
- summary: Pulls down the latest repos from a group in gitlab.
93
+ summary: Pulls down the latest repos from a group in gitlab or a organization group
94
+ in Github.
92
95
  test_files: []