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
1fb4c2df
Commit
1fb4c2df
authored
Feb 15, 2022
by
Pavel Shutsin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add development seeds for triage ops
parent
c128cb00
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
139 additions
and
0 deletions
+139
-0
db/fixtures/development/33_triage_ops.rb
db/fixtures/development/33_triage_ops.rb
+139
-0
No files found.
db/fixtures/development/33_triage_ops.rb
0 → 100644
View file @
1fb4c2df
# frozen_string_literal: true
require
'./spec/support/sidekiq_middleware'
require
'./spec/support/helpers/test_env'
class
Gitlab::Seeder::TriageOps
WEBHOOK_URL
=
'http://0.0.0.0:8080'
WEBHOOK_TOKEN
=
"triage-ops-webhook-token"
def
seed!
puts
"Updating settings to allow web hooks to localhost"
ApplicationSetting
.
current_without_cache
.
update!
(
allow_local_requests_from_web_hooks_and_services:
true
)
Sidekiq
::
Testing
.
inline!
do
puts
"Ensuring required groups"
ensure_group
(
'gitlab-com'
)
ensure_group
(
'gitlab-jh/jh-team'
)
ensure_group
(
'gitlab-org'
)
ensure_group
(
'gitlab-org/gitlab-core-team/community-members'
)
ensure_group
(
'gitlab-org/security'
)
puts
"Ensuring required projects"
ensure_project
(
'gitlab-org/gitlab'
)
ensure_project
(
'gitlab-org/security/gitlab'
)
puts
"Ensuring required bot user"
ensure_bot_user
puts
"Setting up webhooks for
#{
WEBHOOK_URL
}
"
ensure_webhook_for
(
'gitlab-com'
)
ensure_webhook_for
(
'gitlab-org'
)
end
end
private
def
ensure_bot_user
bot
=
User
.
find_by_username
(
'triagebot'
)
bot
||=
User
.
create!
(
username:
'triagebot'
,
name:
'Triage Bot'
,
email:
'triagebot@example.com'
,
confirmed_at:
DateTime
.
now
,
password:
SecureRandom
.
hex
.
slice
(
0
,
16
)
)
ensure_group
(
'gitlab-org'
).
add_maintainer
(
bot
)
ensure_group
(
'gitlab-com'
).
add_maintainer
(
bot
)
params
=
{
scopes:
[
'api'
],
name:
"API Token
#{
Time
.
zone
.
now
}
"
}
response
=
PersonalAccessTokens
::
CreateService
.
new
(
current_user:
bot
,
target_user:
bot
,
params:
params
).
execute
unless
response
.
success?
raise
"Can't create Triage Bot access token:
#{
response
.
message
}
"
end
puts
"Bot with API_TOKEN=
#{
response
[
:personal_access_token
].
token
}
is present now."
bot
end
def
ensure_webhook_for
(
group_path
)
group
=
Group
.
find_by_full_path
(
group_path
)
hook_params
=
{
enable_ssl_verification:
false
,
token:
WEBHOOK_TOKEN
,
url:
WEBHOOK_URL
}
# Subscribe the hook to all possible events.
all_group_hook_events
=
GroupHook
.
triggers
.
values
all_group_hook_events
.
each
{
|
value
|
hook_params
[
value
]
=
true
}
group
.
hooks
.
delete_all
hook
=
group
.
hooks
.
new
(
hook_params
)
hook
.
save!
puts
"Hook token '
#{
hook
.
token
}
' for '
#{
group_path
}
' group is present now."
end
def
ensure_group
(
full_path
)
group
=
Group
.
find_by_full_path
(
full_path
)
return
group
if
group
parent_path
=
full_path
.
split
(
'/'
)[
0
..-
2
].
join
(
'/'
)
parent
=
ensure_group
(
parent_path
)
if
parent_path
.
present?
group_path
=
full_path
.
split
(
'/'
).
last
group
=
Group
.
new
(
name:
group_path
.
titleize
,
path:
group_path
,
parent_id:
parent
&
.
id
)
group
.
description
=
FFaker
::
Lorem
.
sentence
group
.
save!
group
.
add_owner
(
User
.
first
)
group
.
create_namespace_settings
group
end
def
ensure_project
(
project_fullpath
)
project
=
Project
.
find_by_full_path
(
project_fullpath
)
return
project
if
project
group_path
=
project_fullpath
.
split
(
'/'
)[
0
..-
2
].
join
(
'/'
)
project_path
=
project_fullpath
.
split
(
'/'
).
last
group
=
ensure_group
(
group_path
)
params
=
{
namespace_id:
group
.
id
,
name:
project_path
.
titleize
,
path:
project_path
,
description:
FFaker
::
Lorem
.
sentence
,
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
,
skip_disk_validation:
true
}
project
=
::
Projects
::
CreateService
.
new
(
User
.
first
,
params
).
execute
raise
"Can't create project '
#{
project_fullpath
}
' :
#{
project
.
errors
.
full_messages
}
"
unless
project
.
persisted?
project
end
end
if
ENV
[
'SEED_TRIAGE_OPS'
]
Gitlab
::
Seeder
.
quiet
do
Gitlab
::
Seeder
::
TriageOps
.
new
.
seed!
end
else
puts
"Skipped. Use the `SEED_TRIAGE_OPS` environment variable to enable seeding data for triage ops project."
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