avm-eac_gitlab_base0 0.4.0 → 0.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29b6c85b5e8ea4d7c532ac468f22a46222401be32673a9fb57b45c803d097570
4
- data.tar.gz: 393ced74e59d5241951b3509e41d6f0f33dd875b716d0ffea219057b1169c9c3
3
+ metadata.gz: 4783d4719352b2f35cc69d6a1304aab9b24db5f022815afb06de9ba571f07ebd
4
+ data.tar.gz: e0168b060fc67124f9beb7086273a96eac1c0689fa0c9d2848251aa3a8de8d57
5
5
  SHA512:
6
- metadata.gz: c06ad4500da0cd58319c60aebb0fc3702959a151ca6a4866dc941f5d2390c7fb992ef0fdc96d706c315a3e3666faf39a4e8b8ba569b25150405e5fd2844d7ef2
7
- data.tar.gz: 96bd516c191edda77afb8fb342d68d69aaf98d59810cf91cb964c8859a86bf50e68d854cebaa50e88166019b8c3d5ace968170d69860f4a76175a5d46a7ed4db
6
+ metadata.gz: f0a009032b6304a57ea5305f2be019f062ea2345a9a118f02f1a356117fa5e8126201186ff81ed36ea7e8ad35c0508606f8827fda317765fa6d203514ca5477f
7
+ data.tar.gz: 06ded0754642f134e5ed8a19516339aa905ced1e1c85899ad7977c2792e7f5f99c57089e15ab6a9861d7a773c917e3fecc26ba2a571aac93353ecb3be856aeef
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module EacGitlabBase0
7
+ class Api < ::EacRest::Api
8
+ class BaseEntity < ::EacRest::Entity
9
+ class ValidateResponseData
10
+ acts_as_instance_method
11
+ common_constructor :owner, :response
12
+
13
+ # @return Object
14
+ def result
15
+ raise ::Avm::EacGitlabBase0::Api::ForbiddenError.new(response.body_str, response) if
16
+ response.status == 403
17
+
18
+ with_root_attribute(:error) do |v|
19
+ raise "URL: #{response.url}, Error: #{v}"
20
+ end
21
+ with_root_attribute(:message) do |_v|
22
+ return nil if response.status == 404
23
+ end
24
+
25
+ response.body_data
26
+ end
27
+
28
+ protected
29
+
30
+ # @param attribute [String, Symbol]
31
+ # @return [String, nil]
32
+ def with_root_attribute(attribute)
33
+ attribute = attribute.to_s
34
+ response.body_data.then do |v|
35
+ break nil unless v.is_a?(::Hash) && v.key?(attribute)
36
+
37
+ yield(v.fetch(attribute))
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -20,19 +20,27 @@ module Avm
20
20
  ::CGI.escape(id.to_s)
21
21
  end
22
22
 
23
- def fetch_entity(suffix, klass, not_found_message = nil)
23
+ # @param suffix [String]
24
+ # @param klass [Class<Avm::EacGitlabBase0::Api::BaseEntity>]
25
+ # @return [Avm::EacGitlabBase0::Api::BaseEntity]
26
+ def fetch_entity(suffix, klass)
24
27
  validate_response_data(
25
- dump_response(api.request_json(suffix).response),
26
- not_found_message
27
- ).if_present { |v| klass.new(api, v) }
28
+ dump_response(api.request_json(suffix).response)
29
+ ).if_present { |v| child_entity(klass, v) }
28
30
  end
29
31
 
30
- def fetch_entities(suffix, klass)
32
+ # @param suffix [String]
33
+ # @param klass [Class<Avm::EacGitlabBase0::Api::BaseEntity>]
34
+ # @return [Array<Avm::EacGitlabBase0::Api::BaseEntity>]
35
+ def fetch_entities(suffix, klass) # rubocop:disable Metrics/MethodLength
31
36
  r = []
32
37
  request = api.request_json(suffix)
33
38
  while request
34
39
  response = request.response
35
- r += validate_response_data(response).map { |rr| klass.new(api, rr) }
40
+ body_data = validate_response_data(response)
41
+ break unless body_data
42
+
43
+ r += body_data.map { |rr| child_entity(klass, rr) }
36
44
  request = response.link('next').if_present do |v|
37
45
  api.request_json(v)
38
46
  end
@@ -53,19 +61,7 @@ module Avm
53
61
  ::EacRubyUtils::Yaml.dump_file(file, data)
54
62
  end
55
63
 
56
- def validate_response_data(response, not_found_message = nil)
57
- if response.body_data.is_a?(::Hash)
58
- response.body_data['error'].if_present do |v|
59
- raise "URL: #{response.url}, Data: #{v}"
60
- end
61
-
62
- response.body_data['message'].if_present do |v|
63
- return nil if v == not_found_message
64
- end
65
- end
66
-
67
- response.body_data
68
- end
64
+ require_sub __FILE__, require_mode: :kernel
69
65
  end
70
66
  end
71
67
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_gitlab_base0/api/base_entity'
4
+ require 'eac_rest/api'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module Avm
8
+ module EacGitlabBase0
9
+ class Api < ::EacRest::Api
10
+ class ForbiddenError < ::RuntimeError
11
+ def initialize(message, response)
12
+ super(message)
13
+ @response = response
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -21,7 +21,7 @@ module Avm
21
21
  end
22
22
 
23
23
  def api_prefix
24
- "/groups/#{encode_id(id)}"
24
+ "/v4/groups/#{encode_id(id)}"
25
25
  end
26
26
 
27
27
  def to_s
@@ -43,6 +43,14 @@ module Avm
43
43
  ::Avm::EacGitlabBase0::Api::Project
44
44
  )
45
45
  end
46
+
47
+ # @return [Array<Avm::EacGitlabBase0::Api::Group>]
48
+ def subgroups_uncached
49
+ fetch_entities(
50
+ "#{api_prefix}/subgroups?order_by=path&sort=asc&per_page=9999",
51
+ ::Avm::EacGitlabBase0::Api::Group
52
+ )
53
+ end
46
54
  end
47
55
  end
48
56
  end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_gitlab_base0/api/base_entity'
4
+ require 'avm/eac_gitlab_base0/api/project'
5
+ require 'eac_rest/api'
6
+ require 'eac_ruby_utils/core_ext'
7
+
8
+ module Avm
9
+ module EacGitlabBase0
10
+ class Api < ::EacRest::Api
11
+ class NodesSet
12
+ class AddByGroupProjectsId
13
+ acts_as_instance_method
14
+ enable_simple_cache
15
+
16
+ common_constructor :owner, :group_id
17
+
18
+ # @return [Array<Avm::EacGitlabBase0::Api::Project>]
19
+ def result
20
+ subgroups + projects
21
+ end
22
+
23
+ protected
24
+
25
+ # @return [Avm::EacGitlabBase0::Api::Group]
26
+ def group_uncached
27
+ owner.rest_api.root.group(group_id) || raise("No group found with ID = \"#{group_id}\"")
28
+ end
29
+
30
+ # @return [Array<Avm::EacGitlabBase0::Api::Project>]
31
+ def projects
32
+ group.projects.map { |project| owner.send(:add_node, project) }
33
+ end
34
+
35
+ # @return [Array<Avm::EacGitlabBase0::Api::Group>]
36
+ def subgroups
37
+ group.subgroups.map { |subgroup| owner.add_by_group_projects_id(subgroup.id) }
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -42,8 +42,13 @@ module Avm
42
42
  send("add_by_#{type}_id", parsed_id)
43
43
  end
44
44
 
45
+ # @return [Avm::EacGitlabBase0::Api::Root]
46
+ def add_all_projects
47
+ rest_api.root.projects.each { |project| add_node(project) }
48
+ end
49
+
45
50
  # @return [Array<Avm::EacGitlabBase0::Api::Group>]
46
- def group
51
+ def groups
47
52
  nodes.select { |node| node.is_a?(::Avm::EacGitlabBase0::Api::Group) }
48
53
  end
49
54
 
@@ -88,17 +93,6 @@ module Avm
88
93
  [add_node(group)]
89
94
  end
90
95
 
91
- # @return [Array<Avm::EacGitlabBase0::Api::Project>]
92
- def add_by_group_projects_id(id)
93
- group = rest_api.root.group(id)
94
-
95
- raise "No group found with ID = \"#{id}\"" unless group
96
-
97
- group.projects.map do |project|
98
- add_node(project)
99
- end
100
- end
101
-
102
96
  # @return [Array<Avm::EacGitlabBase0::Api::Node>]
103
97
  def add_by_group_and_projects_id(id)
104
98
  add_by_group_id(id) + add_by_group_projects_id(id)
@@ -112,6 +106,8 @@ module Avm
112
106
 
113
107
  [add_node(project)]
114
108
  end
109
+
110
+ require_sub __FILE__, require_mode: :kernel
115
111
  end
116
112
  end
117
113
  end
@@ -3,6 +3,7 @@
3
3
  require 'avm/eac_gitlab_base0/api/file'
4
4
  require 'avm/eac_gitlab_base0/api/member'
5
5
  require 'avm/eac_gitlab_base0/api/node'
6
+ require 'avm/eac_gitlab_base0/api/tree'
6
7
  require 'eac_rest/api'
7
8
  require 'eac_ruby_utils/core_ext'
8
9
 
@@ -32,7 +33,7 @@ module Avm
32
33
  end
33
34
 
34
35
  def api_prefix
35
- "/projects/#{encode_id(id)}"
36
+ "/v4/projects/#{encode_id(id)}"
36
37
  end
37
38
 
38
39
  def full_path
@@ -42,8 +43,15 @@ module Avm
42
43
  def file(path)
43
44
  fetch_entity(
44
45
  "#{api_prefix}/repository/files/#{encode_id(path)}?ref=#{default_branch}",
45
- ::Avm::EacGitlabBase0::Api::File,
46
- '404 File Not Found'
46
+ ::Avm::EacGitlabBase0::Api::File
47
+ )
48
+ end
49
+
50
+ # @return [Array<Avm::EacGitlabBase0::Api::Tree>]
51
+ def tree
52
+ fetch_entities(
53
+ "#{api_prefix}/repository/tree",
54
+ ::Avm::EacGitlabBase0::Api::Tree
47
55
  )
48
56
  end
49
57
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'avm/eac_gitlab_base0/api/base_entity'
4
+ require 'avm/eac_gitlab_base0/api/group'
4
5
  require 'avm/eac_gitlab_base0/api/project'
5
6
  require 'eac_rest/api'
6
7
  require 'eac_ruby_utils/core_ext'
@@ -11,17 +12,31 @@ module Avm
11
12
  class Root < ::Avm::EacGitlabBase0::Api::BaseEntity
12
13
  def group(id)
13
14
  fetch_entity(
14
- "/groups/#{encode_id(id)}?with_projects=false",
15
- ::Avm::EacGitlabBase0::Api::Group,
16
- '404 Group Not Found'
15
+ "/v4/groups/#{encode_id(id)}?with_projects=false",
16
+ ::Avm::EacGitlabBase0::Api::Group
17
+ )
18
+ end
19
+
20
+ # @return [Array<Avm::EacGitlabBase0::Api::Group>]
21
+ def groups
22
+ fetch_entities(
23
+ '/v4/groups?with_projects=false',
24
+ ::Avm::EacGitlabBase0::Api::Group
17
25
  )
18
26
  end
19
27
 
20
28
  def project(id)
21
29
  fetch_entity(
22
- "/projects/#{encode_id(id)}",
23
- ::Avm::EacGitlabBase0::Api::Project,
24
- '404 Project Not Found'
30
+ "/v4/projects/#{encode_id(id)}",
31
+ ::Avm::EacGitlabBase0::Api::Project
32
+ )
33
+ end
34
+
35
+ # @return [Array<Avm::EacGitlabBase0::Api::Projects>]
36
+ def projects
37
+ fetch_entities(
38
+ '/v4/projects',
39
+ ::Avm::EacGitlabBase0::Api::Project
25
40
  )
26
41
  end
27
42
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_gitlab_base0/api/base_entity'
4
+ require 'avm/eac_gitlab_base0/api/file'
5
+ require 'eac_rest/api'
6
+ require 'eac_ruby_utils/core_ext'
7
+
8
+ module Avm
9
+ module EacGitlabBase0
10
+ class Api < ::EacRest::Api
11
+ class Tree < ::Avm::EacGitlabBase0::Api::BaseEntity
12
+ enable_listable
13
+
14
+ lists.add_string :type, :blob, :tree
15
+
16
+ FIELDS = %w[mode name path type].freeze
17
+
18
+ FIELDS.each do |field|
19
+ define_method field do
20
+ data.fetch(field)
21
+ end
22
+ end
23
+
24
+ # @return [Boolean]
25
+ def directory?
26
+ type == TYPE_TREE
27
+ end
28
+
29
+ # @return [Avm::EacGitlabBase0::Api::File]
30
+ def file
31
+ parent_entity.file(path)
32
+ end
33
+
34
+ # @return [Boolean]
35
+ def file?
36
+ type == TYPE_BLOB
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -15,7 +15,7 @@ module Avm
15
15
  end
16
16
 
17
17
  def build_service_url_suffix(suffix)
18
- r = super(suffix)
18
+ r = super
19
19
  r.path = API_SUFFIX + r.path
20
20
  r
21
21
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'avm/instances/base'
4
4
  require 'avm/eac_gitlab_base0/api'
5
+ require 'avm/eac_gitlab_base0/instances/runners'
5
6
  require 'eac_ruby_utils/core_ext'
6
7
 
7
8
  module Avm
@@ -10,7 +11,7 @@ module Avm
10
11
  class Base < ::Avm::Instances::Base
11
12
  # @return [Avm::EacGitlabBase0::Api]
12
13
  def rest_api
13
- @rest_api ||= ::Avm::EacGitlabBase0::Api.new(web_url)
14
+ @rest_api ||= ::Avm::EacGitlabBase0::Api.new("#{web_url}/api")
14
15
  end
15
16
  end
16
17
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/core_ext'
4
+
5
+ module Avm
6
+ module EacGitlabBase0
7
+ module Instances
8
+ module Runners
9
+ class Nodes
10
+ class List
11
+ runner_with :help
12
+
13
+ def run
14
+ infov 'Nodes', runner_context.call(:nodes).count
15
+ runner_context.call(:nodes).each do |p|
16
+ infov ' * ', p
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/core_ext'
4
+
5
+ module Avm
6
+ module EacGitlabBase0
7
+ module Instances
8
+ module Runners
9
+ class Nodes
10
+ class Members
11
+ runner_with :help, :confirmation do
12
+ arg_opt '-s', '--select', 'Seleciona usuário por "username".', repeat: true
13
+ bool_opt '-c', '--clear', 'Remove todos os usuários não selecionados.'
14
+ end
15
+
16
+ def run
17
+ infov 'Nodes', runner_context.call(:nodes).count
18
+ runner_context.call(:nodes).each do |p|
19
+ show_project(p)
20
+ end
21
+ perform_clear
22
+ end
23
+
24
+ def show_project(project)
25
+ infov project, project.members.count
26
+ project.members.each do |member|
27
+ infov ' * ', member_label(member)
28
+ end
29
+ end
30
+
31
+ def member_label(member)
32
+ r = member.to_s
33
+ member_label_color(member).if_present { |v| r = r.send(v) }
34
+ r
35
+ end
36
+
37
+ def member_label_color(member)
38
+ return :red if member_remove?(member)
39
+ return :green if member_selected?(member)
40
+
41
+ nil
42
+ end
43
+
44
+ def member_remove?(member)
45
+ parsed.clear? && !member_selected?(member)
46
+ end
47
+
48
+ def member_selected?(member)
49
+ parsed.select.include?(member.username)
50
+ end
51
+
52
+ def perform_clear
53
+ return unless parsed.clear?
54
+ return unless confirm?('Confirma remoção de membros?')
55
+
56
+ runner_context.call(:nodes).each do |node|
57
+ node.members.each { |member| remove_member(node, member) }
58
+ end
59
+ end
60
+
61
+ def remove_member(node, member)
62
+ return unless member_remove?(member)
63
+
64
+ infom "Removing \"#{member}\" from \"#{node}\"..."
65
+ node.remove_member(member.id)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/core_ext'
4
+
5
+ module Avm
6
+ module EacGitlabBase0
7
+ module Instances
8
+ module Runners
9
+ class Nodes
10
+ require_sub __FILE__
11
+
12
+ runner_with :help, :subcommands do
13
+ arg_opt '-p', '--node', repeat: true
14
+ bool_opt '-G', '--no-groups', 'Não mostra grupos'
15
+ subcommands
16
+ end
17
+
18
+ delegate :nodes, to: :nodes_set
19
+
20
+ def input_nodes_ids
21
+ parsed.node
22
+ end
23
+
24
+ private
25
+
26
+ def nodes_set_uncached
27
+ r = runner_context.call(:instance).rest_api.nodes_set(*input_nodes_ids)
28
+ r.no_groups = parsed.no_groups
29
+ r
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module EacGitlabBase0
7
+ module Instances
8
+ module Runners
9
+ require_sub __FILE__
10
+ end
11
+ end
12
+ end
13
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module EacGitlabBase0
5
- VERSION = '0.4.0'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm-eac_gitlab_base0
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Put here the authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-04 00:00:00.000000000 Z
11
+ date: 2025-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avm-eac_github_base0
@@ -30,34 +30,34 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.119'
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 0.119.2
33
+ version: '0.124'
37
34
  type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
38
  - - "~>"
42
39
  - !ruby/object:Gem::Version
43
- version: '0.119'
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 0.119.2
40
+ version: '0.124'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: eac_ruby_gem_support
49
43
  requirement: !ruby/object:Gem::Requirement
50
44
  requirements:
51
45
  - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: '0.9'
47
+ version: '0.10'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 0.10.1
54
51
  type: :development
55
52
  prerelease: false
56
53
  version_requirements: !ruby/object:Gem::Requirement
57
54
  requirements:
58
55
  - - "~>"
59
56
  - !ruby/object:Gem::Version
60
- version: '0.9'
57
+ version: '0.10'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.10.1
61
61
  description:
62
62
  email:
63
63
  executables: []
@@ -67,16 +67,24 @@ files:
67
67
  - lib/avm/eac_gitlab_base0.rb
68
68
  - lib/avm/eac_gitlab_base0/api.rb
69
69
  - lib/avm/eac_gitlab_base0/api/base_entity.rb
70
+ - lib/avm/eac_gitlab_base0/api/base_entity/validate_response_data.rb
70
71
  - lib/avm/eac_gitlab_base0/api/file.rb
72
+ - lib/avm/eac_gitlab_base0/api/forbidden_error.rb
71
73
  - lib/avm/eac_gitlab_base0/api/group.rb
72
74
  - lib/avm/eac_gitlab_base0/api/member.rb
73
75
  - lib/avm/eac_gitlab_base0/api/node.rb
74
76
  - lib/avm/eac_gitlab_base0/api/nodes_set.rb
77
+ - lib/avm/eac_gitlab_base0/api/nodes_set/add_by_group_projects_id.rb
75
78
  - lib/avm/eac_gitlab_base0/api/project.rb
76
79
  - lib/avm/eac_gitlab_base0/api/root.rb
80
+ - lib/avm/eac_gitlab_base0/api/tree.rb
77
81
  - lib/avm/eac_gitlab_base0/application_scms.rb
78
82
  - lib/avm/eac_gitlab_base0/application_scms/base.rb
79
83
  - lib/avm/eac_gitlab_base0/instances/base.rb
84
+ - lib/avm/eac_gitlab_base0/instances/runners.rb
85
+ - lib/avm/eac_gitlab_base0/instances/runners/nodes.rb
86
+ - lib/avm/eac_gitlab_base0/instances/runners/nodes/list.rb
87
+ - lib/avm/eac_gitlab_base0/instances/runners/nodes/members.rb
80
88
  - lib/avm/eac_gitlab_base0/version.rb
81
89
  homepage:
82
90
  licenses: []