uffizzi_core 2.0.4 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00ba39a6ed0a43804f4225204a8a8bead0bd930b6e41d0af55ed5055b0341148
4
- data.tar.gz: d0f0312479a28b67acda70fa8cc9294f8296215942cceb795f065d356ee62f83
3
+ metadata.gz: f1065eeedad42eb66cc223f635c61871171ab68a30bcbf529601630f4cdd75ee
4
+ data.tar.gz: 4d3a5120d1839a4bf944af27dfcbf501b5b616c909b57af247b9e528c3d4ae62
5
5
  SHA512:
6
- metadata.gz: 00ae81e5bd57a538db963bf231ef34c6e57b574238c1374208f5f412918fd47746b694fe5b5a8f511f0d3d121b26037f4e02dc1149fe65c2369de72b4ad65550
7
- data.tar.gz: e8a42e3edb430950a2eb641b57633f132e49ed94c2e62d51ed4fe48e37c8e9801f69316ff833e0ecafa37848527e9810c2c397a8eeeae4b82a2f9ade1dd62e18
6
+ metadata.gz: 3e0d2877db2d9c6931db243b3f98e47f71235acc288d47c05dd1e5a6841366f82c9ca07ce2958d3b5052869d7ca495089ac3d1da81d636dff2586dd1a21ab842
7
+ data.tar.gz: eabdf9cd8a38a86640d3f25ca0ffc735adae9191b4508c50455d9a24e7d5441c762274033737dae4066060525e7f9953af656a0465cc7418d3d5a3ec324c6f52
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Deployment::LabelsNotFoundError < StandardError
4
+ end
@@ -3,6 +3,7 @@
3
3
  module UffizziCore::Concerns::Models::Deployment
4
4
  extend ActiveSupport::Concern
5
5
 
6
+ # rubocop:disable Metrics/BlockLength
6
7
  included do
7
8
  include AASM
8
9
  include UffizziCore::StateMachineConcern
@@ -72,5 +73,18 @@ module UffizziCore::Concerns::Models::Deployment
72
73
  def preview_url
73
74
  "#{subdomain}.#{Settings.app.managed_dns_zone}"
74
75
  end
76
+
77
+ def from_actions?
78
+ from_github_actions? || from_gitlab_actions?
79
+ end
80
+
81
+ def from_github_actions?
82
+ metadata.dig('labels', 'github', 'repository').present?
83
+ end
84
+
85
+ def from_gitlab_actions?
86
+ metadata.dig('labels', 'gitlab', 'repo').present?
87
+ end
75
88
  end
89
+ # rubocop:enable Metrics/BlockLength
76
90
  end
@@ -89,19 +89,18 @@ class UffizziCore::DeploymentService
89
89
 
90
90
  def build_subdomain(deployment)
91
91
  return build_docker_continuous_preview_subdomain(deployment) if deployment&.continuous_preview_payload&.fetch('docker', nil).present?
92
+ return build_pull_request_subdomain(deployment) if deployment.from_actions?
92
93
 
93
- github_metadata = deployment.metadata.dig('labels', 'github')
94
- return build_pull_request_subdomain(deployment) if
95
- github_metadata&.dig('pull_request', 'number').present? && github_metadata&.dig('repository').present?
96
-
94
+ build_default_subdomain(deployment)
95
+ rescue UffizziCore::Deployment::LabelsNotFoundError
97
96
  build_default_subdomain(deployment)
98
97
  end
99
98
 
100
99
  def build_pull_request_subdomain(deployment)
101
- github_payload = deployment.metadata.dig('labels', 'github')
102
- repo_name = github_payload['repository'].split('/').last.downcase
103
- pull_request_number = github_payload['pull_request']['number']
104
- subdomain = "pr-#{pull_request_number}-#{name(deployment)}-#{repo_name}-#{deployment.project.slug}"
100
+ repo_name, pull_request_number = pull_request_data(deployment)
101
+ raise UffizziCore::Deployment::LabelsNotFoundError if repo_name.nil? || pull_request_number.nil?
102
+
103
+ subdomain = "pr-#{pull_request_number}-#{name(deployment)}-#{repo_name.downcase}"
105
104
  format_subdomain(subdomain)
106
105
  end
107
106
 
@@ -291,5 +290,23 @@ class UffizziCore::DeploymentService
291
290
 
292
291
  sliced_subdomain
293
292
  end
293
+
294
+ def pull_request_data(deployment)
295
+ return github_pull_request_data(deployment) if deployment.from_github_actions?
296
+
297
+ gitlab_merge_request_data(deployment)
298
+ end
299
+
300
+ def github_pull_request_data(deployment)
301
+ github_data = deployment.metadata.dig('labels', 'github')
302
+
303
+ [github_data['repository'], github_data.dig('event', 'number')]
304
+ end
305
+
306
+ def gitlab_merge_request_data(deployment)
307
+ gitlab_data = deployment.metadata.dig('labels', 'gitlab')
308
+
309
+ [gitlab_data['repo'], gitlab_data.dig('merge_request', 'number')]
310
+ end
294
311
  end
295
312
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UffizziCore
4
- VERSION = '2.0.4'
4
+ VERSION = '2.0.5'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uffizzi_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Thurman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-10-18 00:00:00.000000000 Z
12
+ date: 2022-10-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aasm
@@ -774,6 +774,7 @@ files:
774
774
  - app/errors/uffizzi_core/compose_file/parse_error.rb
775
775
  - app/errors/uffizzi_core/compose_file/secrets_error.rb
776
776
  - app/errors/uffizzi_core/deployment/image_pull_error.rb
777
+ - app/errors/uffizzi_core/deployment/labels_not_found_error.rb
777
778
  - app/errors/uffizzi_core/deployment_not_found_error.rb
778
779
  - app/forms/uffizzi_core/api/cli/v1/account/credential/check_credential_form.rb
779
780
  - app/forms/uffizzi_core/api/cli/v1/account/credential/create_form.rb