stash-clone-tool 1.0.0 → 1.0.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 +4 -4
- data/.gitignore +1 -0
- data/README.md +18 -0
- data/bin/stash-clone-tool +20 -2
- data/lib/stash_clone_tool/clone_link.rb +12 -0
- data/lib/stash_clone_tool/project.rb +12 -0
- data/lib/stash_clone_tool/stash_api_client.rb +40 -0
- data/lib/stash_clone_tool/stash_cloner.rb +22 -54
- data/lib/stash_clone_tool/stash_repository.rb +19 -0
- data/lib/stash_clone_tool/version.rb +1 -1
- data/stash-clone-tool.gemspec +5 -3
- metadata +52 -16
- data/README +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57e7254c897b6edd74c17ef9fe668fa7b429d4c5
|
4
|
+
data.tar.gz: 77b7e57fee79af28c6397993f2f63ed583650a84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20e0b175098d681c12d56a01fe9e31c82b5a7c34017139c00d0713031cc9eb47730def6c466092ae9ddd5a6cb983ed179797459b34d67eeb34433d20dce57161
|
7
|
+
data.tar.gz: f980a627bcaf9811c7bfe88350f4ce4cc2a5c76a93c3f16e6d3c0831c29a51d9057630a96ec4a2dccd23f5b4fdc4c412fe6293ec461c555a42fdcf4ce78d30b4
|
data/.gitignore
CHANGED
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Stash Clone Tool
|
2
|
+
Clones all repositories in all projects a user has access to from a stash server.
|
3
|
+
|
4
|
+
Simple to use, enter the stash url, username and password.
|
5
|
+
|
6
|
+
Feel free to contribute at https://github.com/paul-ridgway/stash-clone-tool.
|
7
|
+
|
8
|
+
# Usage
|
9
|
+
Install the stash clone tool:
|
10
|
+
|
11
|
+
gem install stash-clone-tool
|
12
|
+
|
13
|
+
You can now clone all repositories in all the projects you have access to:
|
14
|
+
|
15
|
+
$ stash-clone-tool -s http://stash.example.com -u stashuser -p letmein
|
16
|
+
|
17
|
+
Omit the password argument (-p) to enter your password via masked standard input.
|
18
|
+
|
data/bin/stash-clone-tool
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
1
3
|
require 'bundler/setup'
|
2
4
|
require 'stash_clone_tool/stash_cloner'
|
3
5
|
require 'optparse'
|
@@ -25,6 +27,22 @@ fail 'Must specify Stash username (-u).' if options[:username].nil?
|
|
25
27
|
# Prompt for password if not provided on CLI
|
26
28
|
options[:password] ||= ask('Password: ') { |q| q.echo = '*' }
|
27
29
|
|
28
|
-
|
30
|
+
@last_project = nil
|
29
31
|
cloner = StashCloneTool::StashCloner.new(options[:stash_url], options[:username], options[:password], options[:directory])
|
30
|
-
|
32
|
+
|
33
|
+
cloner.clone_stash do |on|
|
34
|
+
on.initialize_repository do |repository, folder|
|
35
|
+
if @last_project != repository.project
|
36
|
+
puts " - #{repository.project.name}...".light_yellow
|
37
|
+
@last_project = repository.project
|
38
|
+
end
|
39
|
+
puts " - #{repository.name}...".light_yellow
|
40
|
+
puts " Cloning ".light_blue + repository.clone_link(:ssh).light_white + " to ".light_blue + folder.light_white
|
41
|
+
end
|
42
|
+
on.success do |repository|
|
43
|
+
puts " Cloned".light_green
|
44
|
+
end
|
45
|
+
on.failure do |repository, message|
|
46
|
+
puts " #{message}".light_red
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
require 'stash_clone_tool/project'
|
4
|
+
module StashCloneTool
|
5
|
+
class StashApiClient
|
6
|
+
include StashCloneTool
|
7
|
+
|
8
|
+
def initialize(stash_url, username, password)
|
9
|
+
@stash_url = stash_url
|
10
|
+
@username = username
|
11
|
+
@password = password
|
12
|
+
end
|
13
|
+
|
14
|
+
def projects
|
15
|
+
request('/rest/api/1.0/projects?limit=100')['values'].map { |json| Project.new(self, json) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_repositories(project)
|
19
|
+
request("/rest/api/1.0/projects/#{project.key}/repos")['values'].map { |json| StashRepository.new(project, json) }
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def request(url)
|
25
|
+
uri = URI("#{@stash_url}#{url}")
|
26
|
+
req = Net::HTTP::Get.new(uri.to_s)
|
27
|
+
req.basic_auth @username, @password
|
28
|
+
response = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == 'https') do |http|
|
29
|
+
http.request(req)
|
30
|
+
end
|
31
|
+
json = JSON.parse(response.body)
|
32
|
+
if json['errors']
|
33
|
+
error_msg = json['errors'].map { |e| e['message'] }.join('. ')
|
34
|
+
raise StashException.new(error_msg)
|
35
|
+
end
|
36
|
+
json
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -1,68 +1,36 @@
|
|
1
1
|
# Stash Cloner
|
2
|
-
require 'net/http'
|
3
|
-
require 'json'
|
4
2
|
require 'colorize'
|
3
|
+
require 'git'
|
4
|
+
require 'multiblock'
|
5
|
+
require 'stash_clone_tool/stash_api_client'
|
6
|
+
require 'stash_clone_tool/stash_repository'
|
5
7
|
require 'stash_clone_tool/stash_exception'
|
6
8
|
module StashCloneTool
|
9
|
+
|
7
10
|
class StashCloner
|
11
|
+
include StashCloneTool
|
8
12
|
|
9
13
|
def initialize(stash_url, username, password, directory)
|
10
|
-
@
|
11
|
-
@username = username
|
12
|
-
@password = password
|
14
|
+
@stash = StashApiClient.new(stash_url, username, password)
|
13
15
|
@directory = directory
|
14
16
|
end
|
15
17
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
def process_repo(project_key, repo)
|
33
|
-
puts " - #{repo['name']}...".light_yellow
|
34
|
-
clone_links = repo['links']['clone']
|
35
|
-
clone_link = clone_links.select { |l| l['name'] == 'ssh' }.first['href']
|
36
|
-
folder = File.join(@directory, project_key, repo['slug'])
|
37
|
-
git_command = "git clone #{clone_link} #{folder}"
|
38
|
-
puts " Cloning ".light_blue + clone_link.light_white + " to ".light_blue + folder.light_white
|
39
|
-
if Dir.exists?(folder)
|
40
|
-
puts " Target already exists".light_red
|
41
|
-
else
|
42
|
-
puts " #{git_command}".light_green
|
43
|
-
puts
|
44
|
-
system(git_command)
|
45
|
-
puts
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def request(url)
|
50
|
-
uri = URI("#{@stash_url}#{url}")
|
51
|
-
req = Net::HTTP::Get.new(uri.to_s)
|
52
|
-
req.basic_auth @username, @password
|
53
|
-
response = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == 'https') do |http|
|
54
|
-
http.request(req)
|
18
|
+
def clone_stash
|
19
|
+
wrapper = Multiblock.wrapper
|
20
|
+
yield(wrapper)
|
21
|
+
@stash.projects.each do |project|
|
22
|
+
project.repositories.each do |repository|
|
23
|
+
folder = File.join(@directory, project.key, repository.slug)
|
24
|
+
wrapper.call(:initialize_repository, repository, folder)
|
25
|
+
clone_link = repository.clone_link(:ssh)
|
26
|
+
if Dir.exists?(folder)
|
27
|
+
wrapper.call(:failure, repository, 'Target already exists')
|
28
|
+
else
|
29
|
+
Git.clone(clone_link, folder)
|
30
|
+
wrapper.call(:success, repository)
|
31
|
+
end
|
32
|
+
end
|
55
33
|
end
|
56
|
-
json = JSON.parse(response.body)
|
57
|
-
if json['errors']
|
58
|
-
error_msg = json['errors'].map { |e| e['message'] }.join('. ')
|
59
|
-
raise StashException.new(error_msg)
|
60
|
-
end
|
61
|
-
json
|
62
|
-
end
|
63
|
-
|
64
|
-
def get_projects
|
65
|
-
request('/rest/api/1.0/projects?limit=100')
|
66
34
|
end
|
67
35
|
|
68
36
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'stash_clone_tool/clone_link'
|
2
|
+
module StashCloneTool
|
3
|
+
class StashRepository
|
4
|
+
include StashCloneTool
|
5
|
+
attr_reader :name, :slug, :project
|
6
|
+
|
7
|
+
def initialize(project, repo)
|
8
|
+
@name = repo['name']
|
9
|
+
@clone_links = repo['links']['clone'].map{ |link| CloneLink.new(link)}
|
10
|
+
@slug = repo['slug']
|
11
|
+
@project = project
|
12
|
+
end
|
13
|
+
|
14
|
+
def clone_link(type)
|
15
|
+
cl = @clone_links.select { |link| link.type == type }.first
|
16
|
+
cl.uri
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/stash-clone-tool.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'stash_clone_tool/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'stash-clone-tool'
|
8
8
|
spec.version = StashCloneTool::VERSION
|
9
|
-
spec.authors = ['Paul Ridgway']
|
10
|
-
spec.email = ['paul@thefloow.com']
|
9
|
+
spec.authors = ['Paul Ridgway', 'James Ridgway', 'Douglas Mills']
|
10
|
+
spec.email = ['paul@thefloow.com', 'james.ridgway@thefloow.com', 'douglas.mills@thefloow.com']
|
11
11
|
|
12
12
|
spec.summary = 'Tool for cloning all projects from a Stash server.'
|
13
13
|
spec.description = 'Tool for cloning all projects from a Stash server.'
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
17
|
# delete this section to allow pushing this gem to any host.
|
18
18
|
if spec.respond_to?(:metadata)
|
19
|
-
spec.metadata['allowed_push_host'] = "
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
20
|
else
|
21
21
|
fail 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
22
22
|
end
|
@@ -30,4 +30,6 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency 'rake', '~> 10.0'
|
31
31
|
spec.add_dependency 'colorize'
|
32
32
|
spec.add_dependency 'highline'
|
33
|
+
spec.add_dependency 'git'
|
34
|
+
spec.add_dependency 'multiblock'
|
33
35
|
end
|
metadata
CHANGED
@@ -1,112 +1,148 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stash-clone-tool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Ridgway
|
8
|
+
- James Ridgway
|
9
|
+
- Douglas Mills
|
8
10
|
autorequire:
|
9
11
|
bindir: bin
|
10
12
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
13
|
+
date: 2015-08-16 00:00:00.000000000 Z
|
12
14
|
dependencies:
|
13
15
|
- !ruby/object:Gem::Dependency
|
14
16
|
name: bundler
|
15
17
|
requirement: !ruby/object:Gem::Requirement
|
16
18
|
requirements:
|
17
|
-
- - ~>
|
19
|
+
- - "~>"
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: '1.10'
|
20
22
|
type: :development
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
23
25
|
requirements:
|
24
|
-
- - ~>
|
26
|
+
- - "~>"
|
25
27
|
- !ruby/object:Gem::Version
|
26
28
|
version: '1.10'
|
27
29
|
- !ruby/object:Gem::Dependency
|
28
30
|
name: rake
|
29
31
|
requirement: !ruby/object:Gem::Requirement
|
30
32
|
requirements:
|
31
|
-
- - ~>
|
33
|
+
- - "~>"
|
32
34
|
- !ruby/object:Gem::Version
|
33
35
|
version: '10.0'
|
34
36
|
type: :development
|
35
37
|
prerelease: false
|
36
38
|
version_requirements: !ruby/object:Gem::Requirement
|
37
39
|
requirements:
|
38
|
-
- - ~>
|
40
|
+
- - "~>"
|
39
41
|
- !ruby/object:Gem::Version
|
40
42
|
version: '10.0'
|
41
43
|
- !ruby/object:Gem::Dependency
|
42
44
|
name: colorize
|
43
45
|
requirement: !ruby/object:Gem::Requirement
|
44
46
|
requirements:
|
45
|
-
- -
|
47
|
+
- - ">="
|
46
48
|
- !ruby/object:Gem::Version
|
47
49
|
version: '0'
|
48
50
|
type: :runtime
|
49
51
|
prerelease: false
|
50
52
|
version_requirements: !ruby/object:Gem::Requirement
|
51
53
|
requirements:
|
52
|
-
- -
|
54
|
+
- - ">="
|
53
55
|
- !ruby/object:Gem::Version
|
54
56
|
version: '0'
|
55
57
|
- !ruby/object:Gem::Dependency
|
56
58
|
name: highline
|
57
59
|
requirement: !ruby/object:Gem::Requirement
|
58
60
|
requirements:
|
59
|
-
- -
|
61
|
+
- - ">="
|
60
62
|
- !ruby/object:Gem::Version
|
61
63
|
version: '0'
|
62
64
|
type: :runtime
|
63
65
|
prerelease: false
|
64
66
|
version_requirements: !ruby/object:Gem::Requirement
|
65
67
|
requirements:
|
66
|
-
- -
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: git
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :runtime
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: multiblock
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
type: :runtime
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
67
97
|
- !ruby/object:Gem::Version
|
68
98
|
version: '0'
|
69
99
|
description: Tool for cloning all projects from a Stash server.
|
70
100
|
email:
|
71
101
|
- paul@thefloow.com
|
102
|
+
- james.ridgway@thefloow.com
|
103
|
+
- douglas.mills@thefloow.com
|
72
104
|
executables:
|
73
105
|
- stash-clone-tool
|
74
106
|
extensions: []
|
75
107
|
extra_rdoc_files: []
|
76
108
|
files:
|
77
|
-
- .gitignore
|
109
|
+
- ".gitignore"
|
78
110
|
- Gemfile
|
79
111
|
- Gemfile.lock
|
80
|
-
- README
|
112
|
+
- README.md
|
81
113
|
- Rakefile
|
82
114
|
- bin/console
|
83
115
|
- bin/setup
|
84
116
|
- bin/stash-clone-tool
|
117
|
+
- lib/stash_clone_tool/clone_link.rb
|
118
|
+
- lib/stash_clone_tool/project.rb
|
119
|
+
- lib/stash_clone_tool/stash_api_client.rb
|
85
120
|
- lib/stash_clone_tool/stash_cloner.rb
|
86
121
|
- lib/stash_clone_tool/stash_exception.rb
|
122
|
+
- lib/stash_clone_tool/stash_repository.rb
|
87
123
|
- lib/stash_clone_tool/version.rb
|
88
124
|
- stash-clone-tool.gemspec
|
89
125
|
homepage: https://github.com/paul-ridgway/stash-clone-tool
|
90
126
|
licenses: []
|
91
127
|
metadata:
|
92
|
-
allowed_push_host:
|
128
|
+
allowed_push_host: https://rubygems.org
|
93
129
|
post_install_message:
|
94
130
|
rdoc_options: []
|
95
131
|
require_paths:
|
96
132
|
- lib
|
97
133
|
required_ruby_version: !ruby/object:Gem::Requirement
|
98
134
|
requirements:
|
99
|
-
- -
|
135
|
+
- - ">="
|
100
136
|
- !ruby/object:Gem::Version
|
101
137
|
version: '0'
|
102
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
139
|
requirements:
|
104
|
-
- -
|
140
|
+
- - ">="
|
105
141
|
- !ruby/object:Gem::Version
|
106
142
|
version: '0'
|
107
143
|
requirements: []
|
108
144
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.
|
145
|
+
rubygems_version: 2.4.6
|
110
146
|
signing_key:
|
111
147
|
specification_version: 4
|
112
148
|
summary: Tool for cloning all projects from a Stash server.
|