Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
150716d6
Commit
150716d6
authored
Jan 23, 2019
by
Sanad Liaquat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add script to delete all subgroups within the specified group
parent
5cc49c16
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
1 deletion
+91
-1
qa/Gemfile.lock
qa/Gemfile.lock
+1
-1
qa/Rakefile
qa/Rakefile
+6
-0
qa/qa/support/api.rb
qa/qa/support/api.rb
+18
-0
qa/qa/tools/delete_subgroups.rb
qa/qa/tools/delete_subgroups.rb
+66
-0
No files found.
qa/Gemfile.lock
View file @
150716d6
...
@@ -97,7 +97,7 @@ DEPENDENCIES
...
@@ -97,7 +97,7 @@ DEPENDENCIES
airborne (~> 0.2.13)
airborne (~> 0.2.13)
capybara (~> 2.16.1)
capybara (~> 2.16.1)
capybara-screenshot (~> 1.0.18)
capybara-screenshot (~> 1.0.18)
nokogiri (~> 1.10.
0
)
nokogiri (~> 1.10.
1
)
pry-byebug (~> 3.5.1)
pry-byebug (~> 3.5.1)
rake (~> 12.3.0)
rake (~> 12.3.0)
rspec (~> 3.7)
rspec (~> 3.7)
...
...
qa/Rakefile
View file @
150716d6
require_relative
'qa/tools/revoke_all_personal_access_tokens'
require_relative
'qa/tools/revoke_all_personal_access_tokens'
require_relative
'qa/tools/delete_subgroups'
desc
"Revokes all personal access tokens"
desc
"Revokes all personal access tokens"
task
:revoke_personal_access_tokens
do
task
:revoke_personal_access_tokens
do
QA
::
Tools
::
RevokeAllPersonalAccessTokens
.
new
.
run
QA
::
Tools
::
RevokeAllPersonalAccessTokens
.
new
.
run
end
end
desc
"Deletes subgroups within a provided group"
task
:delete_subgroups
do
QA
::
Tools
::
DeleteSubgroups
.
new
.
run
end
qa/qa/support/api.rb
View file @
150716d6
...
@@ -20,6 +20,24 @@ module QA
...
@@ -20,6 +20,24 @@ module QA
e
.
response
e
.
response
end
end
def
delete
(
url
)
RestClient
::
Request
.
execute
(
method: :delete
,
url:
url
,
verify_ssl:
false
)
rescue
RestClient
::
ExceptionWithResponse
=>
e
e
.
response
end
def
head
(
url
)
RestClient
::
Request
.
execute
(
method: :head
,
url:
url
,
verify_ssl:
false
)
rescue
RestClient
::
ExceptionWithResponse
=>
e
e
.
response
end
def
parse_body
(
response
)
def
parse_body
(
response
)
JSON
.
parse
(
response
.
body
,
symbolize_names:
true
)
JSON
.
parse
(
response
.
body
,
symbolize_names:
true
)
end
end
...
...
qa/qa/tools/delete_subgroups.rb
0 → 100644
View file @
150716d6
# frozen_string_literal: true
require_relative
'../../qa'
# This script deletes all subgroups of a group specified by ENV['GROUP_NAME_OR_PATH']
# Required environment variables: PERSONAL_ACCESS_TOKEN and GITLAB_ADDRESS
# Optional environment variable: GROUP_NAME_OR_PATH (defaults to 'gitlab-qa-sandbox-group')
# Run `rake delete_subgroups`
module
QA
module
Tools
class
DeleteSubgroups
include
Support
::
Api
def
initialize
raise
ArgumentError
,
"Please provide GITLAB_ADDRESS"
unless
ENV
[
'GITLAB_ADDRESS'
]
raise
ArgumentError
,
"Please provide PERSONAL_ACCESS_TOKEN"
unless
ENV
[
'PERSONAL_ACCESS_TOKEN'
]
@api_client
=
Runtime
::
API
::
Client
.
new
(
ENV
[
'GITLAB_ADDRESS'
],
personal_access_token:
ENV
[
'PERSONAL_ACCESS_TOKEN'
])
end
def
run
STDOUT
.
puts
'Running...'
# Fetch group's id
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
}
"
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
STDOUT
.
puts
"
\n
Done"
end
private
def
delete_subgroups
(
sub_group_ids
)
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"
print
dot_or_f
end
end
def
fetch_group_id
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
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment