Class: Escobar::Heroku::PipelinePromotionRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/escobar/heroku/pipeline_promotion_request.rb

Overview

Class reperesenting a request for Pipeline Promotion

Defined Under Namespace

Classes: Error, MissingContextsError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, pipeline, source, targets, second_factor) ⇒ PipelinePromotionRequest

Returns a new instance of PipelinePromotionRequest.



10
11
12
13
14
15
16
17
# File 'lib/escobar/heroku/pipeline_promotion_request.rb', line 10

def initialize(client, pipeline, source, targets, second_factor)
  @id = pipeline.id
  @client = client
  @pipeline = pipeline
  @source = source
  @targets = targets || []
  @second_factor = second_factor
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/escobar/heroku/pipeline_promotion_request.rb', line 5

def client
  @client
end

#custom_payloadObject

Returns the value of attribute custom_payload.



8
9
10
# File 'lib/escobar/heroku/pipeline_promotion_request.rb', line 8

def custom_payload
  @custom_payload
end

#environmentObject

Returns the value of attribute environment.



8
9
10
# File 'lib/escobar/heroku/pipeline_promotion_request.rb', line 8

def environment
  @environment
end

#forcedObject

Returns the value of attribute forced.



8
9
10
# File 'lib/escobar/heroku/pipeline_promotion_request.rb', line 8

def forced
  @forced
end

#github_deployment_urlObject (readonly)

Returns the value of attribute github_deployment_url.



6
7
8
# File 'lib/escobar/heroku/pipeline_promotion_request.rb', line 6

def github_deployment_url
  @github_deployment_url
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/escobar/heroku/pipeline_promotion_request.rb', line 5

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/escobar/heroku/pipeline_promotion_request.rb', line 5

def name
  @name
end

#pipelineObject (readonly)

Returns the value of attribute pipeline.



5
6
7
# File 'lib/escobar/heroku/pipeline_promotion_request.rb', line 5

def pipeline
  @pipeline
end

#second_factorObject

Returns the value of attribute second_factor.



8
9
10
# File 'lib/escobar/heroku/pipeline_promotion_request.rb', line 8

def second_factor
  @second_factor
end

#shaObject (readonly)

Returns the value of attribute sha.



6
7
8
# File 'lib/escobar/heroku/pipeline_promotion_request.rb', line 6

def sha
  @sha
end

#sourceObject (readonly)

Returns the value of attribute source.



5
6
7
# File 'lib/escobar/heroku/pipeline_promotion_request.rb', line 5

def source
  @source
end

#targetsObject (readonly)

Returns the value of attribute targets.



5
6
7
# File 'lib/escobar/heroku/pipeline_promotion_request.rb', line 5

def targets
  @targets
end

Instance Method Details

#create(environment, forced, custom_payload) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
# File 'lib/escobar/heroku/pipeline_promotion_request.rb', line 19

def create(environment, forced, custom_payload)
  raise ArgumentError, "No target applications" if targets.empty?
  @environment = environment
  @forced = forced
  @custom_payload = custom_payload

  fill_promotion_target_urls
  create_in_api
end

#create_in_apiObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/escobar/heroku/pipeline_promotion_request.rb', line 29

def create_in_api
  promotion = Escobar::Heroku::PipelinePromotion.new(
    client, pipeline, source, targets, second_factor
  )

  releases = promotion.create
  handle_github_deployment_statuses_for(releases)
  releases
rescue PipelinePromotion::RequiresTwoFactorError
  handle_2fa_failure
  raise
end

#handle_2fa_failureObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/escobar/heroku/pipeline_promotion_request.rb', line 42

def handle_2fa_failure
  target_urls.values.each do |target_url|
    create_github_deployment_status(
      target_url,
      nil,
      "error",
      "Missing second factor"
    )
  end
end

#handle_github_deployment_statuses_for(releases) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/escobar/heroku/pipeline_promotion_request.rb', line 53

def handle_github_deployment_statuses_for(releases)
  releases.each do |release|
    release.sha = release.ref
    release.github_url = target_urls[release.app.id]
    release.pipeline_name = pipeline.name

    create_github_deployment_status(
      release.github_url,
      release.dashboard_release_output_url,
      "pending",
      "Promotion releasing.."
    )
  end
end