Commit 130aab96 authored by Grant Young's avatar Grant Young Committed by Walmyr Lima e Silva Filho

Update QA delete_subgroups task for soft deletions

Task now ignores subgroups already marked for deletion.
Soft deletion was added earlier this week:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/19430
parent 3e9f52f8
......@@ -26,30 +26,19 @@ module QA
group_id = fetch_group_id
sub_groups_head_response = head Runtime::API::Request.new(@api_client, "/groups/#{group_id}/subgroups", per_page: "100").url
total_sub_groups = sub_groups_head_response.headers[:x_total]
total_sub_group_pages = sub_groups_head_response.headers[:x_total_pages]
STDOUT.puts "total_sub_groups: #{total_sub_groups}"
STDOUT.puts "total_sub_group_pages: #{total_sub_group_pages}"
sub_group_ids = fetch_subgroup_ids(group_id, total_sub_group_pages)
STDOUT.puts "Number of Sub Groups not already marked for deletion: #{sub_group_ids.length}"
total_sub_group_pages.to_i.times do |page_no|
# Fetch all subgroups for the top level group
sub_groups_response = get Runtime::API::Request.new(@api_client, "/groups/#{group_id}/subgroups", per_page: "100").url
sub_group_ids = JSON.parse(sub_groups_response.body).map { |subgroup| subgroup["id"] }
if sub_group_ids.any?
STDOUT.puts "\n==== Current Page: #{page_no + 1} ====\n"
delete_subgroups(sub_group_ids)
end
end
delete_subgroups(sub_group_ids) unless sub_group_ids.empty?
STDOUT.puts "\nDone"
end
private
def delete_subgroups(sub_group_ids)
STDOUT.puts "Deleting #{sub_group_ids.length} subgroups..."
sub_group_ids.each do |subgroup_id|
delete_response = delete Runtime::API::Request.new(@api_client, "/groups/#{subgroup_id}").url
dot_or_f = delete_response.code == 202 ? "\e[32m.\e[0m" : "\e[31mF\e[0m"
......@@ -61,6 +50,17 @@ module QA
group_search_response = get Runtime::API::Request.new(@api_client, "/groups", search: ENV['GROUP_NAME_OR_PATH'] || 'gitlab-qa-sandbox-group').url
JSON.parse(group_search_response.body).first["id"]
end
def fetch_subgroup_ids(group_id, group_pages)
sub_groups_ids = []
group_pages.to_i.times do |page_no|
sub_groups_response = get Runtime::API::Request.new(@api_client, "/groups/#{group_id}/subgroups", page: (page_no + 1).to_s, per_page: "100").url
sub_groups_ids.concat(JSON.parse(sub_groups_response.body).reject { |subgroup| !subgroup["marked_for_deletion_on"].nil? }.map { |subgroup| subgroup["id"] })
end
sub_groups_ids.uniq
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment