Read about our upcoming Code of Conduct on this issue

This instance will be upgraded to Heptapod 0.28.1 on 2022-01-26 at 16:00 UTC+1 (a few minutes of down time)

project_service.rb 1.87 KB
Newer Older
1
2
# frozen_string_literal: true

3
4
module TestHooks
  class ProjectService < TestHooks::BaseService
5
    attr_writer :project
6
7
8
9
10

    def project
      @project ||= hook.project
    end

11
12
    private

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    def push_events_data
      throw(:validation_error, 'Ensure the project has at least one commit.') if project.empty_repo?

      Gitlab::DataBuilder::Push.build_sample(project, current_user)
    end

    alias_method :tag_push_events_data, :push_events_data

    def note_events_data
      note = project.notes.first
      throw(:validation_error, 'Ensure the project has notes.') unless note.present?

      Gitlab::DataBuilder::Note.build(note, current_user)
    end

    def issues_events_data
      issue = project.issues.first
      throw(:validation_error, 'Ensure the project has issues.') unless issue.present?

      issue.to_hook_data(current_user)
    end

    alias_method :confidential_issues_events_data, :issues_events_data

    def merge_requests_events_data
      merge_request = project.merge_requests.first
      throw(:validation_error, 'Ensure the project has merge requests.') unless merge_request.present?

      merge_request.to_hook_data(current_user)
    end

    def job_events_data
      build = project.builds.first
      throw(:validation_error, 'Ensure the project has CI jobs.') unless build.present?

      Gitlab::DataBuilder::Build.build(build)
    end

    def pipeline_events_data
52
      pipeline = project.ci_pipelines.first
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
      throw(:validation_error, 'Ensure the project has CI pipelines.') unless pipeline.present?

      Gitlab::DataBuilder::Pipeline.build(pipeline)
    end

    def wiki_page_events_data
      page = project.wiki.pages.first
      if !project.wiki_enabled? || page.blank?
        throw(:validation_error, 'Ensure the wiki is enabled and has pages.')
      end

      Gitlab::DataBuilder::WikiPage.build(page, current_user, 'create')
    end
  end
end