Skip to content

Commit 91f854d

Browse files
committed
fix: handle issues.edited webhook to update ticket title and description
- Add handler for issues.edited events to update ticket metadata - Fix pull_request.edited to also update title (was only updating description) - Add comprehensive tests for both issue and PR metadata updates - Fixes issue where renaming a GitHub issue wouldn't update the bounty title This ensures that when users rename issues or PRs on GitHub, the corresponding tickets in Algora are updated with the new title and description.
1 parent 014299c commit 91f854d

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

lib/algora_web/controllers/webhooks/github_controller.ex

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ defmodule AlgoraWeb.Webhooks.GithubController do
274274
end
275275
end
276276

277+
defp process_event(%Webhook{event_action: "issues.edited"} = webhook, _commands),
278+
do: handle_ticket_metadata_change(webhook)
279+
277280
defp process_event(%Webhook{event_action: event_action, payload: payload}, commands)
278281
when event_action in ["pull_request.opened", "pull_request.reopened", "pull_request.edited"] do
279282
source =
@@ -285,7 +288,10 @@ defmodule AlgoraWeb.Webhooks.GithubController do
285288

286289
if source do
287290
source
288-
|> change(%{description: payload["pull_request"]["body"]})
291+
|> change(%{
292+
title: payload["pull_request"]["title"],
293+
description: payload["pull_request"]["body"]
294+
})
289295
|> Repo.update()
290296
end
291297

@@ -699,6 +705,30 @@ defmodule AlgoraWeb.Webhooks.GithubController do
699705
end
700706
end
701707

708+
defp handle_ticket_metadata_change(%Webhook{payload: payload} = webhook) do
709+
github_ticket = get_github_ticket(webhook)
710+
711+
case Workspace.get_ticket(
712+
payload["repository"]["owner"]["login"],
713+
payload["repository"]["name"],
714+
github_ticket["number"]
715+
) do
716+
nil ->
717+
:ok
718+
719+
ticket ->
720+
case ticket
721+
|> change(%{
722+
title: github_ticket["title"],
723+
description: github_ticket["body"]
724+
})
725+
|> Repo.update() do
726+
{:ok, _} -> :ok
727+
{:error, reason} -> {:error, reason}
728+
end
729+
end
730+
end
731+
702732
defp alert(%Webhook{event_action: event_action} = webhook, {:error, error}) do
703733
message =
704734
case get_github_ticket(webhook) do

test/algora_web/controllers/webhooks/github_controller_test.exs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,53 @@ defmodule AlgoraWeb.Webhooks.GithubControllerTest do
256256
# This test should now PASS with the fix - visibility is preserved
257257
assert final_bounty.visibility == original_visibility
258258
end
259+
260+
test "updates ticket title and description on issues.edited", ctx do
261+
issue_number = :rand.uniform(1000)
262+
updated_title = "Updated Issue Title"
263+
updated_body = "Updated issue description"
264+
265+
# First create the issue (title will be set by GitHub mock to "title #{number}")
266+
process_scenario!(ctx, [
267+
%{
268+
event_action: "issues.opened",
269+
user_type: :repo_admin,
270+
body: "/bounty $100",
271+
params: %{
272+
"issue" => %{
273+
"number" => issue_number,
274+
"state" => "open"
275+
}
276+
}
277+
}
278+
])
279+
280+
ticket = Repo.get_by!(Ticket, number: issue_number)
281+
# This comes from GitHub mock
282+
assert ticket.title == "title #{issue_number}"
283+
# This comes from GitHub mock
284+
assert ticket.description == "body #{issue_number}"
285+
286+
# Now edit the issue title and description
287+
process_scenario!(ctx, [
288+
%{
289+
event_action: "issues.edited",
290+
user_type: :repo_admin,
291+
params: %{
292+
"issue" => %{
293+
"number" => issue_number,
294+
"state" => "open",
295+
"title" => updated_title,
296+
"body" => updated_body
297+
}
298+
}
299+
}
300+
])
301+
302+
ticket = Repo.get_by!(Ticket, number: issue_number)
303+
assert ticket.title == updated_title
304+
assert ticket.description == updated_body
305+
end
259306
end
260307

261308
describe "create tips" do
@@ -1578,6 +1625,7 @@ defmodule AlgoraWeb.Webhooks.GithubControllerTest do
15781625
"id" => 123,
15791626
"number" => 123,
15801627
"state" => "open",
1628+
"title" => "Default Issue Title",
15811629
"body" => mock_body(ctx[:body]),
15821630
"user" => mock_user(ctx[:author])
15831631
}
@@ -1597,6 +1645,7 @@ defmodule AlgoraWeb.Webhooks.GithubControllerTest do
15971645
"id" => 123,
15981646
"number" => 123,
15991647
"state" => "open",
1648+
"title" => "Default PR Title",
16001649
"body" => mock_body(ctx[:body]),
16011650
"user" => mock_user(ctx[:author]),
16021651
"merged_at" => nil

0 commit comments

Comments
 (0)