Skip to content

Commit

Permalink
Use standard before filters
Browse files Browse the repository at this point in the history
Instead of re-inventing set_project/repository/architecture.
  • Loading branch information
hennevogel committed Jun 26, 2024
1 parent 9d9d170 commit 18124e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 44 deletions.
48 changes: 9 additions & 39 deletions src/api/app/controllers/webui/packages/build_log_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,29 @@ class BuildLogController < Webui::WebuiController
include Webui::NotificationsHandler

before_action :check_ajax, only: :update_build_log
before_action :set_project
before_action :set_repository
before_action :set_architecture
before_action :check_build_log_access
before_action :handle_notification, only: :live_build_log

def live_build_log
@repo = @project.repositories.find_by(name: params[:repository]).try(:name)
unless @repo
flash[:error] = "Couldn't find repository '#{params[:repository]}'. Are you sure it still exists?"
redirect_to(package_show_path(@project, @package))
return
end

@arch = Architecture.archcache[params[:arch]].try(:name)
unless @arch
flash[:error] = "Couldn't find architecture '#{params[:arch]}'. Are you sure it still exists?"
redirect_to(package_show_path(@project, @package))
return
end

@offset = 0
@status = get_status(@project, @package_name, @repo, @arch)
@what_depends_on = Package.what_depends_on(@project, @package_name, @repo, @arch)
@status = get_status(@project, @package_name, @repository, @architecture)
@what_depends_on = Package.what_depends_on(@project, @package_name, @repository, @architecture)
@finished = Buildresult.final_status?(status)

set_job_status
end

def update_build_log
# Make sure objects don't contain invalid chars (eg. '../')
@repo = @project.repositories.find_by(name: params[:repository]).try(:name)
unless @repo
@errors = "Couldn't find repository '#{params[:repository]}'. We don't have build log for this repository"
return
end

@arch = Architecture.archcache[params[:arch]].try(:name)
unless @arch
@errors = "Couldn't find architecture '#{params[:arch]}'. We don't have build log for this architecture"
return
end

begin
@maxsize = 1024 * 64
@first_request = params[:initial] == '1'
@offset = params[:offset].to_i
@status = get_status(@project, @package_name, @repo, @arch)
@status = get_status(@project, @package_name, @repository, @architecture)
@finished = Buildresult.final_status?(@status)
@size = get_size_of_log(@project, @package_name, @repo, @arch)
@size = get_size_of_log(@project, @package_name, @repository, @architecture)

chunk_start = @offset
chunk_end = @offset + @maxsize
Expand All @@ -62,7 +38,7 @@ def update_build_log
chunk_end = @size
end

@log_chunk = get_log_chunk(@project, @package_name, @repo, @arch, chunk_start, chunk_end)
@log_chunk = get_log_chunk(@project, @package_name, @repository, @architecture, chunk_start, chunk_end)

old_offset = @offset
@offset = [chunk_end, @size].min
Expand Down Expand Up @@ -96,12 +72,6 @@ def update_build_log
#
# If the check succeeds it sets @project and @package variables.
def check_build_log_access
@project = Project.find_by(name: params[:project])
unless @project
redirect_to root_path, error: "Couldn't find project '#{params[:project]}'. Are you sure it still exists?"
return false
end

@package_name = params[:package]

# No need to check for the package, they only exist on the backend in this case
Expand Down Expand Up @@ -138,7 +108,7 @@ def set_job_status
@percent = nil

begin
jobstatus = get_job_status(@project, @package_name, @repo, @arch)
jobstatus = get_job_status(@project, @package_name, @repository, @architecture)
if jobstatus.present?
js = Xmlhash.parse(jobstatus)
@workerid = js.get('workerid')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
%h3= @pagetitle
%p
%strong Repository:
= @repo
= @repository
%strong Architecture:
= @arch
= @architecture
- if @workerid
= render partial: 'job_status', locals: { worker_id: @workerid, build_time: @buildtime, percent: @percent }
%p
Expand All @@ -22,9 +22,9 @@
%strong Packages:
= @what_depends_on.join(', ')
= render partial: 'live_build_log_controls',
locals: { can_modify: @can_modify, package_name: @package_name, project: @project, arch: @arch, repo: @repo }
locals: { can_modify: @can_modify, package_name: @package_name, project: @project, arch: @architecture, repo: @repository }
#log-space-wrapper{ data: { url: package_update_build_log_path(package: @package_name, project: @project,
status: @status, arch: @arch, repository: @repo) } }
status: @status, arch: @architecture, repository: @repository) } }
.d-block.text-center.shadow-sm.position-sticky.w-100#log-info{ class: @current_notification ? 'notification-bar-offset' : '' }
.running.stop_refresh.py-2.text-bg-info
%i.fas.fa-spinner.fa-pulse
Expand All @@ -43,7 +43,7 @@
%pre.p-4.bg-body-secondary.text-pre-wrap#log-space
- unless @workerid
= render partial: 'live_build_log_controls',
locals: { can_modify: @can_modify, package_name: @package_name, project: @project, arch: @arch, repo: @repo }
locals: { can_modify: @can_modify, package_name: @package_name, project: @project, arch: @architecture, repo: @repository }

:javascript
liveLog = new LiveLog('#log-space-wrapper', '.start_refresh', '.stop_refresh', '#status', #{@finished}, '#log-info',
Expand Down

0 comments on commit 18124e9

Please sign in to comment.