Skip to content

Commit 7632ee7

Browse files
committed
refactor: add helper fn to format name list
1 parent 7b46e3d commit 7632ee7

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

lib/algora/bounties/jobs/notify_claim.ex

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,17 @@ defmodule Algora.Bounties.Jobs.NotifyClaim do
3434
defp add_comment(token, claims) do
3535
primary_claim = List.first(claims)
3636

37+
names =
38+
claims
39+
|> Enum.map(fn c -> c.user.provider_login end)
40+
|> Algora.Util.format_name_list()
41+
3742
Github.create_issue_comment(
3843
token,
3944
primary_claim.target.repository.user.provider_login,
4045
primary_claim.target.repository.name,
4146
primary_claim.target.number,
42-
"💡 #{names(claims)} submitted [#{Claim.type_label(primary_claim.type)}](#{primary_claim.url}) that claims the bounty. You can visit [Algora](#{Claim.reward_url(primary_claim)}) to reward."
47+
"💡 #{names} submitted [#{Claim.type_label(primary_claim.type)}](#{primary_claim.url}) that claims the bounty. You can visit [Algora](#{Claim.reward_url(primary_claim)}) to reward."
4348
)
4449
end
4550

@@ -58,20 +63,4 @@ defmodule Algora.Bounties.Jobs.NotifyClaim do
5863
{:ok, nil}
5964
end
6065
end
61-
62-
defp names([claim]) do
63-
"@#{claim.user.provider_login}"
64-
end
65-
66-
defp names([c1, c2]) do
67-
"@#{c1.user.provider_login} and @#{c2.user.provider_login}"
68-
end
69-
70-
defp names([c1, c2, c3]) do
71-
"@#{c1.user.provider_login}, @#{c2.user.provider_login} and @#{c3.user.provider_login}"
72-
end
73-
74-
defp names([c1, c2 | claims]) do
75-
"@#{c1.user.provider_login}, @#{c2.user.provider_login} and #{length(claims)} others"
76-
end
7766
end

lib/algora/shared/util.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ defmodule Algora.Util do
9696

9797
def normalize_struct(value), do: value
9898

99+
def format_name_list([x]), do: x
100+
def format_name_list([x1, x2]), do: "#{x1} and #{x2}"
101+
def format_name_list([x1, x2, x3]), do: "#{x1}, #{x2} and #{x3}"
102+
def format_name_list([x1, x2 | xs]), do: "#{x1}, #{x2} and #{length(xs)} others"
103+
99104
# TODO: Implement this for all countries
100105
def locale_from_country_code("gr"), do: "el"
101106
def locale_from_country_code(country_code), do: country_code

0 commit comments

Comments
 (0)