Skip to content

Commit

Permalink
Implement workflow run show page
Browse files Browse the repository at this point in the history
  • Loading branch information
danidoni authored and krauselukas committed Jan 24, 2022
1 parent d998aea commit 3e0d023
Show file tree
Hide file tree
Showing 11 changed files with 352 additions and 24 deletions.
14 changes: 14 additions & 0 deletions src/api/app/components/workflow_run_header_component.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
%h3
#{hook_event.humanize} event
%p
- if hook_action
%span.badge.badge-primary= hook_action.humanize
%span.badge{ class: status_class }= status.humanize
%p Repository: #{link_to(repository_name, repository_url)}
- case hook_event
- when 'pull_request'
%p PR: #{link_to("##{event_source_name}", event_source_url)}
- when 'Merge Request Hook'
%p MR: #{link_to("##{event_source_name}", event_source_url)}
- when 'push', 'Push Hook'
%p Commit: #{link_to(event_source_name, event_source_url)}
18 changes: 18 additions & 0 deletions src/api/app/components/workflow_run_header_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class WorkflowRunHeaderComponent < WorkflowRunRowComponent
def initialize(workflow_run:)
super

@workflow_run = workflow_run
end

def status_class
case status
when 'fail'
'badge-danger'
when 'success'
'badge-primary'
else
'badge-warning'
end
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.col-1.text-left
%i{ title: status_title, class: status_icon }
.col.text-left
#{hook_event.humanize} event
= link_to "#{hook_event.humanize} event", token_workflow_run_path(@workflow_run.token, @workflow_run)
- if hook_action
%span.badge.badge-primary= hook_action.humanize
.col.text-left
Expand Down
5 changes: 3 additions & 2 deletions src/api/app/components/workflow_run_row_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class WorkflowRunRowComponent < ApplicationComponent
}.freeze

SOURCE_URL_PAYLOAD_MAPPING = {
'pull_request' => ['pull_request', 'url'],
'pull_request' => ['pull_request', 'html_url'],
'Merge Request Hook' => ['object_attributes', 'url'],
'push' => ['head_commit', 'url'],
'Push Hook' => ['commits', 0, 'url']
Expand Down Expand Up @@ -43,7 +43,8 @@ def repository_url
end

def event_source_name
payload.dig(*SOURCE_NAME_PAYLOAD_MAPPING[hook_event])
path = SOURCE_NAME_PAYLOAD_MAPPING[hook_event]
payload.dig(*path) if path
end

def event_source_url
Expand Down
8 changes: 8 additions & 0 deletions src/api/app/controllers/webui/workflow_runs_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
class Webui::WorkflowRunsController < Webui::WebuiController
def index
@workflow_runs = WorkflowRunPolicy::Scope.new(User.session, WorkflowRun, { token_id: params[:token_id] }).resolve.page(params[:page])
@token = Token::Workflow.find(params[:token_id])
end

def show
@workflow_run = WorkflowRun.find(params[:id])
authorize @workflow_run, policy_class: WorkflowRunPolicy

@token = @workflow_run.token
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@
= link_to('Your Profile', user_path(User.session!))
%li.breadcrumb-item
= link_to 'Tokens', tokens_path
%li.breadcrumb-item.active
Workflow Runs
- if params[:id]
%li.breadcrumb-item
= link_to('Workflow Runs', token_workflow_runs_path(@token.id), title: 'Workflow Runs')
%li.breadcrumb-item.active
= params[:id]
- else
%li.breadcrumb-item.active
Workflow Runs
11 changes: 2 additions & 9 deletions src/api/app/views/webui/workflow_runs/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,9 @@
.text-center
%span.ml-3= page_entries_info(@workflow_runs)
.accordion.pt-3#workflow-runs-accordion
.card
- @workflow_runs.each do |workflow_run|
.card-header{ id: "workflow-run-heading#{workflow_run.id}" }
.mb-0
%button.btn.btn-block{ type: 'button', data: { toggle: 'collapse', target: "#workflow-run#{workflow_run.id}" },
aria: { expanded: 'false', controls: "workflow-run#{workflow_run.id}" } }
.row
= render(WorkflowRunRowComponent.new(workflow_run: workflow_run))
.collapse{ id: "workflow-run#{workflow_run.id}", aria: { labelledby: "#workflow-run-heading#{workflow_run.id}" },
data: { parent: '#workflow-runs-accordion' } }
.card-body
= render(WorkflowRunDetailComponent.new(workflow_run: workflow_run))
.row
= render(WorkflowRunRowComponent.new(workflow_run: workflow_run))
= paginate @workflow_runs, views_prefix: 'webui'
5 changes: 5 additions & 0 deletions src/api/app/views/webui/workflow_runs/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- @pagetitle = "Workflow Run #{@workflow_run.id}"
.card
.card-body
= render(WorkflowRunHeaderComponent.new(workflow_run: @workflow_run))
= render(WorkflowRunDetailComponent.new(workflow_run: @workflow_run))
2 changes: 1 addition & 1 deletion src/api/config/routes/webui_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@
post 'status_messages/:id' => :acknowledge, controller: 'webui/status_messages', as: :acknowledge_status_message

resources :tokens, controller: 'webui/users/tokens' do
resources :workflow_runs, only: [:index], controller: 'webui/workflow_runs'
resources :workflow_runs, only: [:index, :show], controller: 'webui/workflow_runs'
end
resources :token_triggers, only: [:show, :update], controller: 'webui/users/token_triggers'
end
Expand Down
Loading

0 comments on commit 3e0d023

Please sign in to comment.