Skip to content

Commit

Permalink
Merge pull request #6266 from ChrisBr/staging-workflow-default-scope
Browse files Browse the repository at this point in the history
Add default_scope to StagingProject
  • Loading branch information
ChrisBr committed Nov 16, 2018
2 parents 3177dbb + 8a06eb9 commit 6ccf924
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/api/app/models/staging/staging_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class StagingProject < Project
has_many :status_reports, through: :repositories, inverse_of: :checkable
belongs_to :staging_workflow, class_name: 'Staging::Workflow'

default_scope { where.not(staging_workflow: nil) }

def staging_identifier
name[/.*:Staging:(.*)/, 1]
end
Expand Down
3 changes: 2 additions & 1 deletion src/api/app/models/staging/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def write_to_backend

def create_staging_projects
['A', 'B'].each do |letter|
staging_project = Staging::StagingProject.find_or_initialize_by(name: "#{project.name}:Staging:#{letter}")
parent = Project.find_or_initialize_by(name: "#{project.name}:Staging:#{letter}")
staging_project = parent.becomes(Staging::StagingProject)
next if staging_project.staging_workflow # if it belongs to another staging workflow skip it
staging_project.staging_workflow = self
staging_project.store
Expand Down

0 comments on commit 6ccf924

Please sign in to comment.