gitlab-customer-support-operations_gitlab 1.0.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.
Files changed (35) hide show
  1. checksums.yaml +7 -0
  2. data/lib/support_ops_gitlab/gitlab/badges.rb +229 -0
  3. data/lib/support_ops_gitlab/gitlab/base.rb +552 -0
  4. data/lib/support_ops_gitlab/gitlab/client.rb +51 -0
  5. data/lib/support_ops_gitlab/gitlab/commits.rb +198 -0
  6. data/lib/support_ops_gitlab/gitlab/configuration.rb +86 -0
  7. data/lib/support_ops_gitlab/gitlab/epics.rb +325 -0
  8. data/lib/support_ops_gitlab/gitlab/events.rb +167 -0
  9. data/lib/support_ops_gitlab/gitlab/gpg_keys.rb +64 -0
  10. data/lib/support_ops_gitlab/gitlab/group_memberships.rb +33 -0
  11. data/lib/support_ops_gitlab/gitlab/groups.rb +431 -0
  12. data/lib/support_ops_gitlab/gitlab/invitations.rb +72 -0
  13. data/lib/support_ops_gitlab/gitlab/issues.rb +606 -0
  14. data/lib/support_ops_gitlab/gitlab/jobs.rb +61 -0
  15. data/lib/support_ops_gitlab/gitlab/markdown.rb +54 -0
  16. data/lib/support_ops_gitlab/gitlab/merge_requests.rb +411 -0
  17. data/lib/support_ops_gitlab/gitlab/milestones.rb +195 -0
  18. data/lib/support_ops_gitlab/gitlab/namespaces.rb +184 -0
  19. data/lib/support_ops_gitlab/gitlab/notes.rb +182 -0
  20. data/lib/support_ops_gitlab/gitlab/pipelines.rb +258 -0
  21. data/lib/support_ops_gitlab/gitlab/project_access_tokens.rb +245 -0
  22. data/lib/support_ops_gitlab/gitlab/project_memberships.rb +33 -0
  23. data/lib/support_ops_gitlab/gitlab/project_webhook_events.rb +33 -0
  24. data/lib/support_ops_gitlab/gitlab/project_webhooks.rb +218 -0
  25. data/lib/support_ops_gitlab/gitlab/projects.rb +741 -0
  26. data/lib/support_ops_gitlab/gitlab/repository_files.rb +102 -0
  27. data/lib/support_ops_gitlab/gitlab/repository_submodules.rb +78 -0
  28. data/lib/support_ops_gitlab/gitlab/ssh_keys.rb +67 -0
  29. data/lib/support_ops_gitlab/gitlab/user_emails.rb +147 -0
  30. data/lib/support_ops_gitlab/gitlab/user_memberships.rb +21 -0
  31. data/lib/support_ops_gitlab/gitlab/user_tokens.rb +344 -0
  32. data/lib/support_ops_gitlab/gitlab/users.rb +1059 -0
  33. data/lib/support_ops_gitlab/gitlab.rb +45 -0
  34. data/lib/support_ops_gitlab.rb +28 -0
  35. metadata +251 -0
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ # Defines the module GitLab
6
+ module GitLab
7
+ ##
8
+ # Defines the class RepositoryFiles within the module {SupportOps::GitLab}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [String] blob_id
13
+ # @attr [String] commit_id
14
+ # @attr [String] content
15
+ # @attr [String] content_sha256
16
+ # @attr [String] encoding
17
+ # @attr [Boolean] execute_filemode
18
+ # @attr [String] file_name
19
+ # @attr [String] file_path
20
+ # @attr [String] last_commit_id
21
+ # @attr [String] ref
22
+ # @attr [Integer] size
23
+ # @todo Document attribute meaning
24
+ # @todo Stuff at https://docs.gitlab.com/api/repository_files/
25
+ class RepositoryFiles < SupportOps::GitLab::Base
26
+ define_attributes :blob_id, :commit_id, :content, :content_sha256,
27
+ :encoding, :execute_filemode, :file_name, :file_path,
28
+ :last_commit_id, :ref, :size
29
+ readonly_attributes :blob_id, :commit_id, :content, :content_sha256,
30
+ :encoding, :execute_filemode, :file_name, :file_path,
31
+ :last_commit_id, :ref, :size
32
+
33
+ ##
34
+ # Get file from repository
35
+ #
36
+ # @author Jason Colyer
37
+ # @since 1.0.0
38
+ # @see
39
+ # https://docs.gitlab.com/api/repository_files/#get-file-from-repository
40
+ # GitLab API > Repository files > Get file from repository
41
+ # @param project_id [Integer] The project ID to look in (can also use a URL encoded String)
42
+ # @param path [String] The path to the file in the repository
43
+ # @param ref [String] The ref to look in (defaults to HEAD, meaning the default branch)
44
+ # @see SupportOps::GitLab::Configuration Setting up a client
45
+ # @return String
46
+ # @example
47
+ # require 'support_ops_gitlab'
48
+ #
49
+ # SupportOps::GitLab::Configuration.configure do |config|
50
+ # config.url = 'https://gitlab.com/api/v4'
51
+ # config.token = 'abc123'
52
+ # end
53
+ #
54
+ # file = SupportOps::GitLab::RepositoryFiles.get(123456, 'public/hw.txt')
55
+ # pp file.file_path
56
+ # # => "public/hw.txt"
57
+ # pp file.content
58
+ # # => "Hello World!"
59
+ def self.get(project_id, path, ref = 'HEAD')
60
+ response = client.connection.get("projects/#{project_id}/repository/files/#{ERB::Util.url_encode(path)}?ref=#{ref}")
61
+ body = Oj.load(response.body)
62
+ return nil unless response.status == 200
63
+
64
+ RepositoryFiles.new(body)
65
+ end
66
+
67
+ ##
68
+ # Get raw file from repository
69
+ #
70
+ # @author Jason Colyer
71
+ # @since 1.0.0
72
+ # @see
73
+ # https://docs.gitlab.com/api/repository_files/#get-raw-file-from-repository
74
+ # GitLab API > Repository files > Get raw file from repository
75
+ # @param project_id [Integer] The project ID to look in (can also use a URL encoded String)
76
+ # @param path [String] The path to the file in the repository
77
+ # @param ref [String] The ref to look in (defaults to HEAD, meaning the default branch)
78
+ # @param lft [Boolean] Determines if the response should be Git LFS file contents, rather than the pointer (defaults to false)
79
+ # @see SupportOps::GitLab::Configuration Setting up a client
80
+ # @return String
81
+ # @example
82
+ # require 'support_ops_gitlab'
83
+ #
84
+ # SupportOps::GitLab::Configuration.configure do |config|
85
+ # config.url = 'https://gitlab.com/api/v4'
86
+ # config.token = 'abc123'
87
+ # end
88
+ #
89
+ # content = SupportOps::GitLab::RepositoryFiles.get_raw(123456, 'public/hw.txt')
90
+ # pp content
91
+ # # => "Hello World!"
92
+ def self.get_raw(project_id, path, ref = 'HEAD', lfs = false)
93
+ response = client.connection.get("projects/#{project_id}/repository/files/#{ERB::Util.url_encode(path)}/raw?ref=#{ref}")
94
+ return nil unless response.status == 200
95
+
96
+ response.body
97
+ end
98
+
99
+ private
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ # Defines the module GitLab
6
+ module GitLab
7
+ ##
8
+ # Defines the class RepositorySubmodules within the module {SupportOps::GitLab}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [String] authored_date
13
+ # @attr [String] author_email
14
+ # @attr [String] author_name
15
+ # @attr [String] committed_date
16
+ # @attr [String] committer_email
17
+ # @attr [String] committer_name
18
+ # @attr [String] created_at
19
+ # @attr [String] id
20
+ # @attr [String] message
21
+ # @attr [Array] parent_ids
22
+ # @attr [String] short_id
23
+ # @attr [String] status
24
+ # @attr [String] title
25
+ # @todo Document attribute meaning
26
+ class RepositorySubmodules < SupportOps::GitLab::Base
27
+ define_attributes :authored_date, :author_email, :author_name,
28
+ :committed_date, :committer_email, :committer_name,
29
+ :created_at, :id, :message, :parent_ids, :short_id,
30
+ :status, :title
31
+ readonly_attributes :authored_date, :author_email, :author_name,
32
+ :committed_date, :committer_email, :committer_name,
33
+ :created_at, :id, :message, :parent_ids, :short_id,
34
+ :status, :title
35
+
36
+ ##
37
+ # Update existing submodule reference in repository
38
+ #
39
+ # @author Jason Colyer
40
+ # @since 1.0.0
41
+ # @see
42
+ # https://docs.gitlab.com/api/repository_submodules/#update-existing-submodule-reference-in-repository
43
+ # GitLab API > Repository submodules > Update existing submodule reference in repository
44
+ # @param project_id [Integer] The ID of the project the submodule is in
45
+ # @param path [String] The path to the submodule in the project
46
+ # @param branch [String] The branch to update the submodule in
47
+ # @param sha [String] The commit SHA to use for the update
48
+ # @param message [String optional] The commit message to use (defaults to nil, where it would be ignored)
49
+ # @see SupportOps::GitLab::Configuration Setting up a client
50
+ # @return String
51
+ # @example
52
+ # require 'support_ops_gitlab'
53
+ #
54
+ # SupportOps::GitLab::Configuration.configure do |config|
55
+ # config.url = 'https://gitlab.com/api/v4'
56
+ # config.token = 'abc123'
57
+ # end
58
+ #
59
+ # submodule = SupportOps::GitLab::RepositorySubmodules.update!(5, 'lib/modules/example', 'main', '3ddec28ea23acc5caa5d8331a6ecb2a65fc03e88', 'Update submodule reference')
60
+ # pp submodule.id
61
+ # # => "ed899a2f4b50b4370feeea94676502b42383c746"
62
+ def self.update!(project_id, path, branch, sha, message = nil)
63
+ data = {
64
+ branch: branch,
65
+ commit_sha: sha
66
+ }
67
+ data[:commit_message] = message unless message.nil?
68
+ response = client.conneciton.put("projects/#{project_id}/repository/submodules/#{ERB::Util.url_encode(path)}", data.to_json)
69
+ body = Oj.load(response.body)
70
+ raise "Failed to update submodule #{path} => #{body}" unless response.status == 200
71
+ RepositorySubmodules.new(body)
72
+ end
73
+
74
+ private
75
+ end
76
+ end
77
+ end
78
+
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ # Defines the module GitLab
6
+ module GitLab
7
+ ##
8
+ # Defines the class SSHKeys within the module {SupportOps::GitLab}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [String] created_at Timestamp for when the key was created
13
+ # @attr [String] expires_at Timestamp when the SSH key should auto-remove
14
+ # @attr [Integer] id ID value of the key
15
+ # @attr [String] key Public key value
16
+ # @attr [String] title Title for key
17
+ # @attr [String] usage_type Usage scope for the key; possible values: auth, signing, or auth_and_signing; default value: auth_and_signing
18
+ # @todo Get an SSH key for a user > https://docs.gitlab.com/api/user_keys/#get-an-ssh-key-for-a-user
19
+ # @todo Add an SSH key for a user > https://docs.gitlab.com/api/user_keys/#add-an-ssh-key-for-a-user
20
+ # @todo Delete an SSH key for a user > https://docs.gitlab.com/api/user_keys/#delete-an-ssh-key-for-a-user
21
+ class SSHKeys < SupportOps::GitLab::Base
22
+ define_attributes :created_at, :expires_at, :id, :key, :title, :usage_type
23
+ readonly_attributes :created_at, :id
24
+
25
+ ##
26
+ # Lists all SSH keys for a user
27
+ #
28
+ # @author Jason Colyer
29
+ # @since 1.0.0
30
+ # @overload list(key: value)
31
+ # @param user_id [Integer optional] The user ID to get SSH keys of (not
32
+ # including this does it for the current user)
33
+ # @return [Array]
34
+ # @see
35
+ # https://docs.gitlab.com/api/user_keys/#list-all-ssh-keys-for-a-user
36
+ # GitLab API > SSH and GPG Keys > List all SSH keys for a user
37
+ # @see SupportOps::GitLab::Configuration Setting up a client
38
+ # @example
39
+ # require 'support_ops_gitlab'
40
+ #
41
+ # SupportOps::GitLab::Configuration.configure do |config|
42
+ # config.url = 'https://gitlab.example.com/api/v4'
43
+ # config.token = 'abc123'
44
+ # end
45
+ #
46
+ # keys = SupportOps::GitLab::SSHKeys.list(user_id: 123456)
47
+ # pp keys.count
48
+ # # => 3
49
+ # pp keys.last.usage_type
50
+ # # => "auth"
51
+ def self.list(**args)
52
+ args[:user_id] = nil unless args[:user_id]
53
+ url = if args[:user_id].nil?
54
+ 'user/keys'
55
+ else
56
+ "users/#{args[:user_id]}/keys"
57
+ end
58
+ response = client.connection.get(url)
59
+ body = Oj.load(response.body)
60
+ raise "Unable to get SSH keys of user => #{body}" if response.status != 200
61
+ body.map { |s| SSHKeys.new(s) }
62
+ end
63
+
64
+ private
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,147 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ # Defines the module GitLab
6
+ module GitLab
7
+ ##
8
+ # Defines the class UserEmails within the module {SupportOps::GitLab}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [String] confirmed_at Timestamp of when the email address was confirmed
13
+ # @attr [String] email The email address
14
+ # @attr [Integer] id ID of the email address
15
+ # @attr [Boolean] skip_confirmation Used in creations only, skips sending the confirmation email
16
+ # @attr [Integer] user_id Used in creations only, specifies the user ID
17
+ # @todo Get details on an email address => https://docs.gitlab.com/api/user_email_addresses/#get-details-on-an-email-address
18
+ class UserEmails < SupportOps::GitLab::Base
19
+ # @!parse
20
+ # # Adds an email address to a user
21
+ # #
22
+ # # @author Jason Colyer
23
+ # # @since 1.0.0
24
+ # # @return [Object] Instance of {SupportOps::GitLab::Users}
25
+ # # @note This is inherited from {SupportOps::GitLab::Base#save!}
26
+ # # @see
27
+ # # https://docs.gitlab.com/api/user_email_addresses/#add-an-email-address-for-a-user
28
+ # # GitLab API > User Email Addresses > Add an email address for a user
29
+ # # @example
30
+ # # require 'support_ops_gitlab'
31
+ # #
32
+ # # SupportOps::GitLab::Configuration.configure do |config|
33
+ # # config.token = ENV.fetch('GL_TOKEN')
34
+ # # config.url = 'https://gitlab.com/api/v4'
35
+ # # end
36
+ # #
37
+ # # new_email = SupportOps::GitLab::UserEmails.new
38
+ # # new_email.email = 'test@example.com'
39
+ # # new_email.skip_confirmation = true
40
+ # # new_email.user_id = 123456
41
+ # #
42
+ # # new_email.save!
43
+ # #
44
+ # # pp new_email.id
45
+ # # # => 9873843
46
+ # @!parse
47
+ # # Deletes a user
48
+ # #
49
+ # # @author Jason Colyer
50
+ # # @since 1.0.0
51
+ # # @return [Boolean]
52
+ # # @note This is inherited from {SupportOps::GitLab::Base#delete!}
53
+ # # @see
54
+ # # https://docs.gitlab.com/api/user_email_addresses/#delete-an-email-address-for-a-user
55
+ # # GitLab API > User Email Addresses > Delete an email address for a user
56
+ # # @example
57
+ # # require 'support_ops_gitlab'
58
+ # #
59
+ # # SupportOps::GitLab::Configuration.configure do |config|
60
+ # # config.token = ENV.fetch('GL_TOKEN')
61
+ # # config.url = 'https://gitlab.com/api/v4'
62
+ # # end
63
+ # #
64
+ # # emails = SupportOps::GitLab::UserEmails.list
65
+ # # email = emails.last
66
+ # # email.delete!
67
+ # def delete!; end
68
+ define_attributes :confirmed_at, :email, :id, :skip_confirmation, :user_id
69
+ readonly_attributes :confirmed_at, :id
70
+
71
+ ##
72
+ # Lists all email addresses for a user
73
+ #
74
+ # @author Jason Colyer
75
+ # @since 1.0.0
76
+ # @overload list(key: value)
77
+ # @param user_id [Integer optional] The user ID to get emails of (not
78
+ # including this does it for the current user)
79
+ # @return [Array]
80
+ # @see
81
+ # https://docs.gitlab.com/api/user_email_addresses/#list-all-email-addresses-for-a-user
82
+ # GitLab API > User Emails > List all email addresses for a user
83
+ # @see SupportOps::GitLab::Configuration Setting up a client
84
+ # @example
85
+ # require 'support_ops_gitlab'
86
+ #
87
+ # SupportOps::GitLab::Configuration.configure do |config|
88
+ # config.url = 'https://gitlab.example.com/api/v4'
89
+ # config.token = 'abc123'
90
+ # end
91
+ #
92
+ # emails = SupportOps::GitLab::UserEmails.list(user_id: 123456)
93
+ # pp emails.count
94
+ # # => 2
95
+ # pp emails.last.email
96
+ # # => "email2@example.com"
97
+ def self.list(**args)
98
+ args[:user_id] = nil unless args[:user_id]
99
+ url = if args[:user_id].nil?
100
+ 'user/emails'
101
+ else
102
+ "users/#{args[:user_id]}/emails"
103
+ end
104
+ response = client.connection.get(url)
105
+ body = Oj.load(response.body)
106
+ raise "Unable to get emails of user => #{body}" if response.status != 200
107
+ body.map { |e| UserEmails.new(e) }
108
+ end
109
+
110
+ private
111
+
112
+ ##
113
+ # @private
114
+ def create_record
115
+ data = {
116
+ email: self.email,
117
+ skip_confirmation: ( self.skip_confirmation.nil? ? false : self.skip_confirmation )
118
+ }.to_json
119
+ url = if self.user_id.nil?
120
+ 'user/emails'
121
+ else
122
+ "users/#{self.user_id}/emails"
123
+ end
124
+ response = self.client.connection.post(url, data)
125
+ body = Oj.load(response.body)
126
+ raise "Failed to add email address => #{body}" if response.status != 201
127
+ body
128
+ end
129
+
130
+ ##
131
+ # @private
132
+ def update_record
133
+ raise 'You cannot update email addresses like that'
134
+ end
135
+
136
+ ##
137
+ # @private
138
+ def delete_record
139
+ response = self.client.connection.delete("user/emails/#{self.id}")
140
+ body = Oj.load(response.body)
141
+ raise "No such email to delete #{self.email}" if response.status == 404
142
+ raise "Failed to delete email #{self.email} => #{body}" if response.status != 204
143
+ true
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ # Defines the module GitLab
6
+ module GitLab
7
+ ##
8
+ # Defines the class UserMemberships within the module {SupportOps::GitLab}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [Integer] access_level Access level to the source
13
+ # @attr [Integer] source_id ID of the source
14
+ # @attr [String] source_name Name of the source
15
+ # @attr [String] source_type Membership type (Project or Namespace)
16
+ class UserMemberships < SupportOps::GitLab::Base
17
+ define_attributes :access_level, :source_id, :source_name, :source_type
18
+ readonly_attributes :access_level, :source_id, :source_name, :source_type
19
+ end
20
+ end
21
+ end