Skip to content

Commit b4414f8

Browse files
fix: notifications processing crash for task triggered pipelines (#601)
## 📝 Description For task runs there is no hook -> failed processing of pipeline finished message, this fixes the issue and takes if possible tag and pr names from hook, otherwise falls back to pipeline data. #### `logs` ``` INFO 2025-09-22T15:18:44.605829774Z [resource.labels.containerName: notifications] ** (UndefinedFunctionError) function nil.git_ref_type/0 is undefined INFO 2025-09-22T15:18:44.605831724Z [resource.labels.containerName: notifications] nil.git_ref_type() INFO 2025-09-22T15:18:44.605834104Z [resource.labels.containerName: notifications] (notifications 0.1.0) lib/notifications/workers/coordinator.ex:29: anonymous fn/1 in Notifications.Workers.Coordinator.PipelineFinished.handle_message/1 ``` this issue was present before #591 was merged also: ``` INFO 2025-09-22T12:33:05.523589599Z [resource.labels.containerName: notifications] ** (UndefinedFunctionError) function nil.pr_branch_name/0 is undefined INFO 2025-09-22T12:33:15.596608567Z [resource.labels.containerName: notifications] ** (UndefinedFunctionError) function nil.pr_branch_name/0 is undefined INFO 2025-09-22T12:33:25.758473405Z [resource.labels.containerName: notifications] ** (UndefinedFunctionError) function nil.pr_branch_name/0 is undefined ``` ## ✅ Checklist - [x] I have tested this change - [ ] This change requires documentation update
1 parent 3ba4770 commit b4414f8

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

notifications/lib/notifications/workers/coordinator.ex

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ defmodule Notifications.Workers.Coordinator do
2626

2727
Logger.info("#{request_id} #{event.pipeline_id} #{project.metadata.name}")
2828

29-
tag_name = if hook.git_ref_type == :TAG, do: hook.tag_name, else: nil
30-
branch_name = if hook.git_ref_type == :TAG, do: nil, else: pipeline.branch_name
31-
pr_branch_name = if hook.git_ref_type == :TAG, do: "", else: hook.pr_branch_name
29+
{tag_name, branch_name, pr_branch_name} = extract_references(pipeline, hook)
3230

3331
rules =
3432
Filter.find_rules(
@@ -103,6 +101,15 @@ defmodule Notifications.Workers.Coordinator do
103101
end
104102
end
105103

104+
defp extract_references(pipeline, nil), do: extract_references_from_pipeline(pipeline)
105+
defp extract_references(_pipeline, hook = %{git_ref_type: :TAG}), do: {hook.tag_name, nil, ""}
106+
defp extract_references(pipeline, hook), do: {nil, pipeline.branch_name, hook.pr_branch_name}
107+
108+
defp extract_references_from_pipeline(%{branch_name: "refs/tags" <> tag_name}),
109+
do: {tag_name, nil, ""}
110+
111+
defp extract_references_from_pipeline(%{branch_name: branch_name}), do: {nil, branch_name, ""}
112+
106113
defp map_result_to_string(enum), do: enum |> Atom.to_string() |> String.downcase()
107114
end
108115
end

0 commit comments

Comments
 (0)