Class: Ci::CreateTriggerRequestService

Inherits:
Object
  • Object
show all
Defined in:
app/services/ci/create_trigger_request_service.rb

Instance Method Summary collapse

Instance Method Details

#execute(project, trigger, ref, variables = nil) ⇒ Object


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/services/ci/create_trigger_request_service.rb', line 3

def execute(project, trigger, ref, variables = nil)
  commit = project.commit(ref)
  return unless commit

  # check if ref is tag
  tag = project.repository.find_tag(ref).present?

  ci_commit = project.ci_commits.create(sha: commit.sha, ref: ref, tag: tag)

  trigger_request = trigger.trigger_requests.create!(
    variables: variables,
    commit: ci_commit,
  )

  if ci_commit.create_builds(nil, trigger_request)
    trigger_request
  end
end