gitlab_clone 0.10.2
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 +7 -0
- data/README.md +49 -0
- data/bin/gitlab-clone +65 -0
- data/gitlab_clone.gemspec +21 -0
- data/lib/jtc.rb +93 -0
- data/lib/version +1 -0
- data/lib/version.rb +3 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ada24d4740084e2c900b9390c3ff9b65c99c49cf
|
4
|
+
data.tar.gz: 5126d67d5c464c1bebe3e515b1d89ad3868f257d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6eabc4e4728ea79cdd9c414d01f15b64d5d2d5cd61479a5d972a68469b9befb6fe625d388e13c22e6c34c4d327b1aa1ac2ee858f63ce9d3a74f8bb08a36e575d
|
7
|
+
data.tar.gz: 378936fa856481a5ae14389770f0a2eabb031d833d86dfe8e04c06adcecd3f1a6a7b924e6d31f711f453d48d81ea68fa211813beec00cef286a455b3254803fd
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# gitlab_clone
|
2
|
+
|
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...
|
5
|
+
|
6
|
+
## Features
|
7
|
+
gitlab_clone currently features the following:
|
8
|
+
|
9
|
+
* Default cloning of all repos that are in a group called Cookbooks.
|
10
|
+
* Can pick what group you can download all the repos in that group from.
|
11
|
+
* Will do a git pull if an existing repo has been detected.
|
12
|
+
* Support for using either ssh or the web url to download.
|
13
|
+
* List the repos in a group.
|
14
|
+
|
15
|
+
## Examples
|
16
|
+
### Get a list of repos in a group named Home:
|
17
|
+
gitlab_clone -l -g Home
|
18
|
+
|
19
|
+
\-------------------------------------------------------------------
|
20
|
+
|
21
|
+
|
22
|
+
The following 3 repo(s) were found in the group Home.
|
23
|
+
|
24
|
+
Repo1
|
25
|
+
Repo2
|
26
|
+
Repo3
|
27
|
+
|
28
|
+
\-------------------------------------------------------------------
|
29
|
+
|
30
|
+
### Clone the repos in the group named Home:
|
31
|
+
gitlab_clone -w -g Home
|
32
|
+
|
33
|
+
\-------------------------------------------------------------------
|
34
|
+
|
35
|
+
|
36
|
+
### Starting Web Clone Process Of The Group Home ###
|
37
|
+
|
38
|
+
Downloading 3 repo(s) into [HOME_DIR]/projects/Work
|
39
|
+
|
40
|
+
Repo1 directory exists, doing a git pull instead.
|
41
|
+
Cloning Repo2...
|
42
|
+
Cloning Repo3...
|
43
|
+
|
44
|
+
\-------------------------------------------------------------------
|
45
|
+
|
46
|
+
|
47
|
+
## Installation
|
48
|
+
|
49
|
+
gem install gitlab_clone
|
data/bin/gitlab-clone
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Lets require our gems and start this
|
4
|
+
require "json"
|
5
|
+
require "fileutils"
|
6
|
+
require "git"
|
7
|
+
require "jtc"
|
8
|
+
require "version"
|
9
|
+
require "slop"
|
10
|
+
require "httparty"
|
11
|
+
|
12
|
+
# Check to see if we have vars set in envs and alert if we don't have them set...
|
13
|
+
|
14
|
+
|
15
|
+
unless ENV['gitlab_server'] && ENV['gitlab_token']
|
16
|
+
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"
|
19
|
+
puts " example: export gitlab_server=\"http[s]://[server_name]/api/v3\""
|
20
|
+
puts " export gitlab_token=\"secret_token\"\n\n"
|
21
|
+
puts "-----------------------------------------------------------\n"
|
22
|
+
exit
|
23
|
+
end
|
24
|
+
|
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'
|
32
|
+
end
|
33
|
+
|
34
|
+
if ARGV[0].nil?
|
35
|
+
Jtc.printhelp
|
36
|
+
end
|
37
|
+
|
38
|
+
opts.to_hash
|
39
|
+
|
40
|
+
if opts[:c] && opts[:w]
|
41
|
+
puts "\n\t############################################\n"
|
42
|
+
puts "\t You can't web clone and ssh clone"
|
43
|
+
puts "\t Look at help below for valid options"
|
44
|
+
puts "\t############################################\n\n"
|
45
|
+
Jtc.printhelp
|
46
|
+
else
|
47
|
+
|
48
|
+
if opts[:g]
|
49
|
+
clone_group = opts[:g]
|
50
|
+
else
|
51
|
+
clone_group = "Cookbooks"
|
52
|
+
end
|
53
|
+
|
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)
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'gitlab_clone'
|
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."
|
11
|
+
s.authors = ["Nestor N. Camacho III"]
|
12
|
+
s.email = 'ncamacho@nnc3.com.to'
|
13
|
+
s.files = `git ls-files`.split($/)
|
14
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
|
+
s.add_dependency("git", "~> 1.2.6")
|
16
|
+
s.add_dependency("slop", "~> 3.5.0")
|
17
|
+
s.add_dependency("httparty", "~> 0.13.1")
|
18
|
+
s.homepage =
|
19
|
+
'https://bird.nnc3.com/home/clonejtc/wikis/home'
|
20
|
+
s.license = 'MIT'
|
21
|
+
end
|
data/lib/jtc.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
class Jtc
|
2
|
+
TOKEN=ENV['gitlab_token']
|
3
|
+
SERVER=ENV['gitlab_server']
|
4
|
+
HOME=ENV['HOME']
|
5
|
+
|
6
|
+
|
7
|
+
def self.printhelp
|
8
|
+
puts "-------------------------------------------------------------------\n\n"
|
9
|
+
puts "\t\t#### Options for gitlab-clone ####\n\n"
|
10
|
+
puts "\t-h, --help: shows this help message"
|
11
|
+
puts "\t-c, --clone: clones all repos from http[s]://[server_name]/groups/Cookbooks
|
12
|
+
into a ~/projects/Cookbooks directory by default"
|
13
|
+
puts "\t-g, --group: will let you choose which gitlab group to look for repos in"
|
14
|
+
puts "\t-l, --list: will give you a list of repos in git\n\n"
|
15
|
+
puts "\t-w, --web: will clone using web protocol instead of ssh"
|
16
|
+
|
17
|
+
puts "\t NOTE: You need to set gitlab_server and gitlab_token for this to work."
|
18
|
+
puts "\t\texample: export gitlab_server=\"http[s]://[server_name]/api/v3\""
|
19
|
+
puts "\t\t\t export gitlab_token=\"secret_token\""
|
20
|
+
puts "-------------------------------------------------------------------\n\n"
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.list_repos(group_name)
|
24
|
+
repos_list = get_repos(group_name)
|
25
|
+
puts "-------------------------------------------------------------------\n"
|
26
|
+
puts "\tThe following #{repos_list["projects"].length} repo(s) were found in the group #{group_name}.\n\n"
|
27
|
+
repos_list["projects"].length.times do |get|
|
28
|
+
puts "\t\t#{repos_list["projects"][get]["name"]}"
|
29
|
+
end
|
30
|
+
puts "\n-------------------------------------------------------------------"
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.clone(web, group_name)
|
34
|
+
repos_list = get_repos(group_name)
|
35
|
+
repos_dir = "#{HOME}/projects/#{group_name}"
|
36
|
+
|
37
|
+
if File.directory?("#{repos_dir}")
|
38
|
+
FileUtils::mkdir_p repos_dir
|
39
|
+
end
|
40
|
+
|
41
|
+
if web == 1
|
42
|
+
repo_location = 'http_url_to_repo'
|
43
|
+
message = "Web"
|
44
|
+
else
|
45
|
+
repo_location = 'ssh_url_to_repo'
|
46
|
+
message = "Ssh"
|
47
|
+
end
|
48
|
+
puts "-------------------------------------------------------------------\n"
|
49
|
+
puts "\t### Starting #{message} Clone Process Of The Group #{group_name} ###\n\n"
|
50
|
+
puts "\tDownloading #{repos_list["projects"].length} repo(s) into #{repos_dir}\n\n"
|
51
|
+
|
52
|
+
repos_list["projects"].length.times do |get|
|
53
|
+
repo_name = repos_list["projects"][get]["name"]
|
54
|
+
repo = repos_list["projects"][get]["#{repo_location}"]
|
55
|
+
dir = repos_list["projects"][get]["name"]
|
56
|
+
repo_dir = "#{repos_dir}/#{dir}"
|
57
|
+
|
58
|
+
if File.directory?("#{repo_dir}")
|
59
|
+
puts "\t#{repo_name} directory exists, doing a git pull instead."
|
60
|
+
Dir.chdir("#{repo_dir}")
|
61
|
+
g = Git.init
|
62
|
+
g.pull
|
63
|
+
else
|
64
|
+
puts "\tCloning #{repo_name}..."
|
65
|
+
Git.clone("#{repo}", "#{repo_dir}")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
puts "-------------------------------------------------------------------\n"
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.get_repos(group_name)
|
72
|
+
group_id = get_groups[group_name]
|
73
|
+
string = HTTParty.get("#{SERVER}/groups/#{group_id}", :headers => {"PRIVATE-TOKEN" => "#{TOKEN}" }, :verify => false).to_json
|
74
|
+
rep = JSON.parse(string)
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.get_groups
|
78
|
+
string = HTTParty.get("#{SERVER}/groups", :headers => {"PRIVATE-TOKEN" => "#{TOKEN}" }, :verify => false).to_json
|
79
|
+
api_ids = JSON.parse(string)
|
80
|
+
group_ids = {}
|
81
|
+
api_ids.each do |id|
|
82
|
+
group_ids["#{id["name"]}"] = id["id"]
|
83
|
+
end
|
84
|
+
return group_ids
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.version
|
88
|
+
puts "----------------------------------------------------------------\n\n"
|
89
|
+
puts "\t\tCurrent gitlab-clone verison is #{Version::VERSION}\n"
|
90
|
+
puts "----------------------------------------------------------------\n\n"
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
data/lib/version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.10.2
|
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gitlab_clone
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.10.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nestor N. Camacho III
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: git
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.2.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.2.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: slop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.5.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.5.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: httparty
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.13.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.13.1
|
55
|
+
description: Clones All Repos In A Gitlab Group.
|
56
|
+
email: ncamacho@nnc3.com.to
|
57
|
+
executables:
|
58
|
+
- gitlab-clone
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- README.md
|
63
|
+
- bin/gitlab-clone
|
64
|
+
- gitlab_clone.gemspec
|
65
|
+
- lib/jtc.rb
|
66
|
+
- lib/version
|
67
|
+
- lib/version.rb
|
68
|
+
homepage: https://bird.nnc3.com/home/clonejtc/wikis/home
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 2.2.2
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Pulls down the latest repos from a group in gitlab.
|
92
|
+
test_files: []
|