Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions notifications/lib/notifications/workers/coordinator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ defmodule Notifications.Workers.Coordinator do

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

tag_name = if hook.git_ref_type == :TAG, do: hook.tag_name, else: nil
branch_name = if hook.git_ref_type == :TAG, do: nil, else: pipeline.branch_name
pr_branch_name = if hook.git_ref_type == :TAG, do: "", else: hook.pr_branch_name
{tag_name, branch_name, pr_branch_name} = extract_references(pipeline, hook)

rules =
Filter.find_rules(
Expand Down Expand Up @@ -103,6 +101,15 @@ defmodule Notifications.Workers.Coordinator do
end
end

defp extract_references(pipeline, nil), do: extract_references_from_pipeline(pipeline)
defp extract_references(_pipeline, hook = %{git_ref_type: :TAG}), do: {hook.tag_name, nil, ""}
defp extract_references(pipeline, hook), do: {nil, pipeline.branch_name, hook.pr_branch_name}

defp extract_references_from_pipeline(%{branch_name: "refs/tags" <> tag_name}),
do: {tag_name, nil, ""}

defp extract_references_from_pipeline(%{branch_name: branch_name}), do: {nil, branch_name, ""}

defp map_result_to_string(enum), do: enum |> Atom.to_string() |> String.downcase()
end
end