This commit is contained in:
2026-08-06 19:23:04 +02:00
parent d05ed3c515
commit 161f923dc8
7 changed files with 87 additions and 107 deletions
+20 -1
View File
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.1].define(version: 2026_08_05_000003) do
ActiveRecord::Schema[8.1].define(version: 2026_08_06_000001) do
create_table "application_tokens", id: { type: :bigint, unsigned: true }, charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.datetime "created_at", precision: 3
t.datetime "deleted_at", precision: 3
@@ -29,6 +29,24 @@ ActiveRecord::Schema[8.1].define(version: 2026_08_05_000003) do
t.index ["token_digest"], name: "idx_application_tokens_token_digest", unique: true
end
create_table "ci_repositories", id: { type: :bigint, unsigned: true }, charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.boolean "active", default: true, null: false
t.datetime "created_at", precision: 3
t.datetime "deleted_at", precision: 3
t.datetime "last_pipeline_at", precision: 3
t.string "last_pipeline_status", limit: 32
t.string "platform", limit: 32, null: false
t.string "repo_name", limit: 128, null: false
t.string "repo_owner", limit: 128, null: false
t.bigint "software_id", unsigned: true
t.datetime "updated_at", precision: 3
t.bigint "woodpecker_repo_id", null: false, unsigned: true
t.index ["deleted_at"], name: "idx_ci_repos_deleted"
t.index ["repo_owner", "repo_name"], name: "idx_ci_repos_owner_name", unique: true
t.index ["software_id"], name: "idx_ci_repos_software"
t.index ["woodpecker_repo_id"], name: "idx_ci_repos_wp_id", unique: true
end
create_table "downloads", id: { type: :bigint, unsigned: true }, charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.datetime "created_at", precision: 3
t.datetime "deleted_at", precision: 3
@@ -137,6 +155,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_08_05_000003) do
t.datetime "updated_at", precision: 3
end
add_foreign_key "ci_repositories", "softwares", name: "fk_ci_repos_software", on_delete: :nullify
add_foreign_key "downloads", "releases", name: "fk_downloads_release", on_delete: :nullify
add_foreign_key "external_links", "softwares", name: "fk_softwares_external_links", on_delete: :cascade
add_foreign_key "release_assets", "releases", name: "fk_releases_release_assets", on_delete: :cascade
+30 -28
View File
@@ -4,31 +4,6 @@ RSpec.describe WarpEngine::CiPipelineService do
let(:client) { instance_double(WarpEngine::WoodpeckerClient) }
let(:service) { described_class.new(client: client) }
describe "#dashboard" 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(repo.woodpecker_repo_id).and_return(pipeline)
entries = service.dashboard
expect(entries.size).to eq(1)
expect(entries.first[:pipeline]["status"]).to eq("success")
expect(repo.reload.last_pipeline_status).to eq("success")
end
it "handles API errors gracefully per repo" do
create(:ci_repository, repo_owner: "org", repo_name: "broken")
allow(client).to receive(:latest_pipeline)
.and_raise(WarpEngine::WoodpeckerClient::ApiError.new("fail", status: 500))
entries = service.dashboard
expect(entries.size).to eq(1)
expect(entries.first[:pipeline]).to be_nil
end
end
describe "#trigger" do
it "delegates to client" do
repo = build(:ci_repository, repo_owner: "org", repo_name: "game")
@@ -42,12 +17,39 @@ RSpec.describe WarpEngine::CiPipelineService do
end
describe "#list_pipelines" do
it "returns paginated pipelines" do
repo = build(:ci_repository, repo_owner: "org", repo_name: "game")
pipelines = [{ "number" => 1 }, { "number" => 2 }]
it "returns paginated pipelines and refreshes the repo's cached last pipeline" do
repo = create(:ci_repository, repo_owner: "org", repo_name: "game")
pipelines = [
{ "number" => 2, "status" => "failure", "created" => 1_754_500_000 },
{ "number" => 1, "status" => "success", "created" => 1_754_400_000 }
]
allow(client).to receive(:list_pipelines).with(repo.woodpecker_repo_id, page: 1).and_return(pipelines)
expect(service.list_pipelines(repo)).to eq(pipelines)
repo.reload
expect(repo.last_pipeline_status).to eq("failure")
expect(repo.last_pipeline_at).to eq(Time.zone.at(1_754_500_000))
end
it "does not touch the cache on later pages" do
repo = create(:ci_repository, repo_owner: "org", repo_name: "game",
last_pipeline_status: "success")
allow(client).to receive(:list_pipelines).with(repo.woodpecker_repo_id, page: 2)
.and_return([{ "number" => 1, "status" => "failure", "created" => 1_754_400_000 }])
service.list_pipelines(repo, page: 2)
expect(repo.reload.last_pipeline_status).to eq("success")
end
it "leaves the cache alone when the repo has no pipelines" do
repo = create(:ci_repository, repo_owner: "org", repo_name: "game",
last_pipeline_status: "success")
allow(client).to receive(:list_pipelines).and_return([])
expect(service.list_pipelines(repo)).to eq([])
expect(repo.reload.last_pipeline_status).to eq("success")
end
end
end