@@ -4,8 +4,8 @@ defmodule Algora.Bounties.Jobs.NotifyBounty do
4
4
queue: :notify_bounty ,
5
5
max_attempts: 1
6
6
7
- alias Algora.Accounts
8
7
alias Algora.Accounts.User
8
+ alias Algora.Bounties
9
9
alias Algora.Github
10
10
alias Algora.Repo
11
11
alias Algora.Util
@@ -58,22 +58,24 @@ defmodule Algora.Bounties.Jobs.NotifyBounty do
58
58
@ impl Oban.Worker
59
59
def perform ( % Oban.Job {
60
60
args: % {
61
- "amount" => amount ,
61
+ "amount" => _amount ,
62
62
"ticket_ref" => ticket_ref ,
63
63
"installation_id" => installation_id ,
64
64
"command_id" => command_id ,
65
65
"command_source" => command_source
66
66
}
67
67
} ) do
68
68
with { :ok , token } <- Github . get_installation_token ( installation_id ) ,
69
- { :ok , installation } <-
70
- Workspace . fetch_installation_by ( provider: "github" , provider_id: to_string ( installation_id ) ) ,
71
- { :ok , owner } <- Accounts . fetch_user_by ( id: installation . connected_user_id ) ,
72
- { :ok , _ } <-
73
- Github . add_labels ( token , ticket_ref [ "owner" ] , ticket_ref [ "repo" ] , ticket_ref [ "number" ] , [ "💎 Bounty" ] ) ,
74
- { :ok , ticket } <- Workspace . ensure_ticket ( token , ticket_ref [ "owner" ] , ticket_ref [ "repo" ] , ticket_ref [ "number" ] ) do
69
+ { :ok , ticket } <- Workspace . ensure_ticket ( token , ticket_ref [ "owner" ] , ticket_ref [ "repo" ] , ticket_ref [ "number" ] ) ,
70
+ bounties when bounties != [ ] <- Bounties . list_bounties ( ticket_id: ticket . id ) ,
71
+ { :ok , _ } <- Github . add_labels ( token , ticket_ref [ "owner" ] , ticket_ref [ "repo" ] , ticket_ref [ "number" ] , [ "💎 Bounty" ] ) do
72
+ header =
73
+ Enum . map_join ( bounties , "\n " , fn bounty ->
74
+ "## 💎 #{ bounty . amount } bounty [• #{ bounty . owner . name } ](#{ User . url ( bounty . owner ) } )"
75
+ end )
76
+
75
77
body = """
76
- ## 💎 #{ amount } bounty [• #{ owner . name } ]( #{ User . url ( owner ) } )
78
+ #{ header }
77
79
### Steps to solve:
78
80
1. **Start working**: Comment `/attempt ##{ ticket_ref [ "number" ] } ` with your implementation plan
79
81
2. **Submit work**: Create a pull request including `/claim ##{ ticket_ref [ "number" ] } ` in the PR body to claim the bounty
@@ -96,16 +98,16 @@ defmodule Algora.Bounties.Jobs.NotifyBounty do
96
98
response . provider_response_id ,
97
99
body
98
100
) do
99
- { :ok , _comment } ->
100
- try_update_command_response ( response , body )
101
+ { :ok , comment } ->
102
+ try_update_command_response ( response , comment )
101
103
102
104
{ :error , "404 Not Found" } ->
103
105
with { :ok , _ } <- Workspace . delete_command_response ( response . id ) do
104
106
post_response ( token , ticket_ref , command_id , command_source , ticket , body )
105
107
end
106
108
107
109
{ :error , reason } ->
108
- Logger . error ( "Failed to update command response #{ response . id } with body #{ body } " )
110
+ Logger . error ( "Failed to update command response #{ response . id } : #{ inspect ( reason ) } " )
109
111
{ :error , reason }
110
112
end
111
113
@@ -142,8 +144,8 @@ defmodule Algora.Bounties.Jobs.NotifyBounty do
142
144
{ :ok , command_response } ->
143
145
{ :ok , command_response }
144
146
145
- { :error , _reason } ->
146
- Logger . error ( "Failed to update command response #{ command_response . id } " )
147
+ { :error , reason } ->
148
+ Logger . error ( "Failed to update command response #{ command_response . id } : #{ inspect ( reason ) } " )
147
149
{ :ok , command_response }
148
150
end
149
151
end
0 commit comments