Skip to content

Commit f083f93

Browse files
committed
Show profile badges publicly
1 parent b5b0208 commit f083f93

7 files changed

Lines changed: 39 additions & 29 deletions

File tree

app/views/profiles/organization_repository.erb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,15 @@
3838
record: @organization_repository,
3939
heading_id: 'organization-repository-star-history-heading'
4040
} %>
41+
42+
<% if @organization_repository[:polish_repo_badge] && @organization_repository[:polish_repo_badge][:value] %>
43+
<section class="profile-section profile-section--alt" aria-labelledby="organization-repository-badge-heading">
44+
<div class="content">
45+
<h2 id="organization-repository-badge-heading"><%= h t('repositories.badge.title') %></h2>
46+
<%= erb :"profiles/inline_badge_preview", locals: {
47+
badge_path: repository_badge_path(@organization_repository),
48+
alt_text: t('repositories.badge.alt')
49+
} %>
50+
</div>
51+
</section>
52+
<% end %>

app/views/profiles/repository.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
{ label: t('rankings.metric.stars'), value: "⭐ #{number(@repository[:stargazers_count])}" },
2323
{ label: t('rankings.metric.new_stars'), value: "⭐ #{number(@repository[:monthly_stars_delta])}" }
2424
] %>
25-
<% if @show_repository_badge && @repository[:polish_repo_badge] && @repository[:polish_repo_badge][:value] %>
25+
<% if @repository[:polish_repo_badge] && @repository[:polish_repo_badge][:value] %>
2626
<% metric_items << { label: @repository[:polish_repo_badge].fetch(:label), value: @repository[:polish_repo_badge].fetch(:value) } %>
2727
<% end %>
2828
<%= erb :"profiles/metric_card", locals: {
@@ -36,7 +36,7 @@
3636

3737
<%= erb :"profiles/star_history", locals: { record: @repository, heading_id: 'repository-star-history-heading' } %>
3838

39-
<% if @show_repository_badge && @repository[:polish_repo_badge] && @repository[:polish_repo_badge][:value] %>
39+
<% if @repository[:polish_repo_badge] && @repository[:polish_repo_badge][:value] %>
4040
<section class="profile-section profile-section--alt" aria-labelledby="repository-badge-heading">
4141
<div class="content">
4242
<h2 id="repository-badge-heading"><%= h t('repositories.badge.title') %></h2>

app/views/profiles/user.erb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
top_repository_path: top_repository ? repository_profile_path(top_repository) : nil
2626
} %>
2727

28-
<% profile_badge_visible = @show_profile_badges && @profile.fetch(:badges, []).any? %>
28+
<% profile_badge_visible = @profile.fetch(:badges, []).any? %>
2929
<% if @discord_panel %>
3030
<section class="profile-section" aria-label="<%= h t('users.profile_access.title') %>">
3131
<div class="content profile-discord-panel">
@@ -58,10 +58,8 @@
5858
<% metric_items = [] %>
5959
<% metric_items << { label: t('rankings.metric.stars'), value: "⭐ #{number(@profile[:total_stars])}" } unless @profile[:total_stars].nil? %>
6060
<% metric_items << { label: t('rankings.metric.new_stars'), value: "⭐ #{number(@profile[:monthly_stars_delta])}" } unless @profile[:monthly_stars_delta].nil? %>
61-
<% if @show_profile_badges %>
62-
<% @profile.fetch(:badges, []).each do |badge| %>
63-
<% metric_items << { label: badge.fetch(:label), value: (badge[:value] || t('users.metrics.outside_ranking')) } %>
64-
<% end %>
61+
<% @profile.fetch(:badges, []).each do |badge| %>
62+
<% metric_items << { label: badge.fetch(:label), value: (badge[:value] || t('users.metrics.outside_ranking')) } %>
6563
<% end %>
6664
<%= erb :"profiles/metric_card", locals: {
6765
title: t('users.metrics.title'),
@@ -79,7 +77,7 @@
7977
repositories: @repositories,
8078
empty_translation_key: 'users.repositories.empty',
8179
path_builder: method(:repository_profile_path),
82-
badge_path_builder: (@show_profile_badges ? method(:repository_badge_path) : nil),
80+
badge_path_builder: method(:repository_badge_path),
8381
badge_alt_text: t('repositories.badge.alt'),
8482
show_homepage: true
8583
} %>

lib/polish_open_source_rank/web/controllers/public_controller.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ def render_repository_profile(platform, owner, name)
6363
period_start: @period)
6464
halt 404 unless @repository
6565
repository_profile_cache!(@repository)
66-
assign_public_page(
67-
public_page_state.repository_profile(repository: @repository, own_repository: own_repository?(@repository))
68-
)
66+
assign_public_page(public_page_state.repository_profile(repository: @repository))
6967
erb :'profiles/repository'
7068
end
7169

lib/polish_open_source_rank/web/presentation/public_page_state.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,17 @@ def user_profile(profile:, own_profile:)
4747
canonical_path: call_view(:user_profile_path, profile),
4848
discord_panel: private_controls ? call_view(:show_discord_panel_for, profile) : nil,
4949
discord_error: private_controls ? view_context.session.delete(:discord_error) : nil,
50-
show_profile_badges: private_controls,
5150
show_profile_delete_control: private_controls
5251
}
5352
end
5453

55-
def repository_profile(repository:, own_repository:)
54+
def repository_profile(repository:)
5655
source_name = call_view(:platform_name, repository.fetch(:platform))
5756

5857
{
5958
title: repository_profile_seo_title(repository, source_name),
6059
description: repository_profile_seo_description(repository, source_name),
61-
canonical_path: call_view(:repository_profile_path, repository),
62-
show_repository_badge: own_repository
60+
canonical_path: call_view(:repository_profile_path, repository)
6361
}
6462
end
6563

spec/polish_open_source_rank/web/app_spec.rb

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ def user(_access_token)
340340
expect(organization_repository.body).to include('"@type": "SoftwareSourceCode"')
341341
expect(organization_repository.body).to include('id="organization-repository-star-history-heading"')
342342
expect(organization_repository.body).to include('>Historia gwiazdek</h2>')
343+
expect(organization_repository.body).to include(
344+
'<h2 id="organization-repository-badge-heading">Odznaka</h2>'
345+
)
346+
expect(organization_repository.body).to include('/badges/repositories/github/polish-org/toolkit.svg')
347+
expect(organization_repository.body).to include('class="badge-markdown__copy js-copy-badge-markdown"')
343348
expect(organization_repository.body).to include('href="https://www.star-history.com/polish-org/toolkit"')
344349
expect(organization_repository.body).to include(
345350
'src="https://api.star-history.com/chart?repos=polish-org%2Ftoolkit&amp;type=date&amp;legend=top-left"'
@@ -2098,10 +2103,14 @@ def expect_user_profile_page(ranking_response:, profile_response:, badge_respons
20982103
'#1',
20992104
'Najlepsze projekty',
21002105
'alice/app',
2101-
'12 345'
2106+
'12 345',
2107+
'<h2 id="profile-badge-heading">Odznaka</h2>',
2108+
'/badges/users/github/alice.svg',
2109+
'/badges/repositories/github/alice/app.svg',
2110+
'class="badge-markdown__copy js-copy-badge-markdown"'
21022111
)
21032112
expect(profile_response.body).not_to include('class="ranking-action"')
2104-
expect(profile_response.body).not_to include('/badges/users/github/alice.svg')
2113+
expect(profile_response.body).not_to include('Twój dostęp Discord')
21052114
expect(badge_response.status).to eq(200)
21062115
expect(badge_response.content_type).to include('image/svg+xml')
21072116
expect_body_to_include(badge_response, 'Polish Open Source', '1st', 'href="https://rank.example/people"')
@@ -2199,12 +2208,11 @@ def expect_repository_profile_page(**responses)
21992208
'src="https://api.star-history.com/chart?repos=alice%2Fapp&amp;type=date&amp;legend=top-left"'
22002209
)
22012210
expect(profile_response.body).not_to include('Odznaka na GitHub')
2202-
expect(profile_response.body).not_to include('/badges/repositories/github/alice/app.svg')
2203-
expect(owner_profile_response.body).to include('<h2 id="repository-badge-heading">Odznaka</h2>')
2211+
expect(profile_response.body).to include('<h2 id="repository-badge-heading">Odznaka</h2>')
22042212
expect(owner_profile_response.body).not_to include('Odznaka na GitHub')
2205-
expect(owner_profile_response.body).to include('class="badge-markdown__copy js-copy-badge-markdown"')
2206-
expect(owner_profile_response.body).to include('/badges/repositories/github/alice/app.svg')
2207-
expect(owner_profile_response.body).to include(
2213+
expect(profile_response.body).to include('class="badge-markdown__copy js-copy-badge-markdown"')
2214+
expect(profile_response.body).to include('/badges/repositories/github/alice/app.svg')
2215+
expect(profile_response.body).to include(
22082216
'[![Badge Polish Repo](https://rank.example/badges/repositories/github/alice/app.svg)]'
22092217
)
22102218
expect(badge_response.status).to eq(200)

spec/polish_open_source_rank/web/presentation/public_page_state_spec.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ def path_with_optional_slug(path, resource)
262262
canonical_path: '/users/github/ciembor',
263263
discord_panel: :discord_panel,
264264
discord_error: 'Sync failed',
265-
show_profile_badges: true,
266265
show_profile_delete_control: true
267266
)
268267
expect(view_context.session).to be_empty
@@ -279,7 +278,6 @@ def path_with_optional_slug(path, resource)
279278
description: 'users.seo.description|location=Poznan, Poland|platform=GitHub|user=Maciej (ciembor)',
280279
discord_panel: nil,
281280
discord_error: nil,
282-
show_profile_badges: false,
283281
show_profile_delete_control: false
284282
)
285283
end
@@ -290,7 +288,6 @@ def path_with_optional_slug(path, resource)
290288
expect(state).to include(
291289
discord_panel: nil,
292290
discord_error: nil,
293-
show_profile_badges: false,
294291
show_profile_delete_control: false
295292
)
296293
end
@@ -309,8 +306,8 @@ def path_with_optional_slug(path, resource)
309306
}
310307
end
311308

312-
it 'builds repository page state and ownership flag' do
313-
state = page_state.repository_profile(repository: repository, own_repository: true)
309+
it 'builds repository page state' do
310+
state = page_state.repository_profile(repository: repository)
314311

315312
expect(state).to include(
316313
title: 'repositories.seo.title|language=Ruby|platform=GitHub|repository=polish-open-source-rank',
@@ -319,8 +316,7 @@ def path_with_optional_slug(path, resource)
319316
'repository=polish-open-source-rank|summary=repositories.seo.summary_language|' \
320317
'language=Ruby Ranking for Polish open source repositories. ' \
321318
'repositories.seo.summary_stars|stars=1234',
322-
canonical_path: '/repositories/github/ciembor/polish-open-source-rank',
323-
show_repository_badge: true
319+
canonical_path: '/repositories/github/ciembor/polish-open-source-rank'
324320
)
325321
end
326322
end

0 commit comments

Comments
 (0)