avm-eac_gitlab_base0 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e8b66b0877e4db982bc8d9483284f667a2760055b637a013943826c2eca74eb0
4
+ data.tar.gz: 0c5472dc87b20a6959668e4101855ed9744b2d1d7a0f941e162f2debdd1affef
5
+ SHA512:
6
+ metadata.gz: e8cffdf45629aa04094cc4d7f43ae68e755631f9aa37e9e485f04c4ff0a26386c11259ce7bfdc710e9e5354696f7a30e8664565a217e11d8add12769993f632d
7
+ data.tar.gz: dd82f4f598618a17f2b490fe5a5e33767db1ee1be2e2098224c54953567478706fb70b2a8e9ec0638b15dfbc3fbdc8ea2492b260f0d3bee8e48ab6d7b7fb01cc
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_rest/api'
4
+ require 'eac_rest/entity'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module Avm
8
+ module EacGitlabBase0
9
+ class Api < ::EacRest::Api
10
+ class BaseEntity < ::EacRest::Entity
11
+ enable_simple_cache
12
+
13
+ def delete(url_suffix)
14
+ api.request(url_suffix).verb(:delete).response.body_data
15
+ end
16
+
17
+ def encode_id(id)
18
+ return id if id.is_a?(::Integer)
19
+
20
+ ::CGI.escape(id.to_s)
21
+ end
22
+
23
+ def fetch_entity(suffix, klass, not_found_message = nil)
24
+ validate_response_data(
25
+ dump_response(api.request_json(suffix).response),
26
+ not_found_message
27
+ ).if_present { |v| klass.new(api, v) }
28
+ end
29
+
30
+ def fetch_entities(suffix, klass)
31
+ r = []
32
+ request = api.request_json(suffix)
33
+ while request
34
+ response = request.response
35
+ r += validate_response_data(response).map { |rr| klass.new(api, rr) }
36
+ request = response.link('next').if_present do |v|
37
+ api.request_json(v)
38
+ end
39
+ end
40
+ r
41
+ end
42
+
43
+ def dump_response(response)
44
+ basename = response.url.to_s.variableize[0..99]
45
+ { data: response.body_data, headers: response.headers, links: response.links }
46
+ .each { |part, value| dump_debug("#{basename}_#{part}", value) }
47
+ response
48
+ end
49
+
50
+ def dump_debug(basename, data)
51
+ file = ::Pathname.new('/tmp').join('gitlab_temp', basename + '.yaml')
52
+ file.parent.mkpath
53
+ ::EacRubyUtils::Yaml.dump_file(file, data)
54
+ end
55
+
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
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,33 @@
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 File < ::Avm::EacGitlabBase0::Api::BaseEntity
11
+ FIELDS = %w[file_name file_path size encoding content_sha256 ref blob_id commit_id
12
+ last_commit_id].freeze
13
+
14
+ FIELDS.each do |field|
15
+ define_method field do
16
+ data.fetch(field)
17
+ end
18
+ end
19
+
20
+ def content
21
+ case encoding
22
+ when 'base64' then ::Base64.decode64(encoded_content)
23
+ else nyi("Unmapped encoding: #{encoding}")
24
+ end
25
+ end
26
+
27
+ def encoded_content
28
+ data.fetch('content')
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_gitlab_base0/api/node'
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 Group < ::Avm::EacGitlabBase0::Api::Node
12
+ FIELDS = %w[id web_url name path description visibility share_with_group_lock
13
+ require_two_factor_authentication two_factor_grace_period project_creation_level
14
+ auto_devops_enabled subgroup_creation_level emails_disabled lfs_enabled
15
+ avatar_url request_access_enabled full_name full_path parent_id].freeze
16
+
17
+ FIELDS.each do |field|
18
+ define_method field do
19
+ data.fetch(field)
20
+ end
21
+ end
22
+
23
+ def api_prefix
24
+ "/groups/#{encode_id(id)}"
25
+ end
26
+
27
+ def to_s
28
+ full_path
29
+ end
30
+
31
+ private
32
+
33
+ def members_uncached
34
+ fetch_entities(
35
+ "#{api_prefix}/members",
36
+ ::Avm::EacGitlabBase0::Api::Member
37
+ )
38
+ end
39
+
40
+ def projects_uncached
41
+ fetch_entities(
42
+ "#{api_prefix}/projects?order_by=path&sort=asc&per_page=9999",
43
+ ::Avm::EacGitlabBase0::Api::Project
44
+ )
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,25 @@
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 Member < ::Avm::EacGitlabBase0::Api::BaseEntity
11
+ FIELDS = %w[id name username state avatar_url web_url access_level expires_at].freeze
12
+
13
+ FIELDS.each do |field|
14
+ define_method field do
15
+ data.fetch(field)
16
+ end
17
+ end
18
+
19
+ def to_s
20
+ [name, username, state, access_level].join(' / ')
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
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 Node < ::Avm::EacGitlabBase0::Api::BaseEntity
12
+ compare_by :id
13
+
14
+ def remove_member(user_id)
15
+ delete("#{api_prefix}/members/#{encode_id(user_id)}")
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,118 @@
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
+ IDS_PREFIXES = {
13
+ '@@' => :group_and_projects, '@-' => :group_projects, '@' => :group
14
+ }.freeze
15
+
16
+ GROUP_AND_PROJECTS_ID_PARSER = /\A@@(.*)\z/.to_parser { |m| m[1] }
17
+ GROUP_ID_PARSER = /\A@(.*)\z/.to_parser { |m| m[1] }
18
+
19
+ class << self
20
+ def parse_id(id)
21
+ IDS_PREFIXES.each do |prefix, type|
22
+ /\A#{::Regexp.quote(prefix)}(.*)\z/.if_match(id, false) do |m|
23
+ return [m[1], type]
24
+ end
25
+ end
26
+
27
+ [id, :project]
28
+ end
29
+ end
30
+
31
+ attr_reader :rest_api
32
+ attr_writer :no_groups
33
+
34
+ def initialize(rest_api, *ids)
35
+ self.rest_api = rest_api
36
+ ids.each { |id| add(id) }
37
+ end
38
+
39
+ def add(id)
40
+ parsed_id, type = self.class.parse_id(id)
41
+
42
+ send("add_by_#{type}_id", parsed_id)
43
+ end
44
+
45
+ # @return [Array<Avm::EacGitlabBase0::Api::Group>]
46
+ def group
47
+ nodes.select { |node| node.is_a?(::Avm::EacGitlabBase0::Api::Group) }
48
+ end
49
+
50
+ # @return [Array<Avm::EacGitlabBase0::Api::Project>]
51
+ def projects
52
+ nodes.select { |node| node.is_a?(::Avm::EacGitlabBase0::Api::Project) }
53
+ end
54
+
55
+ # @return [Array<Avm::EacGitlabBase0::Api::Node>]
56
+ def nodes
57
+ r = nodes_set
58
+ r = r.reject { |g| g.is_a?(::Avm::EacGitlabBase0::Api::Group) } if no_groups?
59
+ r.sort_by { |p| [p.full_path] }
60
+ end
61
+
62
+ def no_groups?
63
+ @no_groups ? true : false
64
+ end
65
+
66
+ private
67
+
68
+ attr_writer :rest_api
69
+
70
+ # @return [Set<Avm::EacGitlabBase0::Api::Project>]
71
+ def nodes_set
72
+ @nodes_set ||= ::Set.new
73
+ end
74
+
75
+ # @return [Avm::EacGitlabBase0::Api::Node]
76
+ def add_node(node)
77
+ nodes_set.add(node)
78
+
79
+ node
80
+ end
81
+
82
+ # @return [Array<Avm::EacGitlabBase0::Api::Group>]
83
+ def add_by_group_id(id)
84
+ group = rest_api.root.group(id)
85
+
86
+ raise "No group found with ID = \"#{id}\"" unless group
87
+
88
+ [add_node(group)]
89
+ end
90
+
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
+ # @return [Array<Avm::EacGitlabBase0::Api::Node>]
103
+ def add_by_group_and_projects_id(id)
104
+ add_by_group_id(id) + add_by_group_projects_id(id)
105
+ end
106
+
107
+ # @return [Array<Avm::EacGitlabBase0::Api::Project>]
108
+ def add_by_project_id(id)
109
+ project = rest_api.root.project(id)
110
+
111
+ raise "No project found with ID = \"#{id}\"" unless project
112
+
113
+ [add_node(project)]
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_gitlab_base0/api/file'
4
+ require 'avm/eac_gitlab_base0/api/member'
5
+ require 'avm/eac_gitlab_base0/api/node'
6
+ require 'eac_rest/api'
7
+ require 'eac_ruby_utils/core_ext'
8
+
9
+ module Avm
10
+ module EacGitlabBase0
11
+ class Api < ::EacRest::Api
12
+ class Project < ::Avm::EacGitlabBase0::Api::Node
13
+ FIELDS = %w[id description name name_with_namespace path path_with_namespace created_at
14
+ default_branch tag_list ssh_url_to_repo http_url_to_repo web_url readme_url
15
+ avatar_url star_count forks_count last_activity_at empty_repo archived
16
+ visibility resolve_outdated_diff_discussions container_registry_enabled
17
+ issues_enabled merge_requests_enabled wiki_enabled jobs_enabled snippets_enabled
18
+ issues_access_level repository_access_level merge_requests_access_level
19
+ wiki_access_level builds_access_level snippets_access_level
20
+ shared_runners_enabled lfs_enabled creator_id import_status
21
+ ci_default_git_depth public_jobs build_timeout auto_cancel_pending_pipelines
22
+ build_coverage_regex ci_config_path shared_with_groups
23
+ only_allow_merge_if_pipeline_succeeds request_access_enabled
24
+ only_allow_merge_if_all_discussions_are_resolved
25
+ remove_source_branch_after_merge printing_merge_request_link_enabled
26
+ merge_method auto_devops_enabled auto_devops_deploy_strategy].freeze
27
+
28
+ FIELDS.each do |field|
29
+ define_method field do
30
+ data.fetch(field)
31
+ end
32
+ end
33
+
34
+ def api_prefix
35
+ "/projects/#{encode_id(id)}"
36
+ end
37
+
38
+ def full_path
39
+ path_with_namespace
40
+ end
41
+
42
+ def file(path)
43
+ fetch_entity(
44
+ "#{api_prefix}/repository/files/#{encode_id(path)}?ref=#{default_branch}",
45
+ ::Avm::EacGitlabBase0::Api::File,
46
+ '404 File Not Found'
47
+ )
48
+ end
49
+
50
+ def to_s
51
+ path_with_namespace
52
+ end
53
+
54
+ private
55
+
56
+ def members_uncached
57
+ fetch_entities(
58
+ "#{api_prefix}/members",
59
+ ::Avm::EacGitlabBase0::Api::Member
60
+ )
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,30 @@
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 Root < ::Avm::EacGitlabBase0::Api::BaseEntity
12
+ def group(id)
13
+ fetch_entity(
14
+ "/groups/#{encode_id(id)}?with_projects=false",
15
+ ::Avm::EacGitlabBase0::Api::Group,
16
+ '404 Group Not Found'
17
+ )
18
+ end
19
+
20
+ def project(id)
21
+ fetch_entity(
22
+ "/projects/#{encode_id(id)}",
23
+ ::Avm::EacGitlabBase0::Api::Project,
24
+ '404 Project Not Found'
25
+ )
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_rest/api'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module EacGitlabBase0
8
+ class Api < ::EacRest::Api
9
+ require_sub __FILE__
10
+
11
+ API_SUFFIX = '/api/v4'
12
+
13
+ def auth_token
14
+ ENV.fetch('TRF1_GITLAB_PRIVATE_TOKEN')
15
+ end
16
+
17
+ def build_service_url_suffix(suffix)
18
+ r = super(suffix)
19
+ r.path = API_SUFFIX + r.path
20
+ r
21
+ end
22
+
23
+ def custom_headers
24
+ {
25
+ 'PRIVATE-TOKEN' => auth_token
26
+ }
27
+ end
28
+
29
+ # @return [Avm::EacGitlabBase0::Api::ProjectsSet]
30
+ def nodes_set(*projects_ids)
31
+ ::Avm::EacGitlabBase0::Api::NodesSet.new(self, *projects_ids)
32
+ end
33
+
34
+ def request(service_url_suffix, headers = {}, &body_data_proc)
35
+ super(service_url_suffix, custom_headers.merge(headers), &body_data_proc)
36
+ end
37
+
38
+ def root
39
+ @root ||= ::Avm::EacGitlabBase0::Api::Root.new(self, {})
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/base'
4
+ require 'avm/eac_gitlab_base0/api'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module Avm
8
+ module EacGitlabBase0
9
+ module Instances
10
+ class Base < ::Avm::Instances::Base
11
+ # @return [Avm::EacGitlabBase0::Api]
12
+ def rest_api
13
+ @rest_api ||= ::Avm::EacGitlabBase0::Api.new(web_url)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module EacGitlabBase0
5
+ VERSION = '0.3.0'
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module EacGitlabBase0
7
+ require_sub __FILE__
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: avm-eac_gitlab_base0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Put here the authors
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-11-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: eac_ruby_utils
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.119'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.119.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.119'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.119.2
33
+ - !ruby/object:Gem::Dependency
34
+ name: eac_ruby_gem_support
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 0.5.1
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 0.5.1
47
+ description:
48
+ email:
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/avm/eac_gitlab_base0.rb
54
+ - lib/avm/eac_gitlab_base0/api.rb
55
+ - lib/avm/eac_gitlab_base0/api/base_entity.rb
56
+ - lib/avm/eac_gitlab_base0/api/file.rb
57
+ - lib/avm/eac_gitlab_base0/api/group.rb
58
+ - lib/avm/eac_gitlab_base0/api/member.rb
59
+ - lib/avm/eac_gitlab_base0/api/node.rb
60
+ - lib/avm/eac_gitlab_base0/api/nodes_set.rb
61
+ - lib/avm/eac_gitlab_base0/api/project.rb
62
+ - lib/avm/eac_gitlab_base0/api/root.rb
63
+ - lib/avm/eac_gitlab_base0/instances/base.rb
64
+ - lib/avm/eac_gitlab_base0/version.rb
65
+ homepage:
66
+ licenses: []
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubygems_version: 3.1.6
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Put here de description.
87
+ test_files: []