Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
NARKOZ authored Jun 13, 2024
2 parents 51fdbcc + 35dcb04 commit 3057717
Show file tree
Hide file tree
Showing 29 changed files with 1,071 additions and 8 deletions.
21 changes: 19 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,30 @@ on:
- master

jobs:
build:
ruby2x:
runs-on: ubuntu-latest
strategy:
matrix:
ruby:
- 2.6
- 2.7
name: Ruby ${{ matrix.ruby }} test
steps:
- uses: actions/checkout@v2
- name: Set up Ruby ${{ matrix.ruby }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: Build and test with Rake
run: |
gem install bundler -v 2.4.22 --no-document
bundle install --jobs 4 --retry 3
bundle exec rake
ruby3x:
runs-on: ubuntu-latest
strategy:
matrix:
ruby:
- 3.0
- 3.1
- 3.2
Expand Down Expand Up @@ -43,6 +60,6 @@ jobs:
ruby-version: 2.6
- name: Lint with Rubocop
run: |
gem install bundler --no-document
gem install bundler -v 2.4.22 --no-document
bundle install --jobs 4 --retry 3
bundle exec rake rubocop
2 changes: 1 addition & 1 deletion lib/gitlab/cli_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def actions
#
# @return [Gitlab::Client]
def client
@client ||= Gitlab::Client.new(endpoint: (Gitlab.endpoint || ''))
@client ||= Gitlab::Client.new(endpoint: Gitlab.endpoint || '')
end

# Returns method names and their owners
Expand Down
1 change: 1 addition & 0 deletions lib/gitlab/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Client < API
include Markdown
include MergeRequestApprovals
include MergeRequests
include MergeTrains
include Milestones
include Namespaces
include Notes
Expand Down
94 changes: 94 additions & 0 deletions lib/gitlab/client/groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -354,5 +354,99 @@ def add_group_custom_attribute(key, value, group_id)
def delete_group_custom_attribute(key, group_id = nil)
delete("/groups/#{group_id}/custom_attributes/#{key}")
end

# List all the specified groups hooks
#
# @example
# Gitlab.list_group_hooks(3)
#
# @param [Integer] group_id The ID of a group.
# @return [Gitlab::PaginatedResponse] List of registered hooks https://docs.gitlab.com/ee/api/groups.html#hooks
def list_group_hooks(group_id)
get("/groups/#{group_id}/hooks")
end

# get specified group hook
#
# @example
# Gitlab.group_hook(3, 1)
#
# @param [Integer] group_id The ID of a group.
# @param [Integer] hook_id The ID of the hook.
# @return [Gitlab::ObjectifiedHash] The hook https://docs.gitlab.com/ee/api/groups.html#get-group-hook
def group_hook(group_id, hook_id)
get("/groups/#{group_id}/hooks/#{hook_id}")
end

# Add a new group hook
#
# @example
# Gitlab.add_group_hook(3, "https://example.com/my-hook-receiver", {token: "verify me"})
#
# @param [Integer] group_id The ID of a group.
# @param [String] the hook url which will receive the selected events
# @option options [Boolean] :name The name of the group.
# @option options [Boolean] :push_events Trigger hook on push events
# @potion options [String] :push_events_branch_filter Trigger hook on push events for matching branches only.
# @option options [Boolean] :issues_events Trigger hook on issues events
# @option options [Boolean] :confidential_issues_events Trigger hook on confidential issues events
# @option options [Boolean] :merge_requests_events Trigger hook on merge requests events
# @option options [Boolean] :tag_push_events Trigger hook on tag push events
# @option options [Boolean] :note_events Trigger hook on note events
# @option options [Boolean] :confidential_note_events Trigger hook on confidential note events
# @option options [Boolean] :job_events Trigger hook on job events
# @option options [Boolean] :pipeline_events Trigger hook on pipeline events
# @option options [Boolean] :wiki_page_events Trigger hook on wiki page events
# @option options [Boolean] :deployment_events Trigger hook on deployment events
# @option options [Boolean] :releases_events Trigger hook on release events
# @option options [Boolean] :subgroup_events Trigger hook on subgroup events
# @option options [Boolean] :enable_ssl_verification Do SSL verification when triggering the hook
# @option options [String] :token Secret token to validate received payloads; not returned in the response
# @return [Gitlab::ObjectifiedHash] Response body matches https://docs.gitlab.com/ee/api/groups.html#get-group-hook
def add_group_hook(group_id, url, options = {})
post("/groups/#{group_id}/hooks", body: options.merge(url: url))
end

# Edit a group hook
#
# @example
# Gitlab.edit_group_hook(3, 1, "https://example.com/my-hook-receiver", {token: "verify me"})
#
# @param [Integer] group_id The ID of a group.
# @param [Integer] hook_id The ID of a group.
# @param [String] the hook url which will receive the selected events
# @option options [Boolean] :name The name of the group.
# @option options [Boolean] :push_events Trigger hook on push events
# @potion options [String] :push_events_branch_filter Trigger hook on push events for matching branches only.
# @option options [Boolean] :issues_events Trigger hook on issues events
# @option options [Boolean] :confidential_issues_events Trigger hook on confidential issues events
# @option options [Boolean] :merge_requests_events Trigger hook on merge requests events
# @option options [Boolean] :tag_push_events Trigger hook on tag push events
# @option options [Boolean] :note_events Trigger hook on note events
# @option options [Boolean] :confidential_note_events Trigger hook on confidential note events
# @option options [Boolean] :job_events Trigger hook on job events
# @option options [Boolean] :pipeline_events Trigger hook on pipeline events
# @option options [Boolean] :wiki_page_events Trigger hook on wiki page events
# @option options [Boolean] :deployment_events Trigger hook on deployment events
# @option options [Boolean] :releases_events Trigger hook on release events
# @option options [Boolean] :subgroup_events Trigger hook on subgroup events
# @option options [Boolean] :enable_ssl_verification Do SSL verification when triggering the hook
# @option options [String] :token Secret token to validate received payloads; not returned in the response
# @return [Gitlab::ObjectifiedHash] Response body matches https://docs.gitlab.com/ee/api/groups.html#edit-group-hook
def edit_group_hook(group_id, hook_id, url, options = {})
post("/groups/#{group_id}/hooks/#{hook_id}", body: options.merge(url: url))
end

# Delete a group hook
#
# @example
# Gitlab.delete_group_hook(3, 1)
#
# @param [Integer] group_id The ID of a group.
# @param [Integer] hook_id The ID of a group.
# @return [Gitlab::ObjectifiedHash] no body, will evaluate to an empty hash. https://docs.gitlab.com/ee/api/groups.html#delete-group-hook
def delete_group_hook(group_id, hook_id)
delete("/groups/#{group_id}/hooks/#{hook_id}")
end
end
end
11 changes: 11 additions & 0 deletions lib/gitlab/client/issues.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,16 @@ def participants_on_issue(project, id)
def merge_requests_closing_issue_on_merge(project, id)
get("/projects/#{url_encode project}/issues/#{id}/closed_by")
end

# List related merge requests
#
# @example
# Gitlab.related_merge_requests(3, 42)
#
# @param [Integer, String] project The ID or name of a project.
# @param [Integer] id The ID of an issue.
def related_merge_requests(project, id)
get("/projects/#{url_encode project}/issues/#{id}/related_merge_requests")
end
end
end
55 changes: 55 additions & 0 deletions lib/gitlab/client/merge_trains.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# frozen_string_literal: true

class Gitlab::Client
# Defines methods related to merge trains.
# @see https://docs.gitlab.com/ee/api/merge_trains.html
module MergeTrains
# Get list of merge trains for a project.
#
# @example
# Gitlab.merge_trains(1, scope: :active, sort: :asc)
#
# @param [Integer, String] project The ID or name of a project.
# @param [Hash] options A customizable set of options.
# @option options [String] :scope The scope of merge trains to return, one of: :active, :complete
# @option options [String] :sort Sort by created_at either 'asc' or 'desc'
# @return [Array<Gitlab::ObjectifiedHash>]
def merge_trains(project, options = {})
get("/projects/#{url_encode project}/merge_trains", query: options)
end

# Get all merge requests added to a merge train for the requested target branch.
#
# @param [Integer, String] project The ID or name of a project.
# @param [String] target_branch The target branch of the merge train.
# @param [Hash] options A customizable set of options.
# @option options [String] :scope The scope of merge trains to return, one of: :active, :complete
# @option options [String] :sort Sort by created_at either 'asc' or 'desc'
# @return [Array<Gitlab::ObjectifiedHash>]
def merge_train_merge_requests(project, target_branch, options = {})
get("/projects/#{url_encode project}/merge_trains/#{target_branch}", query: options)
end

# Get merge train information for the requested merge request.
#
# @param [Integer, String] project The ID or name of a project.
# @param [Integer] merge_request_iid The IID of the merge request.
# @return [Gitlab::ObjectifiedHash]
def merge_train_status(project, merge_request_iid)
get("/projects/#{url_encode project}/merge_trains/merge_requests/#{merge_request_iid}")
end

# Add a merge request to the merge train targeting the merge request’s target branch.
#
# @param [Integer, String] project The ID or name of a project.
# @param [Integer] merge_request_iid The IID of the merge request.
# @param [Hash] options A customizable set of options.
# @option options [Boolean] :when_pipeline_succeeds Add merge request to merge train when pipeline succeeds.
# @option options [String] :sha If present, the SHA must match the HEAD of the source branch, otherwise the merge fails.
# @option options [Boolean] :squash If true, the commits are squashed into a single commit on merge.
# @return [Array<Gitlab::ObjectifiedHash>] <description>
def add_merge_request_to_merge_train(project, merge_request_iid, options = {})
post("/projects/#{url_encode project}/merge_trains/merge_requests/#{merge_request_iid}", query: options)
end
end
end
25 changes: 25 additions & 0 deletions lib/gitlab/client/pipelines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ def pipeline_test_report(project, id)
get("/projects/#{url_encode project}/pipelines/#{id}/test_report")
end

# Gets a single pipeline's variables.
#
# @example
# Gitlab.pipeline_variables(5, 36)
#
# @param [Integer, String] project The ID or name of a project.
# @param [Integer] id The ID of a pipeline.
# @return [Array<Gitlab::ObjectifiedHash>]
def pipeline_variables(project, id)
get("/projects/#{url_encode project}/pipelines/#{id}/variables")
end

# Create a pipeline.
#
# @example
Expand Down Expand Up @@ -101,5 +113,18 @@ def retry_pipeline(project, id)
def delete_pipeline(project, id)
delete("/projects/#{url_encode project}/pipelines/#{id}")
end

# Update a pipeline metadata
#
# @example
# Gitlab.update_pipeline_metadata(5, 1, name: 'new name')
#
# @param [Integer, String] project The ID or name of a project.
# @param [Integer] id The ID of a pipeline.
# @option options [String] :name The new name of the pipeline.
# @return [Gitlab::ObjectifiedHash]
def update_pipeline_metadata(project, id, options = {})
put("/projects/#{url_encode project}/pipelines/#{id}/metadata", body: options)
end
end
end
93 changes: 92 additions & 1 deletion lib/gitlab/client/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ def create_user(*args)
post('/users', body: body)
end

# Creates a service account.
# Requires authentication from an admin account.
#
# @example
# Gitlab.create_service_account('service_account_6018816a18e515214e0c34c2b33523fc', 'Service account user')
#
# @param [String] name (required) The email of the service account.
# @param [String] username (required) The username of the service account.
# @return [Gitlab::ObjectifiedHash] Information about created service account.
def create_service_account(*args)
raise ArgumentError, 'Missing required parameters' unless args[1]

body = { name: args[0], username: args[1] }
post('/service_accounts', body: body)
end

# Updates a user.
#
# @example
Expand Down Expand Up @@ -298,7 +314,7 @@ def delete_email(id, user_id = nil)
delete(url)
end

# Search for groups by name
# Search for users by name
#
# @example
# Gitlab.user_search('gitlab')
Expand All @@ -313,6 +329,19 @@ def user_search(search, options = {})
get('/users', query: options)
end

# Get user by username
#
# @example
# Gitlab.user_by_username('gitlab')
#
# @param [String] username A username to get.
# @param [Hash] options A customizable set of options.
# @return [Array<Gitlab::ObjectifiedHash>]
def user_by_username(username, options = {})
options[:username] = username
get('/users', query: options)
end

# Gets user custom_attributes.
#
# @example
Expand Down Expand Up @@ -404,6 +433,47 @@ def create_user_impersonation_token(user_id, name, scopes, expires_at = nil)
post("/users/#{user_id}/impersonation_tokens", body: body)
end

# Get all personal access tokens for a user
#
# @example
# Gitlab.user_personal_access_tokens(1)
#
# @param [Integer] user_id The ID of the user.
# @return [Array<Gitlab::ObjectifiedHash>]
def user_personal_access_tokens(user_id)
get("/personal_access_tokens?user_id=#{user_id}")
end

# Create personal access token
#
# @example
# Gitlab.create_personal_access_token(2, "token", ["api", "read_user"])
# Gitlab.create_personal_access_token(2, "token", ["api", "read_user"], "1970-01-01")
#
# @param [Integer] user_id The ID of the user.
# @param [String] name Name of the personal access token.
# @param [Array<String>] scopes Array of scopes for the impersonation token
# @param [String] expires_at Date for impersonation token expiration in ISO format.
# @return [Gitlab::ObjectifiedHash]
def create_personal_access_token(user_id, name, scopes, expires_at = nil)
body = { name: name, scopes: scopes }
body[:expires_at] = expires_at if expires_at
post("/users/#{user_id}/personal_access_tokens", body: body)
end

# Rotate a personal access token
#
# @example
# Gitlab.rotate_personal_access_token(1)
#
# @param [Integer] personal_access_token_id ID of the personal access token.
# @return [Gitlab::ObjectifiedHash]
def rotate_personal_access_token(personal_access_token_id, expires_at = nil)
body = {}
body[:expires_at] = expires_at if expires_at
post("/personal_access_tokens/#{personal_access_token_id}/rotate", body: body)
end

# Revoke an impersonation token
#
# @example
Expand All @@ -416,6 +486,27 @@ def revoke_user_impersonation_token(user_id, impersonation_token_id)
delete("/users/#{user_id}/impersonation_tokens/#{impersonation_token_id}")
end

# Lists all projects and groups a user is a member of
#
# @example
# Gitlab.memberships(2)
#
# @param [Integer] user_id The ID of the user.
def memberships(user_id)
get("/users/#{user_id}/memberships")
end

# Revoke a personal access token
#
# @example
# Gitlab.revoke_personal_access_token(1)
#
# @param [Integer] personal_access_token_id ID of the personal access token.
# @return [Gitlab::ObjectifiedHash]
def revoke_personal_access_token(personal_access_token_id)
delete("/personal_access_tokens/#{personal_access_token_id}")
end

# Disables two factor authentication (2FA) for the specified user.
#
# @example
Expand Down
Loading

0 comments on commit 3057717

Please sign in to comment.