class WarpEngine::PipelineSyncService
Mirrors the repositories of the CI adapter into WarpEngine::Pipeline records.
Public Class Methods
Source
# File app/services/warp_engine/pipeline_sync_service.rb, line 5 def initialize(ci: WarpEngine.ci) @ci = ci end
- ci
-
the
CIadapter, by defaultWarpEngine.ci
Public Instance Methods
Source
# File app/services/warp_engine/pipeline_sync_service.rb, line 50 def activate(repo_id) @ci.activate_repo(repo_id) sync_single(repo_id) end
Activates the CI repository repo_id and syncs its pipeline. Returns the saved WarpEngine::Pipeline.
Source
# File app/services/warp_engine/pipeline_sync_service.rb, line 57 def deactivate(repo_id) @ci.deactivate_repo(repo_id) record = Pipeline.kept.find_by!(woodpecker_repo_id: repo_id) record.update!(active: false) end
Deactivates the CI repository repo_id and marks its pipeline inactive. Raises ActiveRecord::RecordNotFound when no kept pipeline matches.
Source
# File app/services/warp_engine/pipeline_sync_service.rb, line 17 def sync_all remote_repos = @ci.repos results = { created: [], updated: [], deactivated: [] } remote_ids = remote_repos.map(&:id) remote_repos.each do |remote| record = Pipeline.find_or_initialize_by_remote_repo_id(remote.id) was_new = record.new_record? record.assign_attributes( repo_name: remote.name, repo_owner: remote.owner, active: remote.active?, deleted_at: nil ) assign_platform(record, remote.name) next unless record.save results[was_new ? :created : :updated] << record end Pipeline.kept.where.not(woodpecker_repo_id: remote_ids).find_each do |orphan| orphan.update!(active: false) if orphan.active? results[:deactivated] << orphan end results end
Creates or updates (and restores) a WarpEngine::Pipeline for every CI repository, linking it to the kept software of the same name and its platform when the pipeline has none yet, and deactivates the kept pipelines whose repository is gone.
Returns a Hash with the created, updated and deactivated pipelines; a pipeline that does not save is left out. Raises WarpEngine::CI::Error when the CI cannot be reached.