class WarpEngine::CI::Woodpecker::Adapter
The CI adapter for Woodpecker CI. It talks to the Woodpecker API through a CI::Woodpecker::Client, serves generated pipelines as a Woodpecker configuration extension (POST /build/config, httpsig-signed requests checked by CI::Woodpecker::SignatureVerifier) and renders them with CI::Woodpecker::PipelineConfig.
Constants
- SECRET_EVENTS
-
The pipeline events a secret created by
secret_setis available to.
Attributes
The Woodpecker server URL, the owner whose repositories the catalog builds, and the catalog URL the generated pipelines upload to (each nil when unset).
The Woodpecker server URL, the owner whose repositories the catalog builds, and the catalog URL the generated pipelines upload to (each nil when unset).
The Woodpecker server URL, the owner whose repositories the catalog builds, and the catalog URL the generated pipelines upload to (each nil when unset).
Public Class Methods
# File lib/warp_engine/ci/woodpecker/adapter.rb, line 29 def initialize(url: ENV["WOODPECKER_URL"], api_token: ENV["WOODPECKER_API_TOKEN"], repo_owner: ENV["WOODPECKER_REPO_OWNER"], public_key: nil, public_key_url: nil, platforms: {}, update_server: nil) @url = url.presence @api_token = api_token.presence @repo_owner = repo_owner.presence @public_key = public_key.presence @public_key_url = public_key_url.presence @update_server = update_server.presence @config = PipelineConfig.new(platforms: platforms || {}) end
Creates the adapter. Blank values count as unset.
- url
-
the
Woodpeckerserver URL (WOODPECKER_URL) - api_token
-
the
WoodpeckerAPI token (WOODPECKER_API_TOKEN) repo_owner-
the repository owner (
WOODPECKER_REPO_OWNER) - public_key
-
the PEM public key config requests are signed with
- public_key_url
-
the URL to fetch that public key from, when
public_keyis not given - platforms
-
the platforms to build, see
CI::PipelineConfig.new update_server-
the catalog URL the pipelines upload to
Public Instance Methods
Source
# File lib/warp_engine/ci/woodpecker/adapter.rb, line 75 def activate_repo(repo_id) client.activate_repo(repo_id) nil end
Enables CI for the repository repo_id on the server. Returns nil. Raises CI::ApiError.
Source
# File lib/warp_engine/ci/woodpecker/adapter.rb, line 56 def built_kinds(platform) = @config.built_kinds(platform)
Returns the release file kinds the pipeline of platform builds, or nil (see CI::PipelineConfig#built_kinds).
Source
# File lib/warp_engine/ci/woodpecker/adapter.rb, line 59 def client @client ||= Client.new(url: @url, token: @api_token) end
Returns the memoized CI::Woodpecker::Client for the configured URL and token.
Source
# File lib/warp_engine/ci/woodpecker/adapter.rb, line 144 def config_marker(params) configs = params[:configuration].presence || params[:configs].presence || [] configs = Array(configs) configs.each_with_index do |config, index| parsed = parse_marker(config[:data].to_s) next unless parsed marker = { platform: parsed["platform"].to_s, name: parsed["name"].presence || params.dig(:repo, :name).to_s } options = parsed.except("platform", "name") marker[:options] = options if options.any? others = configs.reject.with_index { |_, other| other == index } .map { |other| { name: other[:name].to_s, data: other[:data].to_s } } marker[:others] = others if others.any? return marker end nil end
Finds the marker among the repository’s configs in a config request.
- params
-
the request parameters:
configuration(orconfigs), an Array of Hashes with the config file’snameanddata, andrepowith itsname
Returns nil when no config is a YAML mapping with a platform key. Otherwise returns a Hash with platform, name (the marker’s, else the repository’s), options (the marker’s other keys, when any) and others (the remaining configs as name/data Hashes, when any).
# File lib/warp_engine/ci/woodpecker/adapter.rb, line 170 def config_response(platform:, config:, others: []) { configs: [ { name: platform, data: config } ] + others } end
Returns the body of the config response: the generated config named after platform, followed by the repository’s others configs unchanged.
Source
# File lib/warp_engine/ci/woodpecker/adapter.rb, line 49 def configured? = @url.present? && @api_token.present?
Returns true when both the server URL and the API token are set.
Source
# File lib/warp_engine/ci/woodpecker/adapter.rb, line 81 def deactivate_repo(repo_id) client.deactivate_repo(repo_id) nil end
Disables CI for the repository repo_id on the server. Returns nil. Raises CI::ApiError.
Source
# File lib/warp_engine/ci/woodpecker/adapter.rb, line 46 def name = "Woodpecker"
Returns the display name, "Woodpecker".
# File lib/warp_engine/ci/woodpecker/adapter.rb, line 164 def pipeline_config(platform:, name:, update_server:, options: {}) @config.render(platform: platform, name: name, update_server: update_server, options: options) end
Renders the pipeline of platform. Returns the YAML String or nil (see CI::PipelineConfig#render).
Source
# File lib/warp_engine/ci/woodpecker/adapter.rb, line 52 def platforms = @config.platforms
Returns the configured platforms (see CI::PipelineConfig#platforms).
Source
# File lib/warp_engine/ci/woodpecker/adapter.rb, line 70 def repo(repo_id) to_repo(client.get_repo(repo_id)) end
Returns the CI::Repo of repo_id (the Woodpecker repository id). Raises CI::ApiError when it is not found.
Source
# File lib/warp_engine/ci/woodpecker/adapter.rb, line 65 def repos Array(client.list_repos).map { |remote| to_repo(remote) } end
Returns every repository the API token can see, as an Array of CI::Repo. Raises CI::ConnectionError or CI::ApiError.
Source
# File lib/warp_engine/ci/woodpecker/adapter.rb, line 94 def run(repo_id, number) remote = if number.to_s == "latest" client.latest_pipeline(repo_id) else client.get_pipeline(repo_id, number) end remote && to_run(remote) end
Returns the CI::Run numbered number of repo_id, or the latest run when number is "latest"; nil when there is no latest run. Raises CI::ApiError when the run is not found.
Source
# File lib/warp_engine/ci/woodpecker/adapter.rb, line 87 def runs(repo_id, page: 1) Array(client.list_pipelines(repo_id, page: page)).map { |run| to_run(run) } end
Returns one page (25 runs, newest first) of the pipeline runs of repo_id as an Array of CI::Run.
# File lib/warp_engine/ci/woodpecker/adapter.rb, line 125 def secret_delete(repo_id, name) client.delete_secret(repo_id, name) nil end
Deletes the secret name of repo_id. Returns nil. Raises CI::ApiError when it does not exist.
Source
# File lib/warp_engine/ci/woodpecker/adapter.rb, line 109 def secret_names(repo_id) Array(client.list_secrets(repo_id)).map { |secret| secret["name"] } end
Returns the names of the secrets of repo_id as an Array of Strings.
# File lib/warp_engine/ci/woodpecker/adapter.rb, line 115 def secret_set(repo_id, name:, value:) if secret_names(repo_id).include?(name) client.update_secret(repo_id, name, value: value) else client.create_secret(repo_id, name: name, value: value, events: SECRET_EVENTS) end nil end
Creates or updates the secret name of repo_id with value. A new secret is available to the SECRET_EVENTS events. Returns nil.
# File lib/warp_engine/ci/woodpecker/adapter.rb, line 104 def trigger(repo_id, branch: "main") to_run(client.trigger_pipeline(repo_id, branch: branch || "main")) end
Starts a pipeline of repo_id on branch (main when nil). Returns the new CI::Run.
# File lib/warp_engine/ci/woodpecker/adapter.rb, line 131 def verify_config_request(request) SignatureVerifier.new(request, public_key: @public_key, public_key_url: @public_key_url).valid? end
Returns true when the config extension request carries a valid signature of the configured public key.