From 7d0fe1f04ed285e7e5cf825a305114b3e981c2f8 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Sat, 16 Jul 2016 18:39:58 +0200 Subject: Add implementation of manual actions --- app/models/ci/build.rb | 24 ++++++++++++++++++++++++ app/models/ci/pipeline.rb | 4 ++++ 2 files changed, 28 insertions(+) (limited to 'app/models/ci') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index ffac3a22efc..81feca0088f 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -15,6 +15,7 @@ module Ci scope :with_artifacts, ->() { where.not(artifacts_file: nil) } scope :with_expired_artifacts, ->() { with_artifacts.where('artifacts_expire_at < ?', Time.now) } scope :last_month, ->() { where('created_at > ?', Date.today - 1.month) } + scope :manual_actions, ->() { where(when: :manual).without_created } mount_uploader :artifacts_file, ArtifactUploader mount_uploader :artifacts_metadata, ArtifactUploader @@ -91,6 +92,29 @@ module Ci end end + def manual? + self.when == 'manual' + end + + def playable_actions + pipeline.playable_actions + end + + def playable? + project.builds_enabled? && commands.present? && manual? + end + + def play(current_user = nil) + if skipped? + # We can run skipped build + new_build.user = current_user + new_build.queue + else + # Otherwise we need to create a duplicate + Ci::Build.retry(self, current_user) + end + end + def retryable? project.builds_enabled? && commands.present? && complete? end diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index b468434866b..5aefe1d1694 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -65,6 +65,10 @@ module Ci !tag? end + def playable_actions + builds.manual_actions.latest + end + def retryable? builds.latest.any? do |build| build.failed? && build.retryable? -- cgit v1.2.1 From 3248c9fb56e5d5cb8980cb37effec1ee2f4f664a Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Sat, 16 Jul 2016 23:06:34 +0200 Subject: Rename playable_actions to manual_actions --- app/models/ci/build.rb | 4 ---- app/models/ci/pipeline.rb | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) (limited to 'app/models/ci') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 81feca0088f..a05b3f43f97 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -96,10 +96,6 @@ module Ci self.when == 'manual' end - def playable_actions - pipeline.playable_actions - end - def playable? project.builds_enabled? && commands.present? && manual? end diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 5aefe1d1694..de9c74194ac 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -65,8 +65,8 @@ module Ci !tag? end - def playable_actions - builds.manual_actions.latest + def manual_actions + builds.latest.manual_actions end def retryable? -- cgit v1.2.1 From e00da96c88314df79600e7848ae6fe7e4a29af2e Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Sun, 17 Jul 2016 01:48:51 +0200 Subject: Improve manual actions code and add model, service and feature tests Manual actions are accessible from: - Pipelines - Builds - Environments - Deployments --- app/models/ci/build.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'app/models/ci') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index a05b3f43f97..248ecd71962 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -15,7 +15,7 @@ module Ci scope :with_artifacts, ->() { where.not(artifacts_file: nil) } scope :with_expired_artifacts, ->() { with_artifacts.where('artifacts_expire_at < ?', Time.now) } scope :last_month, ->() { where('created_at > ?', Date.today - 1.month) } - scope :manual_actions, ->() { where(when: :manual).without_created } + scope :manual_actions, ->() { where(when: :manual).relevant } mount_uploader :artifacts_file, ArtifactUploader mount_uploader :artifacts_metadata, ArtifactUploader @@ -96,15 +96,19 @@ module Ci self.when == 'manual' end + def other_actions + pipeline.manual_actions.where.not(id: self) + end + def playable? project.builds_enabled? && commands.present? && manual? end def play(current_user = nil) - if skipped? - # We can run skipped build - new_build.user = current_user - new_build.queue + # Try to queue a current build + if self.queue + self.update(user: current_user) + self else # Otherwise we need to create a duplicate Ci::Build.retry(self, current_user) -- cgit v1.2.1 From 5b119a9dc85943b3f60868a347a814e767c9840c Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Sun, 17 Jul 2016 15:59:07 +0200 Subject: Fix rubocop offenses --- app/models/ci/build.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/models/ci') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 248ecd71962..c9566560461 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -107,8 +107,8 @@ module Ci def play(current_user = nil) # Try to queue a current build if self.queue - self.update(user: current_user) - self + self.update(user: current_user) + self else # Otherwise we need to create a duplicate Ci::Build.retry(self, current_user) -- cgit v1.2.1 From 60583bf9db5be7f83863602672e1689853609687 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Mon, 18 Jul 2016 14:57:24 +0200 Subject: Make manual actions to work with master code --- app/models/ci/build.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/ci') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index c9566560461..49a123d488b 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -15,7 +15,7 @@ module Ci scope :with_artifacts, ->() { where.not(artifacts_file: nil) } scope :with_expired_artifacts, ->() { with_artifacts.where('artifacts_expire_at < ?', Time.now) } scope :last_month, ->() { where('created_at > ?', Date.today - 1.month) } - scope :manual_actions, ->() { where(when: :manual).relevant } + scope :manual_actions, ->() { where(when: :manual) } mount_uploader :artifacts_file, ArtifactUploader mount_uploader :artifacts_metadata, ArtifactUploader -- cgit v1.2.1