Skip to content

Commit e0e1c3e

Browse files
committed
feat: add reward links to bounty solutions table
1 parent a41def0 commit e0e1c3e

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

β€Žlib/algora/bounties/bounties.exβ€Ž

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ defmodule Algora.Bounties do
144144
type: :claim,
145145
started_at: claim.inserted_at,
146146
user: claim.user,
147-
group_id: "claim-#{claim.group_id}",
147+
group_id: claim.group_id,
148+
solution_id: "claim-#{claim.group_id}",
148149
indicator: "🟒",
149150
solution: "##{claim.source.number}"
150151
}
@@ -155,7 +156,8 @@ defmodule Algora.Bounties do
155156
type: :attempt,
156157
started_at: attempt.inserted_at,
157158
user: attempt.user,
158-
group_id: "attempt-#{attempt.id}",
159+
group_id: attempt.id,
160+
solution_id: "attempt-#{attempt.id}",
159161
indicator: get_attempt_emoji(attempt),
160162
solution: "WIP"
161163
}
@@ -183,9 +185,9 @@ defmodule Algora.Bounties do
183185
solution = Enum.find(solutions, &(&1.type == :claim)) || List.first(solutions)
184186
%{solution | started_at: started_at}
185187
end)
186-
|> Enum.group_by(& &1.group_id)
187-
|> Enum.sort_by(fn {_group_id, solutions} -> Enum.min_by(solutions, & &1.started_at).started_at end)
188-
|> Enum.map(fn {_group_id, solutions} ->
188+
|> Enum.group_by(& &1.solution_id)
189+
|> Enum.sort_by(fn {_solution_id, solutions} -> Enum.min_by(solutions, & &1.started_at).started_at end)
190+
|> Enum.map(fn {_solution_id, solutions} ->
189191
primary_solution = Enum.min_by(solutions, & &1.started_at)
190192
timestamp = Calendar.strftime(primary_solution.started_at, "%b %d, %Y, %I:%M:%S %p")
191193

@@ -195,7 +197,14 @@ defmodule Algora.Bounties do
195197
|> Enum.map(&"@#{&1.user.provider_login}")
196198
|> Util.format_name_list()
197199

198-
"| #{primary_solution.indicator} #{users} | #{timestamp} | #{primary_solution.solution} |"
200+
actions =
201+
if primary_solution.type == :claim do
202+
"[Reward](#{AlgoraWeb.Endpoint.url()}/claims/#{primary_solution.group_id})"
203+
else
204+
""
205+
end
206+
207+
"| #{primary_solution.indicator} #{users} | #{timestamp} | #{primary_solution.solution} | #{actions} |"
199208
end)
200209

201210
solutions_table =
@@ -204,8 +213,8 @@ defmodule Algora.Bounties do
204213
else
205214
"""
206215
207-
| Attempt | Started (UTC) | Solution |
208-
| --- | --- | --- |
216+
| Attempt | Started (UTC) | Solution | Actions |
217+
| --- | --- | --- | --- |
209218
#{Enum.join(solutions, "\n")}
210219
"""
211220
end

β€Žtest/algora/bounties_test.exsβ€Ž

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -364,13 +364,15 @@ defmodule Algora.BountiesTest do
364364
user: solver1,
365365
target: ticket,
366366
source: insert!(:ticket, number: 101, repository: repository),
367-
inserted_at: ~U[2024-01-01 12:30:00Z]
367+
inserted_at: ~U[2024-01-01 12:30:00Z],
368+
group_id: "group-101"
368369
),
369370
insert!(:claim,
370371
user: solver2,
371372
target: ticket,
372373
source: insert!(:ticket, number: 102, repository: repository),
373-
inserted_at: ~U[2024-01-02 12:30:00Z]
374+
inserted_at: ~U[2024-01-02 12:30:00Z],
375+
group_id: "group-102"
374376
),
375377
insert!(:claim,
376378
user: solver5,
@@ -399,13 +401,13 @@ defmodule Algora.BountiesTest do
399401
400402
Thank you for contributing to repo_owner/test_repo!
401403
402-
| Attempt | Started (UTC) | Solution |
403-
| --- | --- | --- |
404-
| 🟒 @solver1 | Jan 01, 2024, 12:00:00 PM | #101 |
405-
| 🟒 @solver2 | Jan 02, 2024, 12:30:00 PM | #102 |
406-
| πŸ”΄ @solver3 | Jan 03, 2024, 12:00:00 PM | WIP |
407-
| 🟑 @solver4 | Jan 04, 2024, 12:00:00 PM | WIP |
408-
| 🟒 @solver5 and @solver6 | Jan 05, 2024, 12:00:00 PM | #105 |
404+
| Attempt | Started (UTC) | Solution | Actions |
405+
| --- | --- | --- | --- |
406+
| 🟒 @solver1 | Jan 01, 2024, 12:00:00 PM | #101 | [Reward](http://localhost:4002/claims/group-101) |
407+
| 🟒 @solver2 | Jan 02, 2024, 12:30:00 PM | #102 | [Reward](http://localhost:4002/claims/group-102) |
408+
| πŸ”΄ @solver3 | Jan 03, 2024, 12:00:00 PM | WIP | |
409+
| 🟑 @solver4 | Jan 04, 2024, 12:00:00 PM | WIP | |
410+
| 🟒 @solver5 and @solver6 | Jan 05, 2024, 12:00:00 PM | #105 | [Reward](http://localhost:4002/claims/group-105) |
409411
"""
410412

411413
assert response == String.trim(expected_response)

0 commit comments

Comments
Β (0)