gitlab_clone 0.11.0 → 0.12.1
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/README.md +31 -1
- data/bin/gitlab-clone +32 -38
- data/gitlab_clone.gemspec +6 -6
- data/lib/github.rb +4 -4
- data/lib/gitlab.rb +102 -0
- data/lib/setup.rb +169 -0
- data/lib/version +1 -1
- data/lib/version.rb +10 -1
- metadata +6 -5
- data/lib/jtc.rb +0 -95
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1592b0779099389ef722fc3c7fb8ce3252718892
|
4
|
+
data.tar.gz: 5aeaa3bf8bf122d09e4fcc13c18e2087be43a48c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d962571766641130e6c9366c61ec50d941367a055eaa9e662bd0366618b81f91a437ec74353e10e91d64901de5f32ee8953bec4815855b3b67df5233a33530d
|
7
|
+
data.tar.gz: fc23dddbcd28fae94ac492999c4b705a578ea6beab35b1160bde3fa7d66f4d9dbaac2462dacd8b4a749eae3c892ab78269d27832becff97267c9ee9ab4ab25e7
|
data/README.md
CHANGED
@@ -5,9 +5,22 @@ gitlab_clone allows you to clone repositories from a gitlab server's group using
|
|
5
5
|
|
6
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...
|
7
7
|
|
8
|
+
|
9
|
+
Your tokens for either Gitlab or Gitgub are stored in the settings of your user profile.
|
10
|
+
|
11
|
+
|
12
|
+
For gitlab it will be:
|
13
|
+
|
14
|
+
http://gitlab_server/profile/account
|
15
|
+
|
16
|
+
|
17
|
+
For github it will be:
|
18
|
+
|
19
|
+
https://github.com/settings/applications
|
20
|
+
|
8
21
|
## Features
|
9
22
|
gitlab_clone currently features the following:
|
10
|
-
|
23
|
+
* Github organization supprt. You can bring down all the repos in an organization that you have access to.
|
11
24
|
* Default cloning of all repos that are in a group called Cookbooks.
|
12
25
|
* Can pick what group you can download all the repos in that group from.
|
13
26
|
* Will do a git pull if an existing repo has been detected.
|
@@ -45,6 +58,23 @@ gitlab_clone currently features the following:
|
|
45
58
|
|
46
59
|
\-------------------------------------------------------------------
|
47
60
|
|
61
|
+
### Clone the repos in the group named Home from Github:
|
62
|
+
gitlab-clone -w -g Home -o
|
63
|
+
|
64
|
+
\-------------------------------------------------------------------
|
65
|
+
|
66
|
+
|
67
|
+
### Starting Web Clone Process Of The Group Home ###
|
68
|
+
|
69
|
+
Downloading 3 repo(s) into [HOME_DIR]/projects/Home
|
70
|
+
|
71
|
+
Repo1 directory exists, doing a git pull instead.
|
72
|
+
Cloning Repo2...
|
73
|
+
Cloning Repo3...
|
74
|
+
|
75
|
+
\-------------------------------------------------------------------
|
76
|
+
|
77
|
+
|
48
78
|
|
49
79
|
## Installation
|
50
80
|
|
data/bin/gitlab-clone
CHANGED
@@ -4,12 +4,13 @@
|
|
4
4
|
require "json"
|
5
5
|
require "fileutils"
|
6
6
|
require "git"
|
7
|
-
require "
|
7
|
+
require "gitlab"
|
8
|
+
require "setup"
|
8
9
|
require "github"
|
9
10
|
require "version"
|
10
11
|
require "slop"
|
11
12
|
require "httparty"
|
12
|
-
|
13
|
+
require "rainbow"
|
13
14
|
|
14
15
|
opts = Slop.parse do
|
15
16
|
on :h, :help, 'help'
|
@@ -19,71 +20,64 @@ opts = Slop.parse do
|
|
19
20
|
on :v, :version, 'version'
|
20
21
|
on :g, :group=, 'group'
|
21
22
|
on :o, :github, 'github'
|
23
|
+
on :n, :config, 'print config'
|
24
|
+
on :r, :reconfigure, 'reconfigure gitlab server and token settings'
|
22
25
|
end
|
23
26
|
|
24
|
-
|
25
|
-
|
27
|
+
# If no arugments are passed, give help information
|
28
|
+
if ARGV[0].nil?
|
29
|
+
Gitlab.printhelp
|
26
30
|
end
|
27
31
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
puts " export gitlab_token=\"secret_token\"\n\n"
|
35
|
-
puts "-----------------------------------------------------------\n"
|
32
|
+
if opts[:o] && !Setup.github_precheck
|
33
|
+
puts Rainbow("Whoops looks like you have not set your Github token yet. Would you like to do so now?").yellow
|
34
|
+
answer = STDIN.gets.chomp.downcase
|
35
|
+
if answer == "y" or answer == "yes"
|
36
|
+
Setup.github_configure
|
37
|
+
end
|
36
38
|
exit
|
37
39
|
end
|
38
40
|
|
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
|
46
|
-
end
|
47
|
-
|
48
|
-
if ARGV[0].nil?
|
49
|
-
Jtc.printhelp
|
50
|
-
end
|
51
41
|
|
52
42
|
opts.to_hash
|
53
43
|
|
54
44
|
if opts[:c] && opts[:w]
|
55
|
-
puts "\n\t
|
56
|
-
puts "\t You can't web clone and ssh clone"
|
57
|
-
puts "\t
|
58
|
-
puts "\t############################################\n
|
59
|
-
Jtc.printhelp
|
45
|
+
puts Rainbow("\n\t############################################").red
|
46
|
+
puts Rainbow("\t You can't web clone and ssh clone").red
|
47
|
+
puts Rainbow("\t gitlab-clone -h for more information").red
|
48
|
+
puts Rainbow("\t############################################\n").red
|
60
49
|
else
|
61
50
|
|
51
|
+
if opts[:o] && !opts[:g]
|
52
|
+
puts Rainbow("Github option requiers you to enter a organizational name.\n\n").red
|
53
|
+
end
|
54
|
+
|
62
55
|
if opts[:g]
|
63
56
|
clone_group = opts[:g]
|
64
|
-
elsif opts[:l] || opts[:o] || opts[:w] || opts[:c]
|
65
|
-
puts "
|
57
|
+
elsif opts[:l] || opts[:o] || opts[:w] || opts[:c]
|
58
|
+
puts Rainbow("\nNo organizational or group name was given. Using default of \"Cookbooks\"\n\n").purple.italic
|
66
59
|
clone_group = "Cookbooks"
|
67
60
|
end
|
68
61
|
|
69
|
-
|
70
62
|
if opts[:o]
|
71
63
|
class_to_use = Github
|
72
64
|
else
|
73
|
-
class_to_use =
|
65
|
+
class_to_use = Gitlab
|
74
66
|
end
|
75
67
|
|
76
68
|
if opts[:h]
|
77
|
-
|
69
|
+
Gitlab.printhelp
|
70
|
+
elsif opts[:r]
|
71
|
+
Setup.configure
|
78
72
|
elsif opts[:c]
|
79
73
|
class_to_use.clone(0, clone_group)
|
80
74
|
elsif opts[:w]
|
81
75
|
class_to_use.clone(1, clone_group)
|
82
76
|
elsif opts[:v]
|
83
|
-
|
77
|
+
Version::version
|
78
|
+
elsif opts[:n]
|
79
|
+
Gitlab.config
|
84
80
|
elsif opts[:l]
|
85
|
-
class_to_use.list_repos(clone_group)
|
81
|
+
class_to_use.list_repos(clone_group)
|
86
82
|
end
|
87
83
|
end
|
88
|
-
|
89
|
-
|
data/gitlab_clone.gemspec
CHANGED
@@ -4,18 +4,18 @@ require 'version'
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = 'gitlab_clone'
|
7
|
-
s.version = Version::
|
8
|
-
s.date = '
|
7
|
+
s.version = Version::current
|
8
|
+
s.date = '2017-01-11'
|
9
9
|
s.summary = "Pulls down the latest repos from a group in gitlab or a organization group in Github."
|
10
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
|
-
s.files
|
13
|
+
s.files = `git ls-files`.split($/)
|
14
14
|
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
15
|
s.add_dependency("git", "~> 1.2.6")
|
16
16
|
s.add_dependency("slop", "~> 3.5.0")
|
17
17
|
s.add_dependency("httparty", "~> 0.13.1")
|
18
|
-
s.homepage =
|
19
|
-
|
20
|
-
s.
|
18
|
+
s.homepage = 'https://github.com/ncamacho/gitlab_clone'
|
19
|
+
s.license = 'MIT'
|
20
|
+
s.post_install_message = "\n\n\tGitlab Clone is now installed!\n\n"
|
21
21
|
end
|
data/lib/github.rb
CHANGED
@@ -22,11 +22,11 @@ def self.clone(web, group_name)
|
|
22
22
|
if File.directory?("#{repos_dir}")
|
23
23
|
FileUtils::mkdir_p repos_dir
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
if web == 1
|
27
27
|
repo_location = 'clone_url'
|
28
28
|
message = "Web"
|
29
|
-
else
|
29
|
+
else
|
30
30
|
repo_location = 'ssh_url'
|
31
31
|
message = "Ssh"
|
32
32
|
end
|
@@ -47,7 +47,7 @@ def self.clone(web, group_name)
|
|
47
47
|
g.pull
|
48
48
|
else
|
49
49
|
puts "\tCloning #{repo_name}..."
|
50
|
-
Git.clone("#{repo}", "#{repo_dir}")
|
50
|
+
Git.clone("#{repo}", "#{repo_dir}")
|
51
51
|
end
|
52
52
|
end
|
53
53
|
puts "-------------------------------------------------------------------\n"
|
@@ -57,4 +57,4 @@ def self.clone(web, group_name)
|
|
57
57
|
string = HTTParty.get("#{SERVER}/orgs/#{group_name}/repos", :headers => {"Authorization" => "token #{TOKEN}", 'User-Agent' => 'HTTParty'}, :verify => false).to_json
|
58
58
|
rep = JSON.parse(string)
|
59
59
|
end
|
60
|
-
end
|
60
|
+
end
|
data/lib/gitlab.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
class Gitlab
|
2
|
+
require "setup"
|
3
|
+
require "rainbow"
|
4
|
+
|
5
|
+
user_home = ENV['HOME']
|
6
|
+
user_defined_dir = "code" ### need to add the ability to set this dynamically
|
7
|
+
HOME = "#{user_home}/#{user_defined_dir}"
|
8
|
+
|
9
|
+
def self.printhelp
|
10
|
+
puts Rainbow("---------------------------------------------------------------------------------------\n").green
|
11
|
+
puts Rainbow("\t\t###### Options for gitlab_clone ######\n\n").green
|
12
|
+
puts Rainbow("\t-h, --help: shows this help message").green
|
13
|
+
puts Rainbow("\t-c, --clone: clones all repos from https://gitlab_server/groups/Cookbooks
|
14
|
+
into a ~/code/Cookbooks directory by default").green
|
15
|
+
puts Rainbow("\t-w, --web: will clone using web protocol instead of ssh").green
|
16
|
+
puts Rainbow("\t-l, --list: will give you a list of repos in git").green
|
17
|
+
puts Rainbow("\t-g, --group: will let you choose which gitlab group to look for repos in").green
|
18
|
+
puts Rainbow("\t-o, --github: will allow you to clone from Github").green
|
19
|
+
puts Rainbow("\t-n, --config: will print your current configuration settings").green
|
20
|
+
puts Rainbow("\t-r, --reconfigure: will start the configuration process\n\n").green
|
21
|
+
puts Rainbow("\t NOTE: You need to configure your settings first, with -r or --reconfigure.").green
|
22
|
+
puts Rainbow("\n---------------------------------------------------------------------------------------\n\n").green
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.list_repos(group_name)
|
26
|
+
repos_list = get_repos(group_name)
|
27
|
+
puts Rainbow("-------------------------------------------------------------------\n").green
|
28
|
+
puts Rainbow("\tThe following #{repos_list["projects"].length} repo(s) were found in the group #{group_name}.").green
|
29
|
+
repos_list["projects"].length.times do |get|
|
30
|
+
puts Rainbow("\t\t#{repos_list["projects"][get]["name"]}").blue
|
31
|
+
end
|
32
|
+
puts Rainbow("\n-------------------------------------------------------------------").green
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.clone(web, group_name)
|
36
|
+
repos_list = get_repos(group_name)
|
37
|
+
repos_dir = "#{HOME}/#{group_name}"
|
38
|
+
|
39
|
+
if File.directory?("#{repos_dir}")
|
40
|
+
FileUtils::mkdir_p repos_dir
|
41
|
+
end
|
42
|
+
|
43
|
+
if web == 1
|
44
|
+
repo_location = 'http_url_to_repo'
|
45
|
+
message = "Web"
|
46
|
+
else
|
47
|
+
repo_location = 'ssh_url_to_repo'
|
48
|
+
message = "Ssh"
|
49
|
+
end
|
50
|
+
puts Rainbow("-------------------------------------------------------------------\n").green
|
51
|
+
puts Rainbow("\t### Starting #{message} Clone Process Of The Group #{group_name} ###").green
|
52
|
+
puts Rainbow("\tDownloading #{repos_list["projects"].length} repo(s) into #{repos_dir}\n").green
|
53
|
+
|
54
|
+
repos_list["projects"].length.times do |get|
|
55
|
+
repo_name = repos_list["projects"][get]["name"]
|
56
|
+
repo = repos_list["projects"][get]["#{repo_location}"]
|
57
|
+
dir = repos_list["projects"][get]["name"]
|
58
|
+
repo_dir = "#{repos_dir}/#{dir}"
|
59
|
+
|
60
|
+
if File.directory?("#{repo_dir}")
|
61
|
+
puts Rainbow("\t\"#{repo_name}\" repo directory exists, doing a git pull instead.").purple
|
62
|
+
Dir.chdir("#{repo_dir}")
|
63
|
+
g = Git.init
|
64
|
+
g.pull
|
65
|
+
else
|
66
|
+
puts Rainbow("\tCloning repo \"#{repo_name}\"...").blue
|
67
|
+
Git.clone("#{repo}", "#{repo_dir}")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
puts Rainbow("\n-------------------------------------------------------------------\n").green
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.get_repos(group_name)
|
74
|
+
group_id = get_groups[group_name]
|
75
|
+
string = HTTParty.get("#{Setup.get_gitlabserver}/groups/#{group_id}", :headers => {"PRIVATE-TOKEN" => "#{Setup.get_token}" }, :verify => false).to_json
|
76
|
+
rep = JSON.parse(string)
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.get_groups
|
80
|
+
string = HTTParty.get("#{Setup.get_gitlabserver}/groups", :headers => {"PRIVATE-TOKEN" => "#{Setup.get_token}" }, :verify => false).to_json
|
81
|
+
api_ids = JSON.parse(string)
|
82
|
+
group_ids = {}
|
83
|
+
api_ids.each do |id|
|
84
|
+
group_ids["#{id["name"]}"] = id["id"]
|
85
|
+
end
|
86
|
+
return group_ids
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.config
|
90
|
+
puts Rainbow("################### Current Gitlab Configuration ###################").green
|
91
|
+
puts
|
92
|
+
puts Rainbow("\tCurrent Gitlab token:\t\t #{Setup.get_token}").green
|
93
|
+
puts Rainbow("\tCurrent Gitlab server address:\t #{Setup.get_gitlabserver}").green
|
94
|
+
if Setup.github_precheck
|
95
|
+
puts Rainbow("\tCurrent Github token:\t\t #{Setup.get_github_token}").green
|
96
|
+
end
|
97
|
+
puts Rainbow("\tCurrent home directory:\t\t #{HOME}").green
|
98
|
+
puts
|
99
|
+
puts Rainbow("#######################################################################").green
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
data/lib/setup.rb
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
class Setup
|
2
|
+
require "rainbow"
|
3
|
+
|
4
|
+
user_home=ENV['HOME']
|
5
|
+
CONFIG = "#{user_home}/.gitlab_config"
|
6
|
+
|
7
|
+
### This checks to see if the json we are getting from the file is valid or not.
|
8
|
+
def self.valid_json
|
9
|
+
JSON.parse(File.read(CONFIG))
|
10
|
+
return true
|
11
|
+
rescue JSON::ParserError
|
12
|
+
return false
|
13
|
+
end
|
14
|
+
|
15
|
+
### Precheck to see if we have a token yet in the file
|
16
|
+
def self.github_precheck
|
17
|
+
if File.exist?(CONFIG) && self.valid_json
|
18
|
+
JSON.parse(File.read(CONFIG))
|
19
|
+
params = JSON.parse(File.read(CONFIG))
|
20
|
+
if params["github_token"]
|
21
|
+
return true
|
22
|
+
else
|
23
|
+
return false
|
24
|
+
end
|
25
|
+
else
|
26
|
+
return false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
### Prehceck to see if we dont have a file or vaild json in the file
|
31
|
+
def self.precheck
|
32
|
+
if !File.exist?(CONFIG) or !self.valid_json
|
33
|
+
return false
|
34
|
+
else
|
35
|
+
return true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
### This does a check to see if we have a server or token set and if we don't start the configureation process
|
40
|
+
def self.check
|
41
|
+
if File.exist?(CONFIG) && self.valid_json
|
42
|
+
JSON.parse(File.read(CONFIG))
|
43
|
+
params = JSON.parse(File.read(CONFIG))
|
44
|
+
unless params["gitlab_server"] && params["gitlab_token"]
|
45
|
+
puts Rainbow("It looks like either your server or token is not set properly. Do you wish to add them now? ").yellow
|
46
|
+
answer = STDIN.gets.chomp.downcase
|
47
|
+
if answer == "y" or answer == "yes"
|
48
|
+
self.configure
|
49
|
+
end
|
50
|
+
end
|
51
|
+
else
|
52
|
+
puts Rainbow("You do not have a valid config file. Do you wish to create one now and configure it? ").yellow
|
53
|
+
answer = STDIN.gets.chomp.downcase
|
54
|
+
if answer == "y" or answer == "yes"
|
55
|
+
self.configure
|
56
|
+
else
|
57
|
+
puts Rainbow("Ok, but nothing is going to work till you do....\n").yellow
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
### This configures the config file for gitlab settings.
|
63
|
+
def self.configure
|
64
|
+
if File.exist?(CONFIG)
|
65
|
+
JSON.parse(File.read(CONFIG))
|
66
|
+
params = JSON.parse(File.read(CONFIG))
|
67
|
+
else
|
68
|
+
params = {}
|
69
|
+
end
|
70
|
+
puts Rainbow("What is the name of your gitlab server?\nExample: http[s]://server.domain.tld:\nServer: ").purple
|
71
|
+
answer = STDIN.gets.chomp.downcase
|
72
|
+
answer = "#{answer}/api/v3"
|
73
|
+
params["gitlab_server"] = answer
|
74
|
+
params["gitlab_server"]
|
75
|
+
puts Rainbow("What is your token?\nExample: 3pe14gZfap:\nToken: ").purple
|
76
|
+
params["gitlab_token"] = STDIN.gets.chomp
|
77
|
+
puts Rainbow("Do you wish to do the Github token now too? ").purple
|
78
|
+
answer = STDIN.gets.chomp.downcase
|
79
|
+
|
80
|
+
if answer == "y" or answer == "yes"
|
81
|
+
puts Rainbow("What is your Github token? ").purple
|
82
|
+
params["github_token"] = STDIN.gets.chomp
|
83
|
+
end
|
84
|
+
|
85
|
+
save = JSON.generate(params)
|
86
|
+
puts Rainbow("\n\nUpdating config file with the following:").purple
|
87
|
+
puts Rainbow("Gitlab server: #{params["gitlab_server"]}").purple
|
88
|
+
puts Rainbow("Gitlab token: #{params["gitlab_token"]}").purple
|
89
|
+
|
90
|
+
if params["github_token"]
|
91
|
+
puts Rainbow("Github token: #{params["github_token"]}").purple
|
92
|
+
end
|
93
|
+
|
94
|
+
puts Rainbow("\nIs this information correct? ").yellow
|
95
|
+
answer = STDIN.gets.chomp.downcase
|
96
|
+
if answer == "y" or answer == "yes"
|
97
|
+
config_file = File.open(CONFIG, "w")
|
98
|
+
config_file.write(save)
|
99
|
+
config_file.close
|
100
|
+
puts Rainbow("Configuration saved.\n\n").green
|
101
|
+
exit
|
102
|
+
else
|
103
|
+
self.configure
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
### This configures the github token
|
108
|
+
def self.github_configure
|
109
|
+
if self.precheck && !self.github_precheck
|
110
|
+
params = JSON.parse(File.read(CONFIG))
|
111
|
+
puts Rainbow("What is your Github token?\nExample: 3pe14gZfap:\nToken: ").purple
|
112
|
+
params["github_token"] = STDIN.gets.chomp
|
113
|
+
save = JSON.generate(params)
|
114
|
+
puts Rainbow("\n\nUpdating config file with the following:
|
115
|
+
Github token: #{params["github_token"]} \n\n").purple
|
116
|
+
puts Rainbow("Is this information correct? ").yellow
|
117
|
+
answer = STDIN.gets.chomp.downcase
|
118
|
+
if answer == "y" or answer == "yes"
|
119
|
+
config_file = File.open(CONFIG, "w")
|
120
|
+
config_file.write(save)
|
121
|
+
config_file.close
|
122
|
+
puts Rainbow("Configuration saved.\n\n").green
|
123
|
+
exit
|
124
|
+
end
|
125
|
+
else
|
126
|
+
puts "Whoa! Looks like we don't have configuration file yet. Do you want to create one now?"
|
127
|
+
answer = STDIN.gets.chomp.downcase
|
128
|
+
if answer == "y" or answer == "yes"
|
129
|
+
self.configure
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
### Get the token in the file
|
135
|
+
def self.get_token
|
136
|
+
unless Setup.precheck
|
137
|
+
puts Rainbow("\n\nWhoops! Looks like we have not setup a config before...\n").yellow
|
138
|
+
Setup.configure
|
139
|
+
else
|
140
|
+
JSON.parse(File.read(CONFIG))
|
141
|
+
params = JSON.parse(File.read(CONFIG))
|
142
|
+
return params["gitlab_token"]
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
### Get the token in the file
|
147
|
+
def self.get_github_token
|
148
|
+
unless Setup.github_precheck
|
149
|
+
puts Rainbow("\n\nWhoops! Looks like we have not setup a github token yet...\n").yellow
|
150
|
+
Setup.github_configure
|
151
|
+
else
|
152
|
+
JSON.parse(File.read(CONFIG))
|
153
|
+
params = JSON.parse(File.read(CONFIG))
|
154
|
+
return params["github_token"]
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
### Get the gitlabserver in the file
|
159
|
+
def self.get_gitlabserver
|
160
|
+
unless Setup.precheck
|
161
|
+
puts Rainbow("\n\nWhoops! Looks like we have not setup a config before...\n").yellow
|
162
|
+
Setup.configure
|
163
|
+
else
|
164
|
+
JSON.parse(File.read(CONFIG))
|
165
|
+
params = JSON.parse(File.read(CONFIG))
|
166
|
+
return params["gitlab_server"]
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
data/lib/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.12.1
|
data/lib/version.rb
CHANGED
@@ -1,3 +1,12 @@
|
|
1
1
|
module Version
|
2
|
-
|
2
|
+
require "rainbow"
|
3
|
+
def self.current
|
4
|
+
File.open(File.expand_path('../version', __FILE__)).read
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.version
|
8
|
+
puts Rainbow("\n\n\----------------------------------------------------------------\n").green
|
9
|
+
puts Rainbow("\t\tCurrent Gitlab-Clone version is #{Version::current}").green
|
10
|
+
puts Rainbow("----------------------------------------------------------------\n\n").green
|
11
|
+
end
|
3
12
|
end
|
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.
|
4
|
+
version: 0.12.1
|
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:
|
11
|
+
date: 2017-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: git
|
@@ -64,14 +64,15 @@ files:
|
|
64
64
|
- changelog
|
65
65
|
- gitlab_clone.gemspec
|
66
66
|
- lib/github.rb
|
67
|
-
- lib/
|
67
|
+
- lib/gitlab.rb
|
68
|
+
- lib/setup.rb
|
68
69
|
- lib/version
|
69
70
|
- lib/version.rb
|
70
71
|
homepage: https://github.com/ncamacho/gitlab_clone
|
71
72
|
licenses:
|
72
73
|
- MIT
|
73
74
|
metadata: {}
|
74
|
-
post_install_message:
|
75
|
+
post_install_message: "\n\n\tGitlab Clone is now installed!\n\n"
|
75
76
|
rdoc_options: []
|
76
77
|
require_paths:
|
77
78
|
- lib
|
@@ -87,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
88
|
version: '0'
|
88
89
|
requirements: []
|
89
90
|
rubyforge_project:
|
90
|
-
rubygems_version: 2.
|
91
|
+
rubygems_version: 2.5.1
|
91
92
|
signing_key:
|
92
93
|
specification_version: 4
|
93
94
|
summary: Pulls down the latest repos from a group in gitlab or a organization group
|
data/lib/jtc.rb
DELETED
@@ -1,95 +0,0 @@
|
|
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
|
-
puts "\t-o, --github: will use Github instead of Gitlab for git server."
|
17
|
-
|
18
|
-
puts "\t NOTE: You need to set gitlab_server and gitlab_token or github_token for this to work."
|
19
|
-
puts "\t\texample: export gitlab_server=\"http[s]://[server_name]/api/v3\""
|
20
|
-
puts "\t\t\t export gitlab_token=\"secret_token\""
|
21
|
-
puts "\t\t\t export github_token=\"secret_token\""
|
22
|
-
puts "-------------------------------------------------------------------\n\n"
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.list_repos(group_name)
|
26
|
-
repos_list = get_repos(group_name)
|
27
|
-
puts "-------------------------------------------------------------------\n"
|
28
|
-
puts "\tThe following #{repos_list["projects"].length} repo(s) were found in the group #{group_name}.\n\n"
|
29
|
-
repos_list["projects"].length.times do |get|
|
30
|
-
puts "\t\t#{repos_list["projects"][get]["name"]}"
|
31
|
-
end
|
32
|
-
puts "\n-------------------------------------------------------------------"
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.clone(web, group_name)
|
36
|
-
repos_list = get_repos(group_name)
|
37
|
-
repos_dir = "#{HOME}/projects/#{group_name}"
|
38
|
-
|
39
|
-
if File.directory?("#{repos_dir}")
|
40
|
-
FileUtils::mkdir_p repos_dir
|
41
|
-
end
|
42
|
-
|
43
|
-
if web == 1
|
44
|
-
repo_location = 'http_url_to_repo'
|
45
|
-
message = "Web"
|
46
|
-
else
|
47
|
-
repo_location = 'ssh_url_to_repo'
|
48
|
-
message = "Ssh"
|
49
|
-
end
|
50
|
-
puts "-------------------------------------------------------------------\n"
|
51
|
-
puts "\t### Starting #{message} Clone Process Of The Group #{group_name} ###\n\n"
|
52
|
-
puts "\tDownloading #{repos_list["projects"].length} repo(s) into #{repos_dir}\n\n"
|
53
|
-
|
54
|
-
repos_list["projects"].length.times do |get|
|
55
|
-
repo_name = repos_list["projects"][get]["name"]
|
56
|
-
repo = repos_list["projects"][get]["#{repo_location}"]
|
57
|
-
dir = repos_list["projects"][get]["name"]
|
58
|
-
repo_dir = "#{repos_dir}/#{dir}"
|
59
|
-
|
60
|
-
if File.directory?("#{repo_dir}")
|
61
|
-
puts "\t#{repo_name} directory exists, doing a git pull instead."
|
62
|
-
Dir.chdir("#{repo_dir}")
|
63
|
-
g = Git.init
|
64
|
-
g.pull
|
65
|
-
else
|
66
|
-
puts "\tCloning #{repo_name}..."
|
67
|
-
Git.clone("#{repo}", "#{repo_dir}")
|
68
|
-
end
|
69
|
-
end
|
70
|
-
puts "-------------------------------------------------------------------\n"
|
71
|
-
end
|
72
|
-
|
73
|
-
def self.get_repos(group_name)
|
74
|
-
group_id = get_groups[group_name]
|
75
|
-
string = HTTParty.get("#{SERVER}/groups/#{group_id}", :headers => {"PRIVATE-TOKEN" => "#{TOKEN}" }, :verify => false).to_json
|
76
|
-
rep = JSON.parse(string)
|
77
|
-
end
|
78
|
-
|
79
|
-
def self.get_groups
|
80
|
-
string = HTTParty.get("#{SERVER}/groups", :headers => {"PRIVATE-TOKEN" => "#{TOKEN}" }, :verify => false).to_json
|
81
|
-
api_ids = JSON.parse(string)
|
82
|
-
group_ids = {}
|
83
|
-
api_ids.each do |id|
|
84
|
-
group_ids["#{id["name"]}"] = id["id"]
|
85
|
-
end
|
86
|
-
return group_ids
|
87
|
-
end
|
88
|
-
|
89
|
-
def self.version
|
90
|
-
puts "----------------------------------------------------------------\n\n"
|
91
|
-
puts "\t\tCurrent gitlab-clone verison is #{Version::VERSION}\n"
|
92
|
-
puts "----------------------------------------------------------------\n\n"
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|