pipeline fix

This commit is contained in:
2026-08-06 16:04:50 +02:00
parent 731b267aa1
commit bae6fc06a6
4 changed files with 39 additions and 22 deletions
@@ -7,7 +7,7 @@ module WarpEngine
def dashboard
CiRepository.active.includes(:software).map do |repo|
pipeline = begin
@client.latest_pipeline(repo.repo_owner, repo.repo_name)
@client.latest_pipeline(repo.woodpecker_repo_id)
rescue WoodpeckerClient::ApiError
nil
end
@@ -24,15 +24,15 @@ module WarpEngine
end
def trigger(repo, branch: "main")
@client.trigger_pipeline(repo.repo_owner, repo.repo_name, branch: branch)
@client.trigger_pipeline(repo.woodpecker_repo_id, branch: branch)
end
def list_pipelines(repo, page: 1)
@client.list_pipelines(repo.repo_owner, repo.repo_name, page: page)
@client.list_pipelines(repo.woodpecker_repo_id, page: page)
end
def pipeline_detail(repo, number)
@client.get_pipeline(repo.repo_owner, repo.repo_name, number)
@client.get_pipeline(repo.woodpecker_repo_id, number)
end
end
end
@@ -61,21 +61,21 @@ module WarpEngine
# --- Pipelines ---
def list_pipelines(owner, repo_name, page: 1, per_page: 25)
get("/api/repos/#{owner}/#{repo_name}/pipelines",
def list_pipelines(repo_id, page: 1, per_page: 25)
get("/api/repos/#{repo_id}/pipelines",
params: { page: page, perPage: per_page })
end
def latest_pipeline(owner, repo_name)
get("/api/repos/#{owner}/#{repo_name}/pipelines/latest")
def latest_pipeline(repo_id)
get("/api/repos/#{repo_id}/pipelines/latest")
end
def get_pipeline(owner, repo_name, number)
get("/api/repos/#{owner}/#{repo_name}/pipelines/#{number}")
def get_pipeline(repo_id, number)
get("/api/repos/#{repo_id}/pipelines/#{number}")
end
def trigger_pipeline(owner, repo_name, branch: "main")
post("/api/repos/#{owner}/#{repo_name}/pipelines",
def trigger_pipeline(repo_id, branch: "main")
post("/api/repos/#{repo_id}/pipelines",
body: { branch: branch })
end
@@ -136,7 +136,16 @@ module WarpEngine
case response
when Net::HTTPSuccess, Net::HTTPNoContent
return nil if response.body.blank?
JSON.parse(response.body)
begin
JSON.parse(response.body)
rescue JSON::ParserError
# A wrong path falls through to the Woodpecker SPA, which answers
# 200 with index.html — surface that as an API error, not a parse one.
raise ApiError.new(
"Expected JSON from #{uri.path} but got: #{response.body.truncate(80)}",
status: response.code.to_i, body: response.body
)
end
when Net::HTTPNotFound
raise ApiError.new("Not found: #{uri.path}", status: 404, body: response.body)
else
@@ -8,7 +8,7 @@ RSpec.describe WarpEngine::CiPipelineService do
it "returns latest pipeline for each active repo" do
repo = create(:ci_repository, repo_owner: "org", repo_name: "game")
pipeline = { "number" => 5, "status" => "success", "created_at" => "2026-08-06T12:00:00Z" }
allow(client).to receive(:latest_pipeline).with("org", "game").and_return(pipeline)
allow(client).to receive(:latest_pipeline).with(repo.woodpecker_repo_id).and_return(pipeline)
entries = service.dashboard
@@ -37,7 +37,7 @@ RSpec.describe WarpEngine::CiPipelineService do
result = service.trigger(repo, branch: "main")
expect(result["number"]).to eq(6)
expect(client).to have_received(:trigger_pipeline).with("org", "game", branch: "main")
expect(client).to have_received(:trigger_pipeline).with(repo.woodpecker_repo_id, branch: "main")
end
end
@@ -45,7 +45,7 @@ RSpec.describe WarpEngine::CiPipelineService do
it "returns paginated pipelines" do
repo = build(:ci_repository, repo_owner: "org", repo_name: "game")
pipelines = [{ "number" => 1 }, { "number" => 2 }]
allow(client).to receive(:list_pipelines).with("org", "game", page: 1).and_return(pipelines)
allow(client).to receive(:list_pipelines).with(repo.woodpecker_repo_id, page: 1).and_return(pipelines)
expect(service.list_pipelines(repo)).to eq(pipelines)
end
@@ -67,23 +67,23 @@ RSpec.describe WarpEngine::WoodpeckerClient do
describe "pipelines" do
it "lists pipelines" do
pipelines = [{ "number" => 1, "status" => "success" }]
stub_wp(:get, "/api/repos/org/game/pipelines?page=1&perPage=25", body: pipelines)
stub_wp(:get, "/api/repos/42/pipelines?page=1&perPage=25", body: pipelines)
expect(client.list_pipelines("org", "game")).to eq(pipelines)
expect(client.list_pipelines(42)).to eq(pipelines)
end
it "gets latest pipeline" do
pipeline = { "number" => 5, "status" => "running" }
stub_wp(:get, "/api/repos/org/game/pipelines/latest", body: pipeline)
stub_wp(:get, "/api/repos/42/pipelines/latest", body: pipeline)
expect(client.latest_pipeline("org", "game")).to eq(pipeline)
expect(client.latest_pipeline(42)).to eq(pipeline)
end
it "triggers a pipeline" do
pipeline = { "number" => 6, "status" => "pending" }
stub_wp(:post, "/api/repos/org/game/pipelines", body: pipeline)
stub_wp(:post, "/api/repos/42/pipelines", body: pipeline)
expect(client.trigger_pipeline("org", "game", branch: "main")).to eq(pipeline)
expect(client.trigger_pipeline(42, branch: "main")).to eq(pipeline)
end
end
@@ -115,5 +115,13 @@ RSpec.describe WarpEngine::WoodpeckerClient do
expect { client.list_repos }.to raise_error(WarpEngine::WoodpeckerClient::ConnectionError)
end
it "raises ApiError when a 200 response is not JSON" do
stub_request(:get, "#{base_url}/api/repos")
.to_return(status: 200, body: "<!doctype html><html></html>",
headers: { "Content-Type" => "text/html" })
expect { client.list_repos }.to raise_error(WarpEngine::WoodpeckerClient::ApiError, /Expected JSON/)
end
end
end