Skip to content

Commit 66c8cf6

Browse files
committed
Show workflow run repository link only when necessary
1 parent 827c28f commit 66c8cf6

5 files changed

Lines changed: 24 additions & 4 deletions

File tree

src/api/app/components/workflow_run_row_component.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
- if hook_action
66
%span.ms-2.badge.text-bg-primary= hook_action.humanize
77
.col.text-start
8-
= link_to_if repository_url, repository_name, repository_url
8+
= link_to_if repository_url && not_unique_repository, repository_name, repository_url
99
- if event_source_name
1010
- popover_content = render partial: 'webui/workflow_runs/event_links', locals: { hook_event: hook_event,
1111
formatted_event_source_name: formatted_event_source_name,

src/api/app/components/workflow_run_row_component.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class WorkflowRunRowComponent < ApplicationComponent
2-
attr_reader :workflow_run, :status, :hook_event, :hook_action, :repository_name, :repository_url, :event_source_name, :event_source_url, :formatted_event_source_name, :token_id
2+
attr_reader :workflow_run, :status, :hook_event, :hook_action, :repository_name, :repository_url, :event_source_name, :event_source_url, :formatted_event_source_name, :token_id, :not_unique_repository
33

4-
def initialize(workflow_run:, token_id:)
4+
def initialize(workflow_run:, token_id:, not_unique_repository: false)
55
super
66

77
@workflow_run = workflow_run
@@ -14,6 +14,7 @@ def initialize(workflow_run:, token_id:)
1414
@event_source_url = workflow_run.event_source_url
1515
@formatted_event_source_name = workflow_run.formatted_event_source_name
1616
@token_id = token_id
17+
@not_unique_repository = not_unique_repository
1718
end
1819

1920
def status_title

src/api/app/models/token/workflow.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ def members
6969
[users, groups&.map(&:users)&.flatten].flatten.compact.uniq
7070
end
7171

72+
def unique_repositories
73+
# A fast way to retrieve all the possible options, without the ids
74+
unique_no_id = workflow_runs.where.not(response_url: nil).select(:repository_name, :repository_owner, :response_url).distinct
75+
# Now we retrieve a unique record for every option
76+
unique_no_id.map { |i| workflow_runs.find_by(i.slice(:repository_name, :repository_owner, :response_url)) }
77+
end
78+
7279
private
7380

7481
def validation_errors

src/api/app/views/webui/users/tokens/show.html.haml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@
4646
= link_to(@token.executor.login, user_path(@token.executor))
4747

4848
- if @token.type == 'Token::Workflow'
49+
.row
50+
.col
51+
.mb-3
52+
%label.fw-bold
53+
Workflow Repositories:
54+
%ul
55+
- @token.unique_repositories.each do |unique_repository|
56+
%li
57+
= link_to unique_repository.repository_full_name, unique_repository.repository_url
58+
4959
.row
5060
.col
5161
.mb-3

src/api/app/views/webui/workflow_runs/index.html.haml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
.text-center
2323
%span.ms-3= page_entries_info(@workflow_runs)
2424
.pt-3#workflow-runs
25+
- not_unique_repository = Token::Workflow.find(@token.id).unique_repositories.count != 1
2526
- @workflow_runs.each do |workflow_run|
2627
.border-bottom.py-2{ id: "workflow-run-heading#{workflow_run.id}" }
2728
.mb-0
2829
.row
29-
= render(WorkflowRunRowComponent.new(workflow_run: workflow_run, token_id: @token.id))
30+
= render(WorkflowRunRowComponent.new(workflow_run: workflow_run, token_id: @token.id,
31+
not_unique_repository: not_unique_repository))
3032
= paginate @workflow_runs, views_prefix: 'webui'

0 commit comments

Comments
 (0)