Skip to content

Commit

Permalink
Merge pull request #13726 from hellcp-work/ensure-correct-staging
Browse files Browse the repository at this point in the history
Ensure that the staging badge displays when submitted against a staging project
  • Loading branch information
danidoni committed Feb 8, 2023
2 parents 1b2c3ac + dd38228 commit 902c125
Show file tree
Hide file tree
Showing 4 changed files with 1,114 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/api/app/controllers/webui/request_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ def show
diffs: true, action_id: action_id.to_i, cacheonly: 1).first
@active_action = @bs_request.bs_request_actions.find(action_id)

@request_reviews = @bs_request.reviews.for_non_staging_projects
@staging_status = staging_status(@bs_request)
target_project = Project.find_by_name(@bs_request.target_project_name)
@request_reviews = @bs_request.reviews.for_non_staging_projects(target_project)
@staging_status = staging_status(@bs_request, target_project) if Staging::Workflow.find_by(project: target_project)
@refresh = @action[:diff_not_cached]

# Collecting all issues in a hash. Each key is the issue name and the value is a hash containing all the issue details.
Expand All @@ -42,7 +43,7 @@ def show
@project_maintainers = if Project.deleted?(@bs_request.target_project_name)
[]
else
Project.find_by_name(@bs_request.target_project_name).maintainers
target_project.maintainers
end

# search for a project, where the user is not a package maintainer but a project maintainer and show
Expand Down Expand Up @@ -473,8 +474,7 @@ def render_request_update
}
end

def staging_status(request)
target_project = Project.find_by(name: request.target_project_name)
def staging_status(request, target_project)
return nil unless (staging_review = request.reviews.staging(target_project).last)

if staging_review.for_project?
Expand Down
9 changes: 6 additions & 3 deletions src/api/app/models/review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ class NotFoundError < APIError
scope :opened, -> { where(state: :new) }
scope :accepted, -> { where(state: :accepted) }
scope :declined, -> { where(state: :declined) }
scope :for_staging_projects, -> { includes(:project).where.not(projects: { staging_workflow_id: nil }) }
scope :for_non_staging_projects, -> { includes(:project).where(projects: { staging_workflow_id: nil }) }
scope :for_staging_projects, lambda { |project|
includes(:project).where(projects: { staging_workflow: Staging::Workflow.find_by(project:) })
.where.not(projects: { staging_workflow_id: nil })
}
scope :for_non_staging_projects, ->(project) { where.not(id: for_staging_projects(project)) }

scope :staging, ->(project) { for_staging_projects.or(where(group: Staging::Workflow.find_by(project:)&.managers_group)) }
scope :staging, ->(project) { for_staging_projects(project).or(where(group: Staging::Workflow.find_by(project:).managers_group)) }

before_validation(on: :create) do
self.state = :new if self[:state].nil?
Expand Down
Loading

0 comments on commit 902c125

Please sign in to comment.