Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot
2025-07-15 09:07:59 +00:00
parent b9b0bdc404
commit d720dd102d
54 changed files with 1992 additions and 1988 deletions

View File

@ -1,35 +1,34 @@
# frozen_string_literal: true
# This script deletes all projects directly under a group specified by ENV['TOP_LEVEL_GROUP_NAME']
# This script deletes all projects directly under all 'gitlab-e2e-sandbox-group-<#0-7>' groups OR a group specified by
# ENV['TOP_LEVEL_GROUP_NAME']
# - If `dry_run` is true the script will list projects to be deleted, but it won't delete them
# Required environment variables: GITLAB_QA_ACCESS_TOKEN and GITLAB_ADDRESS
# Optional environment variables: TOP_LEVEL_GROUP_NAME (default: 'gitlab-e2e-sandbox-group-<current weekday #>'),
# CLEANUP_ALL_E2E_SANDBOX_GROUPS (default: false),
# Optional environment variables: TOP_LEVEL_GROUP_NAME,
# PERMANENTLY_DELETE (default: false),
# DELETE_BEFORE (default: 1 day ago)
# DELETE_BEFORE - YYYY-MM-DD, YYYY-MM-DD HH:MM:SS, or YYYY-MM-DDT00:00:00Z
# - Set TOP_LEVEL_GROUP_NAME to the name of the e2e sandbox group that you would like to delete projects under.
# - Set CLEANUP_ALL_E2E_SANDBOX_GROUPS to true if you would like to delete projects under all
# 'gitlab-e2e-sandbox-group-*' groups. Otherwise, this will fall back to TOP_LEVEL_GROUP_NAME.
# Otherwise, this will fall back to deleting projects under all top level groups.
# - Set PERMANENTLY_DELETE to true if you would like to permanently delete subgroups on an environment with
# deletion protection enabled. Otherwise, subgroups will remain available during the retention period specified
# in admin settings. On environments with deletion protection disabled, subgroups will always be permanently deleted.
# - Set DELETE_BEFORE to only delete projects that were created before a given date, otherwise defaults to 1 day ago
# - Set DELETE_BEFORE to only delete projects that were created before a given date, otherwise defaults to 2 hours ago
# Run `rake delete_projects`
module QA
module Tools
class DeleteProjects < DeleteResourceBase
# @example mark projects for deletion under 'gitlab-e2e-sandbox-group-<current weekday #>' older than 1 day
# @example mark projects for deletion that are older than 2 hours under all gitlab-e2e-sandbox-group-<#0-7> groups
# GITLAB_ADDRESS=<address> \
# GITLAB_QA_ACCESS_TOKEN=<token> bundle exec rake delete_projects
#
# @example permanently delete projects older than 1 day under all gitlab-e2e-sandbox-group-* groups
# @example permanently delete projects older than 2 hours under all gitlab-e2e-sandbox-group-<#0-7> groups
# GITLAB_ADDRESS=<address> \
# GITLAB_QA_ACCESS_TOKEN=<token> \
# CLEANUP_ALL_E2E_SANDBOX_GROUPS=true \
# PERMANENTLY_DELETE=true bundle exec rake delete_projects
#
# @example mark projects for deletion under 'gitlab-e2e-sandbox-group-2' created before 2023-01-01
@ -48,14 +47,14 @@ module QA
end
def run
if ENV['CLEANUP_ALL_E2E_SANDBOX_GROUPS']
if ENV['TOP_LEVEL_GROUP_NAME']
group_id = fetch_group_id(@api_client, ENV['TOP_LEVEL_GROUP_NAME'])
results = delete_projects(group_id)
else
results = SANDBOX_GROUPS.flat_map do |name|
group_id = fetch_group_id(@api_client, name)
delete_projects(group_id)
end.compact
else
group_id = fetch_group_id(@api_client)
results = delete_projects(group_id)
end
log_results(results)

View File

@ -12,7 +12,8 @@ module QA
ITEMS_PER_PAGE = '100'
PAGE_CUTOFF = '10'
SANDBOX_GROUPS = %w[gitlab-e2e-sandbox-group-1
SANDBOX_GROUPS = %w[gitlab-e2e-sandbox-group-0
gitlab-e2e-sandbox-group-1
gitlab-e2e-sandbox-group-2
gitlab-e2e-sandbox-group-3
gitlab-e2e-sandbox-group-4
@ -27,7 +28,7 @@ module QA
@api_client = Runtime::API::Client.new(ENV['GITLAB_ADDRESS'],
personal_access_token: ENV['GITLAB_QA_ACCESS_TOKEN'])
@delete_before = Date.parse(ENV['DELETE_BEFORE'] || (Date.today - 1).to_s)
@delete_before = Time.parse(ENV['DELETE_BEFORE'] || (Time.now - (2 * 3600)).to_s).utc.iso8601(3)
@dry_run = dry_run
@permanently_delete = !!(ENV['PERMANENTLY_DELETE'].to_s =~ /true|1|y/i)
@type = nil
@ -164,7 +165,7 @@ module QA
).url
if response.code == HTTP_STATUS_OK
resources.concat(parse_body(response).select { |r| Date.parse(r[:created_at]) < @delete_before })
resources.concat(parse_body(response).select { |r| Time.parse(r[:created_at]) < @delete_before })
else
logger.error("Request for #{@type} returned (#{response.code}): `#{response}` ")
exit 1 if fatal_response?(response.code)

View File

@ -1,36 +1,33 @@
# frozen_string_literal: true
# This script deletes all subgroups of a group specified by ENV['TOP_LEVEL_GROUP_NAME']
# - If `dry_run` is true the script will list groups to be deleted, but it won't delete them
# This script deletes all subgroups of all 'gitlab-e2e-sandbox-group-<#0-7>' groups OR all subgroups of a group
# specified by ENV['TOP_LEVEL_GROUP_NAME']
# - If `dry_run` is true the script will list subgroups to be deleted, but it won't delete them
# Required environment variables: GITLAB_QA_ACCESS_TOKEN and GITLAB_ADDRESS
# Optional environment variables: TOP_LEVEL_GROUP_NAME (default: 'gitlab-e2e-sandbox-group-<current weekday #>'),
# CLEANUP_ALL_E2E_SANDBOX_GROUPS (default: false),
# Optional environment variables: TOP_LEVEL_GROUP_NAME,
# PERMANENTLY_DELETE (default: false),
# DELETE_BEFORE (default: 1 day ago)
# - Set TOP_LEVEL_GROUP_NAME to override the default group name determination logic.
# If not set, the default group name will be:
# - All 'gitlab-e2e-sandbox-group-*' groups when CLEANUP_ALL_E2E_SANDBOX_GROUPS is true
# - 'gitlab-e2e-sandbox-group-<current weekday #>' when CLEANUP_ALL_E2E_SANDBOX_GROUPS is false
# DELETE_BEFORE - YYYY-MM-DD, YYYY-MM-DD HH:MM:SS, or YYYY-MM-DDT00:00:00Z
# - Set TOP_LEVEL_GROUP_NAME to only delete subgroups under the given group.
# If not set, subgroups of all 'gitlab-e2e-sandbox-group-<#0-7>' groups will be deleted.
# - Set PERMANENTLY_DELETE to true if you would like to permanently delete subgroups on an environment with
# deletion protection enabled. Otherwise, subgroups will remain available during the retention period specified
# in admin settings. On environments with deletion protection disabled, subgroups will always be permanently deleted.
# - Set DELETE_BEFORE to only delete snippets that were created before a given date, otherwise defaults to 1 day ago
# - Set DELETE_BEFORE to only delete snippets that were created before a given date, otherwise defaults to 2 hours ago
# Run `rake delete_subgroups`
module QA
module Tools
class DeleteSubgroups < DeleteResourceBase
# @example mark subgroups for deletion that are older than 1 day under 'gitlab-e2e-sandbox-group-<current weekday #>'
# @example mark subgroups for deletion that are older than 2 hours under all gitlab-e2e-sandbox-group-<#0-7> groups
# GITLAB_ADDRESS=<address> \
# GITLAB_QA_ACCESS_TOKEN=<token> bundle exec rake delete_subgroups
#
# @example permanently delete subgroups older than 1 day under all gitlab-e2e-sandbox-group-* groups
# @example permanently delete subgroups older than 2 hours under all gitlab-e2e-sandbox-group-<#0-7> groups
# GITLAB_ADDRESS=<address> \
# GITLAB_QA_ACCESS_TOKEN=<token> \
# CLEANUP_ALL_E2E_SANDBOX_GROUPS=true \
# PERMANENTLY_DELETE=true bundle exec rake delete_subgroups
#
# @example mark subgroups for deletion under 'gitlab-e2e-sandbox-group-2' created before 2023-01-01
@ -49,14 +46,14 @@ module QA
end
def run
if ENV['CLEANUP_ALL_E2E_SANDBOX_GROUPS'] && !ENV['TOP_LEVEL_GROUP_NAME']
if ENV['TOP_LEVEL_GROUP_NAME']
group_id = fetch_group_id(@api_client, ENV['TOP_LEVEL_GROUP_NAME'])
results = delete_subgroups(group_id)
else
results = SANDBOX_GROUPS.flat_map do |name|
group_id = fetch_group_id(@api_client, name)
delete_subgroups(group_id)
end.compact
else
group_id = fetch_group_id(@api_client)
results = delete_subgroups(group_id)
end
log_results(results)

View File

@ -6,15 +6,15 @@
# Required environment variables: GITLAB_QA_ACCESS_TOKEN and GITLAB_ADDRESS
# - GITLAB_QA_ACCESS_TOKEN should have API access and belong to the user whose snippets will be deleted
# Optional environment variables: DELETE_BEFORE (default: 1 day ago)
# - Set DELETE_BEFORE to only delete snippets that were created before a given date, otherwise defaults to 1 day ago
# Optional environment variables: DELETE_BEFORE - YYYY-MM-DD, YYYY-MM-DD HH:MM:SS, or YYYY-MM-DDT00:00:00Z
# - Set DELETE_BEFORE to only delete snippets that were created before a given date, otherwise defaults to 2 hours ago
# Run `rake delete_test_snippets`
module QA
module Tools
class DeleteTestSnippets < DeleteResourceBase
# @example delete snippets older than 1 day for the user associated with the given access token
# @example delete snippets older than 2 hours for the user associated with the given access token
# GITLAB_ADDRESS=<address> \
# GITLAB_QA_ACCESS_TOKEN=<token> bundle exec rake delete_test_snippets
#

View File

@ -8,8 +8,8 @@
# Required environment variables: GITLAB_QA_ACCESS_TOKEN and GITLAB_ADDRESS
# - GITLAB_QA_ACCESS_TOKEN should have API access and belong to the user whose keys will be deleted
# Optional environment variables: DELETE_BEFORE (default: 1 day ago)
# - Set DELETE_BEFORE to only delete snippets that were created before a given date, otherwise defaults to 1 day ago
# Optional environment variables: DELETE_BEFORE - YYYY-MM-DD, YYYY-MM-DD HH:MM:SS, or YYYY-MM-DDT00:00:00Z
# - Set DELETE_BEFORE to only delete snippets that were created before a given date, otherwise defaults to 2 hours ago
# Run `rake delete_test_ssh_keys`

View File

@ -7,8 +7,8 @@
# Required environment variables: GITLAB_QA_ADMIN_ACCESS_TOKEN, GITLAB_QA_ACCESS_TOKEN, and GITLAB_ADDRESS
# - GITLAB_QA_ADMIN_ACCESS_TOKEN must have admin API access
# Optional environment variables: DELETE_BEFORE (default: 1 day ago)
# - Set DELETE_BEFORE to only delete users that were created before a given date, otherwise defaults to 1 day ago
# Optional environment variables: DELETE_BEFORE - YYYY-MM-DD, YYYY-MM-DD HH:MM:SS, or YYYY-MM-DDT00:00:00Z
# - Set DELETE_BEFORE to only delete users that were created before a given date, otherwise defaults to 2 hours ago
# Run `rake delete_test_users`

View File

@ -4,15 +4,16 @@
# - If `dry_run` is true the script will list groups to be deleted, but it won't delete them
# Required environment variables: GITLAB_QA_ACCESS_TOKEN, GITLAB_ADDRESS
# Optional environment variables: DELETE_BEFORE
# - Set DELETE_BEFORE to delete only groups that were created before the given date (default: 1 day ago)
# Optional environment variables: DELETE_BEFORE - YYYY-MM-DD, YYYY-MM-DD HH:MM:SS, or YYYY-MM-DDT00:00:00Z
# - Set DELETE_BEFORE to delete only groups that were created before the given date (default: 2 hours ago)
# Run `rake delete_user_groups`
module QA
module Tools
class DeleteUserGroups < DeleteResourceBase
EXCLUDE_GROUPS = %w[gitlab-e2e-sandbox-group-1
EXCLUDE_GROUPS = %w[gitlab-e2e-sandbox-group-0
gitlab-e2e-sandbox-group-1
gitlab-e2e-sandbox-group-2
gitlab-e2e-sandbox-group-3
gitlab-e2e-sandbox-group-4
@ -30,7 +31,7 @@ module QA
qa-perf-testing
remote-development].freeze
# @example - delete user groups older than 1 day
# @example - delete user groups older than 2 hours
# GITLAB_ADDRESS=<address> \
# GITLAB_QA_ACCESS_TOKEN=<token> \
# bundle exec rake delete_user_groups

View File

@ -8,8 +8,8 @@
# OR
# - USER_ID to the id of the user whose projects are to be deleted.
# Optional environment variables: DELETE_BEFORE
# - Set DELETE_BEFORE to delete only projects that were created before the given date (default: 1 day ago)
# Optional environment variables: DELETE_BEFORE - YYYY-MM-DD, YYYY-MM-DD HH:MM:SS, or YYYY-MM-DDT00:00:00Z
# - Set DELETE_BEFORE to delete only projects that were created before the given date (default: 2 hours ago)
# Run `rake delete_user_projects`
@ -26,7 +26,7 @@ module QA
gitlab-qa-user5
gitlab-qa-user6].freeze
# @example - delete the given users projects older than 3 days
# @example - delete the given users projects older than 2 hours
# GITLAB_ADDRESS=<address> \
# GITLAB_QA_ACCESS_TOKEN=<token> \
# USER_ID=<id> bundle exec rake delete_user_projects

View File

@ -5,9 +5,7 @@ module QA
module Lib
module Group
include Support::API
def fetch_group_id(api_client, name = ENV['TOP_LEVEL_GROUP_NAME'])
group_name = name || "gitlab-e2e-sandbox-group-#{Time.now.wday + 1}"
def fetch_group_id(api_client, group_name)
logger.info("Fetching group #{group_name}...")
group_search_response = get Runtime::API::Request.new(api_client, "/groups/#{group_name}").url