Skip to content

Commit

Permalink
Show meaningful data for each workflow run
Browse files Browse the repository at this point in the history
Instead of rendering the workflow run id, show what triggered the
workflow run as an Event (and action if applicable) and from where, as a
link to the source (be it a PR or a commit, and the project).
  • Loading branch information
danidoni committed Jan 17, 2022
1 parent 6051adf commit 7a406f0
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
49 changes: 49 additions & 0 deletions src/api/app/models/workflow_run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,55 @@ class WorkflowRun < ApplicationRecord
def update_to_fail(message)
update(response_body: message, status: 'fail')
end

def payload
@payload ||= JSON.parse(request_payload)
end

def hook_action
payload['action']
end

def parsed_request_headers
request_headers.split("\n").each_with_object({}) do |h, headers|
k, v = h.split(':')
headers[k] = v.strip
end
end

def hook_event
parsed_request_headers['HTTP_X_GITHUB_EVENT']
end

def repository_name
payload['repository']['full_name']
end

def repository_url
payload['repository']['html_url']
end

def hook_source_name
case hook_event
when 'pull_request'
"##{payload['pull_request']['number']}"
when 'push'
"#{payload.dig('head_commit', 'id')}"
else
payload['repository']['full_name']
end
end

def hook_source_url
case hook_event
when 'pull_request'
payload['pull_request']['url']
when 'push'
payload.dig('head_commit', 'url')
else
payload['repository']['html_url']
end
end
end

# == Schema Information
Expand Down
9 changes: 8 additions & 1 deletion src/api/app/views/webui/workflow_runs/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@
- else
%i.fas.fa-exclamation-triangle.text-danger{ title: 'Status: failed' }
.col.text-left
Workflow Run #{workflow_run.id}
= workflow_run.hook_event.humanize
Event
- if workflow_run.hook_action
%span.badge.badge-primary= workflow_run.hook_action.humanize
.col.text-left
= link_to workflow_run.repository_name, workflow_run.repository_url
- if workflow_run.hook_source_name
= link_to workflow_run.hook_source_name, workflow_run.hook_source_url, { class: 'link-secondary' }
.col.text-right
= workflow_run.created_at
.collapse{ id: "workflow-run#{workflow_run.id}", aria: { labelledby: "#workflow-run-heading#{workflow_run.id}" },
Expand Down

0 comments on commit 7a406f0

Please sign in to comment.