debian-mirror-gitlab/app/services/concerns/integrations/project_test_data.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

82 lines
2.6 KiB
Ruby
Raw Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
module Integrations
module ProjectTestData
2023-03-17 16:20:25 +05:30
NoDataError = Class.new(ArgumentError)
2020-06-23 00:09:42 +05:30
private
2023-03-17 16:20:25 +05:30
def no_data_error(msg)
raise NoDataError, msg
end
2020-06-23 00:09:42 +05:30
def push_events_data
Gitlab::DataBuilder::Push.build_sample(project, current_user)
end
def note_events_data
2021-04-29 21:17:54 +05:30
note = NotesFinder.new(current_user, project: project, target: project, sort: 'id_desc').execute.first
2021-03-11 19:13:27 +05:30
2023-03-17 16:20:25 +05:30
no_data_error(s_('TestHooks|Ensure the project has notes.')) unless note.present?
2020-06-23 00:09:42 +05:30
Gitlab::DataBuilder::Note.build(note, current_user)
end
def issues_events_data
2021-03-11 19:13:27 +05:30
issue = IssuesFinder.new(current_user, project_id: project.id, sort: 'created_desc').execute.first
2023-03-17 16:20:25 +05:30
no_data_error(s_('TestHooks|Ensure the project has issues.')) unless issue.present?
2020-06-23 00:09:42 +05:30
issue.to_hook_data(current_user)
end
def merge_requests_events_data
2021-03-11 19:13:27 +05:30
merge_request = MergeRequestsFinder.new(current_user, project_id: project.id, sort: 'created_desc').execute.first
2023-03-17 16:20:25 +05:30
no_data_error(s_('TestHooks|Ensure the project has merge requests.')) unless merge_request.present?
2020-06-23 00:09:42 +05:30
merge_request.to_hook_data(current_user)
end
def job_events_data
2021-03-11 19:13:27 +05:30
build = Ci::JobsFinder.new(current_user: current_user, project: project).execute.first
2023-03-17 16:20:25 +05:30
no_data_error(s_('TestHooks|Ensure the project has CI jobs.')) unless build.present?
2020-06-23 00:09:42 +05:30
Gitlab::DataBuilder::Build.build(build)
end
def pipeline_events_data
2021-03-11 19:13:27 +05:30
pipeline = Ci::PipelinesFinder.new(project, current_user, order_by: 'id', sort: 'desc').execute.first
2023-03-17 16:20:25 +05:30
no_data_error(s_('TestHooks|Ensure the project has CI pipelines.')) unless pipeline.present?
2020-06-23 00:09:42 +05:30
Gitlab::DataBuilder::Pipeline.build(pipeline)
end
def wiki_page_events_data
page = project.wiki.list_pages(limit: 1).first
2021-03-11 19:13:27 +05:30
2023-03-17 16:20:25 +05:30
no_data_error(s_('TestHooks|Ensure the wiki is enabled and has pages.')) if !project.wiki_enabled? || page.blank?
2020-06-23 00:09:42 +05:30
Gitlab::DataBuilder::WikiPage.build(page, current_user, 'create')
end
def deployment_events_data
2021-03-11 19:13:27 +05:30
deployment = DeploymentsFinder.new(project: project, order_by: 'created_at', sort: 'desc').execute.first
2023-03-17 16:20:25 +05:30
no_data_error(s_('TestHooks|Ensure the project has deployments.')) unless deployment.present?
2020-06-23 00:09:42 +05:30
2022-08-13 15:12:31 +05:30
Gitlab::DataBuilder::Deployment.build(deployment, deployment.status, Time.current)
2020-06-23 00:09:42 +05:30
end
2021-01-29 00:20:46 +05:30
def releases_events_data
2021-03-11 19:13:27 +05:30
release = ReleasesFinder.new(project, current_user, order_by: :created_at, sort: :desc).execute.first
2023-03-17 16:20:25 +05:30
no_data_error(s_('TestHooks|Ensure the project has releases.')) unless release.present?
2021-01-29 00:20:46 +05:30
release.to_hook_data('create')
end
2020-06-23 00:09:42 +05:30
end
end