gl 0.2.1 → 0.3.0

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
  SHA256:
3
- metadata.gz: 9c68809c9d31ef96ad88527015b3432f3bd364769945b1b04117eb3b0e50f774
4
- data.tar.gz: 1d4e6bee5defb3ac371cebf07f847f2861cc20eda5af7ba272089657851e0959
3
+ metadata.gz: bcad142f18a5ae01fdf53d892e4f9046df3a37ae9e69802a1b63d084d4b11fcf
4
+ data.tar.gz: 06ecdaaaceff8b4241c33c66b7c066b4bad4302e3c08eabd033336d387b3564b
5
5
  SHA512:
6
- metadata.gz: 024c1f21ce307a94efc92e8891cb057ef007b21480182a6f8becb33f2e6e0c71b905a6631e99aebf67d472498beb7e3e1c140690264f5b7241c7a00ae1258fe6
7
- data.tar.gz: c54840dfbf91cc4d787995be0d45b0c4c820b2bbfa22bbe7e94b8819f9ec984967c5617a7f7e4bd410e6dea21e11276d49259587bdbfa33439cd09ab549ace55
6
+ metadata.gz: 86310a663708bc342f3b50e703bb2789a8b72d049c1a6f1dc225093205c3241cd353a7f787aa842b7d043a53ff1fd0922fce621df53145a470f97aa047ec90ac
7
+ data.tar.gz: 522140b9b71f5ef24480f40210c0155f44d2f82e271e14dd1625ac6d6854407a13fb30e343b6398bf968448a899d6d8ccda83714e483f53c33e89aa164764877
data/.rubocop_todo.yml CHANGED
@@ -1,27 +1,33 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-08-19 10:13:44 +0200 using RuboCop version 0.74.0.
3
+ # on 2019-08-19 16:08:47 +0200 using RuboCop version 0.74.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 2
9
+ # Offense count: 1
10
+ Lint/ShadowingOuterLocalVariable:
11
+ Exclude:
12
+ - 'lib/gl/cli/registry.rb'
13
+
14
+ # Offense count: 4
10
15
  Metrics/AbcSize:
11
- Max: 45
16
+ Max: 48
12
17
 
13
- # Offense count: 3
18
+ # Offense count: 5
14
19
  # Configuration parameters: CountComments, ExcludedMethods.
15
20
  Metrics/MethodLength:
16
21
  Max: 35
17
22
 
18
- # Offense count: 5
23
+ # Offense count: 6
19
24
  Style/Documentation:
20
25
  Exclude:
21
26
  - 'spec/**/*'
22
27
  - 'test/**/*'
23
28
  - 'lib/gl.rb'
24
29
  - 'lib/gl/cli.rb'
30
+ - 'lib/gl/cli/global.rb'
25
31
  - 'lib/gl/cli/issues.rb'
26
32
  - 'lib/gl/cli/merge_requests.rb'
27
33
  - 'lib/gl/cli/registry.rb'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gl (0.2.0)
4
+ gl (0.2.1)
5
5
  gitlab (~> 4.12)
6
6
  thor (~> 0.20.3)
7
7
  tty-progressbar (~> 0.17.0)
data/README.md CHANGED
@@ -15,6 +15,7 @@ Inside your git workspace you can issue the following commands:
15
15
  $ gl
16
16
 
17
17
  Commands:
18
+ gl global # commands unrelated to the current project
18
19
  gl help [COMMAND] # Describe available commands or one specific command
19
20
  gl issues # handle issues of the project
20
21
  gl mr # handle merge requests of the project
@@ -70,6 +71,18 @@ $ gl issue open 409
70
71
  $ gl mr open 213
71
72
  ```
72
73
 
74
+ With the registry subcommand you can get a overview about the registry usage.
75
+
76
+ ```bash
77
+ $ gl registry status
78
+
79
+ +---------------------------+------+-------------+
80
+ | Registry | Tags | Size |
81
+ +---------------------------+------+-------------+
82
+ | XXXXXXXXXXXXXXXXXXXXXXXXX | 42 | 13511.85 MB |
83
+ +---------------------------+------+-------------+
84
+ ```
85
+
73
86
  ## Development
74
87
 
75
88
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/gl/cli.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'gl/cli/registry'
4
4
  require 'gl/cli/merge_requests'
5
5
  require 'gl/cli/issues'
6
+ require 'gl/cli/global'
6
7
 
7
8
  module Gl
8
9
  class CLI < Thor
@@ -15,14 +16,16 @@ module Gl
15
16
  desc 'issues', 'handle issues of the project'
16
17
  subcommand 'issues', Issues
17
18
 
19
+ desc 'global', 'commands unrelated to the current project'
20
+ subcommand 'global', Global
21
+
18
22
  def self.setup
19
23
  Gitlab.endpoint = "https://#{Gl.remote_base}/api/v4/"
20
24
  Gl.validate_endpoint!
21
25
 
22
- prompt = TTY::Prompt.new
23
-
24
26
  token = `git config --get gl.#{Gl.remote_slug}.token`.chomp
25
27
  if token.empty?
28
+ prompt = TTY::Prompt.new
26
29
  Gl.open_in_browser('profile/personal_access_tokens')
27
30
  token = prompt.mask("Please enter your GitLab token for #{Gl.remote_base}")
28
31
 
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gl
4
+ class Global < Thor
5
+ desc 'registry', 'display statistics about the registry'
6
+ def registry
7
+ spinner = TTY::Spinner.new('[:spinner] Fetching projects ...')
8
+
9
+ results = {}
10
+
11
+ spinner.auto_spin
12
+ projects = Gitlab.projects.auto_paginate
13
+ spinner.stop("Found #{projects.count}")
14
+
15
+ bar = TTY::ProgressBar.new(
16
+ 'processing projects [:bar] :current/:total processed (:percent, :eta remaining)',
17
+ total: projects.size
18
+ )
19
+
20
+ projects.each do |project|
21
+ bar.advance(1)
22
+ registries = begin
23
+ Gitlab.registry_repositories(project.id).auto_paginate
24
+ rescue Gitlab::Error::Forbidden
25
+ next
26
+ end
27
+
28
+ next if registries.empty?
29
+
30
+ infos = registries.map do |registry|
31
+ tags = Gitlab.registry_repository_tags(project.id, registry.id).auto_paginate
32
+
33
+ next if tags.empty?
34
+
35
+ tags = tags.map do |tag|
36
+ Gitlab.registry_repository_tag(project.id, registry.id, tag.name)
37
+ rescue Gitlab::Error::NotFound
38
+ next
39
+ end
40
+
41
+ tags
42
+ end
43
+
44
+ sizes = infos.flatten.compact.map(&:total_size)
45
+
46
+ project_size = sizes.compact.inject(0) { |sum, x| sum + x }
47
+ results[project.path_with_namespace] = (project_size / 1024.0 / 1024.0).round(2)
48
+ end
49
+
50
+ bar.finish
51
+ table = TTY::Table.new(['Project', 'Size in MB'], results.sort_by { |_key, value| -value })
52
+ table << ['Total usage', results.values.inject(0) { |sum, x| sum + x }.round(2)]
53
+ puts table.render(:ascii, alignments: %i[left right])
54
+ end
55
+ end
56
+ end
@@ -4,53 +4,27 @@ module Gl
4
4
  class Registry < Thor
5
5
  desc 'status', 'display statistics about the registry'
6
6
  def status
7
- spinner = TTY::Spinner.new('[:spinner] Fetching projects ...')
7
+ project = Gl.current_project
8
8
 
9
- results = {}
9
+ registries = Gitlab.registry_repositories(project).auto_paginate
10
10
 
11
- spinner.auto_spin
12
- projects = Gitlab.projects.auto_paginate
13
- spinner.stop("Found #{projects.count}")
14
-
15
- bar = TTY::ProgressBar.new(
16
- 'processing projects [:bar] :current/:total processed (:percent, :eta remaining)',
17
- total: projects.size
18
- )
19
-
20
- projects.each do |project|
21
- bar.advance(1)
22
- registries = begin
23
- Gitlab.registry_repositories(project.id)
24
- rescue Gitlab::Error::Forbidden
25
- next
26
- end
27
-
28
- next if registries.empty?
29
-
30
- infos = registries.map do |registry|
31
- tags = Gitlab.registry_repository_tags(project.id, registry.id)
11
+ table = TTY::Table.new(header: %w[Registry Tags Size]) do |table|
12
+ registries.each do |registry|
13
+ tags = Gitlab.registry_repository_tags(project, registry.id).auto_paginate
32
14
 
33
15
  next if tags.empty?
34
16
 
35
17
  tags = tags.map do |tag|
36
- Gitlab.registry_repository_tag(project.id, registry.id, tag.name)
18
+ Gitlab.registry_repository_tag(project, registry.id, tag.name)
37
19
  rescue Gitlab::Error::NotFound
38
20
  next
39
21
  end
40
22
 
41
- tags
23
+ tags_size = tags.flatten.compact.map(&:total_size).inject(0) { |sum, x| sum + x }
24
+ table << [registry.path, tags.count, "#{(tags_size / 1024.0 / 1024.0).round(2)} MB"]
42
25
  end
43
-
44
- sizes = infos.flatten.compact.map(&:total_size)
45
-
46
- project_size = sizes.inject(0) { |sum, x| sum + x }
47
- results[project.path_with_namespace] = (project_size / 1024.0 / 1024.0).round(2)
48
26
  end
49
-
50
- bar.finish
51
- table = TTY::Table.new(['Project', 'Size in MB'], results.sort_by { |_key, value| -value })
52
- table << ['Total usage', results.values.inject(0) { |sum, x| sum + x }.round(2)]
53
- puts table.render(:ascii, alignments: %i[left right])
27
+ puts table.render(:ascii, alignments: %i[left right], padding: [0, 1])
54
28
  end
55
29
  end
56
30
  end
data/lib/gl/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gl
4
- VERSION = '0.2.1'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flipez
@@ -144,6 +144,7 @@ files:
144
144
  - gl.gemspec
145
145
  - lib/gl.rb
146
146
  - lib/gl/cli.rb
147
+ - lib/gl/cli/global.rb
147
148
  - lib/gl/cli/issues.rb
148
149
  - lib/gl/cli/merge_requests.rb
149
150
  - lib/gl/cli/registry.rb