stash-clone-tool 1.0.5 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ebc88ad19870702aa2a90ad2644f6d2eeee3a12
4
- data.tar.gz: 9fe7de3380c8067c1a9f96645363c80e91fad836
3
+ metadata.gz: 4b1ae15f4539ffe0fc37dfd2446290f97a35d4e7
4
+ data.tar.gz: 3ca8efa8ff5ddca48a3cbb7999b1723fc78f2e9c
5
5
  SHA512:
6
- metadata.gz: 743aaaa6a73c9ebe532f20fbea2a184fdf3d6ecb79f3ff9a53aceca89e3f642489aba9cd62db630e8f037805051c8172b8fd622d95a8abca794ef8e3524e7365
7
- data.tar.gz: 4251cc618255a1f832a52a5cbb5e7c8f60fad77628eb079d33ff0d0da294c5099dc690a964ccb351a2d5451fb6825f4b12206c41ff6aefe509b54e3f7ced082d
6
+ metadata.gz: '09b441285ec41e03cbd3e5cbe8200c7782f6761b1a7a72bf596003389c8fdd149ff11e0037ea98370dfab5e3a2d0ba9eaf4d22e2fe73740ffbc6e55f50434de7'
7
+ data.tar.gz: e97f16866ea5b34d55e0b5653934ff3a65d8c5d8a0280fc442a7b907f8601c0e83bf8222f0bdd2e75df903d7d256d4d78a8e830de361c63d3a103bec50d6a332
data/.gitignore CHANGED
@@ -1,8 +1,9 @@
1
- /.idea
1
+ /*.gem
2
2
  /.bundle/
3
- /Gemfile.lock
3
+ /.idea
4
+ /coverage/
4
5
  /doc/
6
+ /Gemfile.lock
5
7
  /pkg/
6
8
  /spec/reports/
7
- /tmp/
8
- /*.gem
9
+ /tmp/
data/.overcommit.yml ADDED
@@ -0,0 +1,15 @@
1
+ PreCommit:
2
+ BundleCheck:
3
+ enabled: true
4
+ FixMe:
5
+ enabled: true
6
+ keywords: ["FIXME", "TODO"]
7
+ exclude:
8
+ - .overcommit.yml
9
+ RuboCop:
10
+ enabled: true
11
+ on_warn: fail
12
+ command: ['bundle', 'exec', 'rubocop']
13
+ PrePush:
14
+ RSpec:
15
+ enabled: true
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ Metrics/LineLength:
2
+ Max: 120
3
+ Metrics/MethodLength:
4
+ Max: 40
5
+ Metrics/AbcSize:
6
+ Enabled: false
7
+ Documentation:
8
+ Enabled: false
9
+ Style/ClassAndModuleChildren:
10
+ Enabled: false
11
+ Style/AlignHash:
12
+ Enabled: false
13
+ Style/MultilineOperationIndentation:
14
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.13.7
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gemspec
3
+ gemspec
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/paul-ridgway/stash-clone-tool.svg?branch=master)](https://travis-ci.org/paul-ridgway/stash-clone-tool)
2
+
1
3
  # Stash Clone Tool
2
4
  Clones all repositories in all projects a user has access to from a stash server.
3
5
 
@@ -5,7 +7,7 @@ Simple to use, enter the stash url, username and password.
5
7
 
6
8
  Feel free to contribute at https://github.com/paul-ridgway/stash-clone-tool.
7
9
 
8
- # Usage
10
+ ## Usage
9
11
  Install the stash clone tool:
10
12
 
11
13
  gem install stash-clone-tool
@@ -16,3 +18,17 @@ You can now clone all repositories in all the projects you have access to:
16
18
 
17
19
  Omit the password argument (-p) to enter your password via masked standard input.
18
20
 
21
+ ## Development
22
+ stash-clone-tool uses rubocop and overcommit to ensure build quality.
23
+
24
+ To enable overcommit:
25
+
26
+ $ overcommit && overcommit --sign
27
+
28
+ To check code style:
29
+
30
+ $ bundle exec rubocop
31
+
32
+ The project can be build (which also runs rubocop), using:
33
+
34
+ $ bundle exec rake
data/Rakefile CHANGED
@@ -1 +1,12 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'rubocop/rake_task'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ desc 'Run rubocop'
8
+ task :rubocop do
9
+ RuboCop::RakeTask.new
10
+ end
11
+
12
+ task default: [:rubocop, :spec, :build]
data/bin/stash-clone-tool CHANGED
@@ -4,10 +4,10 @@ require 'bundler/setup'
4
4
  require 'stash_clone_tool/stash_cloner'
5
5
  require 'optparse'
6
6
  require 'highline/import'
7
- options = {directory: '.'}
7
+ options = { directory: '.' }
8
8
  clone_options = {}
9
9
  exclude = []
10
- cli = OptionParser.new do |opts|
10
+ OptionParser.new do |opts|
11
11
  opts.banner = 'Usage: stash-clone-tool [options]'
12
12
  opts.on('-s', '--stash URL', 'Stash Server URL (required)') do |stash_url|
13
13
  options[:stash_url] = stash_url
@@ -18,39 +18,41 @@ cli = OptionParser.new do |opts|
18
18
  opts.on('-p', '--password PASSWORD', 'Stash password') do |password|
19
19
  options[:password] = password
20
20
  end
21
- opts.on('-d', '--directory DIRECTORY_PATH', 'Path to clone stash projects into (default: working directory).') do |directory|
21
+ opts.on('-d', '--directory PATH', 'Path to clone stash projects into (default: working directory).') do |directory|
22
22
  options[:directory] = directory
23
23
  end
24
24
  opts.on('--depth DEPTH', 'Clone depth (assumes single branch unless --no-single-branch).') do |depth|
25
25
  clone_options[:depth] = depth
26
26
  end
27
- opts.on("--exclude AN,PS,JU", Array, "Project keys to exclude") do |list|
27
+ opts.on('--exclude KEY1,KEY2,...', Array, 'Project keys to exclude') do |list|
28
28
  list.each { |key| exclude << key }
29
29
  end
30
30
  end.parse!
31
31
 
32
- fail 'Must specify Stash server URL (-s).' if options[:stash_url].nil?
33
- fail 'Must specify Stash username (-u).' if options[:username].nil?
32
+ raise 'Must specify Stash server URL (-s).' if options[:stash_url].nil?
33
+ raise 'Must specify Stash username (-u).' if options[:username].nil?
34
34
 
35
35
  # Prompt for password if not provided on CLI
36
36
  options[:password] ||= ask('Password: ') { |q| q.echo = '*' }
37
37
 
38
- @last_project = nil
39
- cloner = StashCloneTool::StashCloner.new(options[:stash_url], options[:username], options[:password], options[:directory])
38
+ last_project = nil
39
+ cloner = StashCloneTool::StashCloner.new(options[:stash_url], options[:username], options[:password],
40
+ options[:directory])
40
41
 
41
42
  cloner.clone_stash(clone_options, exclude) do |on|
42
43
  on.initialize_repository do |repository, folder|
43
- if @last_project != repository.project
44
+ if last_project != repository.project
44
45
  puts " - #{repository.project.name} (#{repository.project.name}...".light_yellow
45
- @last_project = repository.project
46
+ last_project = repository.project
46
47
  end
47
48
  puts " - #{repository.name}...".light_yellow
48
- puts " Cloning ".light_blue + repository.clone_link(:ssh).light_white + " to ".light_blue + folder.light_white
49
+ puts ' Cloning '.light_blue + repository.clone_link(:ssh).light_white + ' to '.light_blue +
50
+ folder.light_white
49
51
  end
50
- on.success do |repository|
51
- puts " Cloned".light_green
52
+ on.success do |_|
53
+ puts ' Cloned'.light_green
52
54
  end
53
- on.failure do |repository, message|
55
+ on.failure do |_, message|
54
56
  puts " #{message}".light_red
55
57
  end
56
- end
58
+ end
@@ -1,12 +1,10 @@
1
1
  module StashCloneTool
2
2
  class CloneLink
3
-
4
3
  attr_reader :uri, :type
5
4
 
6
5
  def initialize(link)
7
6
  @uri = link['href']
8
7
  @type = link['name'].to_sym
9
8
  end
10
-
11
9
  end
12
- end
10
+ end
@@ -1,6 +1,5 @@
1
1
  module StashCloneTool
2
2
  class Project
3
-
4
3
  attr_reader :name, :key, :repositories
5
4
 
6
5
  def initialize(client, json)
@@ -9,4 +8,4 @@ module StashCloneTool
9
8
  @repositories = client.get_repositories(self)
10
9
  end
11
10
  end
12
- end
11
+ end
@@ -16,7 +16,9 @@ module StashCloneTool
16
16
  end
17
17
 
18
18
  def get_repositories(project)
19
- request("/rest/api/1.0/projects/#{project.key}/repos")['values'].map { |json| StashRepository.new(project, json) }
19
+ request("/rest/api/1.0/projects/#{project.key}/repos?limit=100")['values'].map do |json|
20
+ StashRepository.new(project, json)
21
+ end
20
22
  end
21
23
 
22
24
  private
@@ -25,16 +27,19 @@ module StashCloneTool
25
27
  uri = URI("#{@stash_url}#{url}")
26
28
  req = Net::HTTP::Get.new(uri.to_s)
27
29
  req.basic_auth @username, @password
28
- response = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == 'https') do |http|
30
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
29
31
  http.request(req)
30
32
  end
31
- json = JSON.parse(response.body)
33
+ process_response(response.body)
34
+ end
35
+
36
+ def process_response(body)
37
+ json = JSON.parse(body)
32
38
  if json['errors']
33
39
  error_msg = json['errors'].map { |e| e['message'] }.join('. ')
34
- raise StashException.new(error_msg)
40
+ raise StashException, error_msg
35
41
  end
36
42
  json
37
43
  end
38
-
39
44
  end
40
- end
45
+ end
@@ -6,7 +6,6 @@ require 'stash_clone_tool/stash_api_client'
6
6
  require 'stash_clone_tool/stash_repository'
7
7
  require 'stash_clone_tool/stash_exception'
8
8
  module StashCloneTool
9
-
10
9
  class StashCloner
11
10
  include StashCloneTool
12
11
 
@@ -23,16 +22,14 @@ module StashCloneTool
23
22
  project.repositories.each do |repository|
24
23
  folder = File.join(@directory, project.key, repository.slug)
25
24
  wrapper.call(:initialize_repository, repository, folder)
26
- clone_link = repository.clone_link(:ssh)
27
- if Dir.exists?(folder)
25
+ if Dir.exist?(folder)
28
26
  wrapper.call(:failure, repository, 'Target already exists')
29
27
  else
30
- Git.clone(clone_link, folder, clone_options)
28
+ Git.clone(repository.clone_link(:ssh), folder, clone_options)
31
29
  wrapper.call(:success, repository)
32
30
  end
33
31
  end
34
32
  end
35
33
  end
36
-
37
34
  end
38
35
  end
@@ -1,4 +1,4 @@
1
1
  module StashCloneTool
2
- class StashException < Exception
2
+ class StashException < RuntimeError
3
3
  end
4
- end
4
+ end
@@ -6,7 +6,7 @@ module StashCloneTool
6
6
 
7
7
  def initialize(project, repo)
8
8
  @name = repo['name']
9
- @clone_links = repo['links']['clone'].map{ |link| CloneLink.new(link)}
9
+ @clone_links = repo['links']['clone'].map { |link| CloneLink.new(link) }
10
10
  @slug = repo['slug']
11
11
  @project = project
12
12
  end
@@ -16,4 +16,4 @@ module StashCloneTool
16
16
  cl.uri
17
17
  end
18
18
  end
19
- end
19
+ end
@@ -1,4 +1,4 @@
1
1
  # Version
2
2
  module StashCloneTool
3
- VERSION = '1.0.5'
3
+ VERSION = '1.0.7'.freeze
4
4
  end
@@ -13,13 +13,8 @@ Gem::Specification.new do |spec|
13
13
  spec.description = 'Tool for cloning all projects from a Stash server.'
14
14
  spec.homepage = 'https://github.com/paul-ridgway/stash-clone-tool'
15
15
 
16
- # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
- # delete this section to allow pushing this gem to any host.
18
- if spec.respond_to?(:metadata)
19
- spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
- else
21
- fail 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
22
- end
16
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
17
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
23
18
 
24
19
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
20
  spec.bindir = 'bin'
@@ -28,6 +23,10 @@ Gem::Specification.new do |spec|
28
23
 
29
24
  spec.add_development_dependency 'bundler', '~> 1.10'
30
25
  spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rubocop'
27
+ spec.add_development_dependency 'overcommit'
28
+ spec.add_development_dependency 'rspec'
29
+ spec.add_development_dependency 'simplecov'
31
30
  spec.add_runtime_dependency 'colorize', '~> 0.7.7'
32
31
  spec.add_runtime_dependency 'highline', '~> 1.7', '>= 1.7.3'
33
32
  spec.add_runtime_dependency 'git', '~> 1.2', '>= 1.2.9.1'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stash-clone-tool
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Ridgway
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-05-14 00:00:00.000000000 Z
13
+ date: 2017-01-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -40,6 +40,62 @@ dependencies:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '10.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rubocop
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: overcommit
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: rspec
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
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: simplecov
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
43
99
  - !ruby/object:Gem::Dependency
44
100
  name: colorize
45
101
  requirement: !ruby/object:Gem::Requirement
@@ -119,6 +175,9 @@ extensions: []
119
175
  extra_rdoc_files: []
120
176
  files:
121
177
  - ".gitignore"
178
+ - ".overcommit.yml"
179
+ - ".rubocop.yml"
180
+ - ".travis.yml"
122
181
  - Gemfile
123
182
  - Gemfile.lock
124
183
  - README.md
@@ -154,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
213
  version: '0'
155
214
  requirements: []
156
215
  rubyforge_project:
157
- rubygems_version: 2.4.6
216
+ rubygems_version: 2.6.8
158
217
  signing_key:
159
218
  specification_version: 4
160
219
  summary: Tool for cloning all projects from a Stash server.