Skip to content

Commit 662d552

Browse files
fix(public-api/v1alpha): run_now allowed without branch and reference fields (#606)
## 📝 Description The previously expected behavior of the run_now action was that the branch parameter was optional. If not specified, it would default to the branch defined in the task. That behavior was broken in https://github.com/semaphoreio/semaphore/pull/599/files#diff-08b07813ddaf1b74e7b39d039b97e08c5190b4a6deaeece94c5653d2c786a8ec ## ✅ Checklist - [ ] I have tested this change - [ ] This change requires documentation update
1 parent 9480e60 commit 662d552

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

public-api/v1alpha/lib/pipelines_api/schedules/run_now.ex

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,9 @@ defmodule PipelinesAPI.Schedules.RunNow do
7171

7272
defp normalize_reference_params(params) do
7373
cond do
74-
# New reference format
7574
params["reference"] ->
7675
{:ok, params}
7776

78-
# Legacy branch format - convert to reference
7977
params["branch"] ->
8078
reference = %{
8179
"type" => "BRANCH",
@@ -89,9 +87,8 @@ defmodule PipelinesAPI.Schedules.RunNow do
8987

9088
{:ok, updated_params}
9189

92-
# No reference information provided
9390
true ->
94-
{:error, "Either 'reference' or 'branch' parameter is required"}
91+
{:ok, params}
9592
end
9693
end
9794

@@ -112,6 +109,8 @@ defmodule PipelinesAPI.Schedules.RunNow do
112109
end
113110
end
114111

112+
defp validate_reference_params(params), do: {:ok, params}
113+
115114
# Enhanced error handling
116115

117116
defp handle_run_now_response({:error, {:user, message}}) when is_binary(message) do

public-api/v1alpha/test/router/schedules/run_now_test.exs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ defmodule PipelinesAPI.Schedules.RunNow.Test do
149149
post_run_now(params, scheduler.id, 400, false)
150150
end
151151

152-
test "POST /schedules/:id/run_now - fails when both reference and branch are missing" do
152+
test "POST /schedules/:id/run_now - success when both reference and branch are missing" do
153153
org = Support.Stubs.Organization.create_default()
154154
user = Support.Stubs.User.create_default()
155155
project = Support.Stubs.Project.create(org, user)
@@ -159,8 +159,10 @@ defmodule PipelinesAPI.Schedules.RunNow.Test do
159159
"pipeline_file" => ".semaphore/semaphore.yml"
160160
}
161161

162-
assert "\"Either 'reference' or 'branch' parameter is required\"" =
163-
post_run_now(params, scheduler.id, 400, false)
162+
assert %{"workflow_id" => workflow_id} = post_run_now(params, scheduler.id, 200)
163+
assert {:ok, _} = UUID.info(workflow_id)
164+
165+
assert Support.Stubs.DB.find_all_by(:triggers, :periodic_id, scheduler.id) |> Enum.count() > 0
164166
end
165167

166168
test "POST /schedules/:id/run_now - fails with empty reference name" do

0 commit comments

Comments
 (0)