class WarpEngine::CI::Gitlab::Client
A minimal JSON client of the GitLab REST API (v4), authenticated with a PRIVATE-TOKEN. Every call returns the parsed JSON (nil for an empty body), raises CI::ConnectionError when the server cannot be reached and CI::ApiError for an error status or a non-JSON body.
Public Class Methods
Source
# File lib/warp_engine/ci/gitlab/client.rb, line 15 def initialize(url:, token:) @base_url = url.to_s.chomp("/") @token = token end
- url
-
the GitLab URL (a trailing slash is dropped)
- token
-
the access token sent as
PRIVATE-TOKEN
Public Instance Methods
Source
# File lib/warp_engine/ci/gitlab/client.rb, line 31 def activate_repo(_project_id) nil end
Does nothing and returns nil: GitLab CI needs no activation.
# File lib/warp_engine/ci/gitlab/client.rb, line 46 def create_secret(project_id, name:, value:) post("/api/v4/projects/#{project_id}/variables", body: { key: name, value: value, protected: false, masked: true }) end
POST /api/v4/projects/:project_id/variables: creates the masked, unprotected variable name.
# File lib/warp_engine/ci/gitlab/client.rb, line 36 def deactivate_repo(_project_id) nil end
Does nothing and returns nil: GitLab CI needs no activation.
# File lib/warp_engine/ci/gitlab/client.rb, line 58 def delete_secret(project_id, secret_name) delete("/api/v4/projects/#{project_id}/variables/#{secret_name}") end
DELETE /api/v4/projects/:project_id/variables/:secret_name: deletes the variable.
# File lib/warp_engine/ci/gitlab/client.rb, line 76 def get_pipeline(project_id, pipeline_id) get("/api/v4/projects/#{project_id}/pipelines/#{pipeline_id}") end
GET /api/v4/projects/:project_id/pipelines/:pipeline_id: returns the pipeline Hash.
Source
# File lib/warp_engine/ci/gitlab/client.rb, line 26 def get_repo(project_id) get("/api/v4/projects/#{project_id}") end
GET /api/v4/projects/:project_id: returns the project Hash.
Source
# File lib/warp_engine/ci/gitlab/client.rb, line 69 def latest_pipeline(project_id) results = get("/api/v4/projects/#{project_id}/pipelines", params: { per_page: 1, sort: "desc" }) Array(results).first end
Returns the newest pipeline Hash of the project, or nil when it has none.
# File lib/warp_engine/ci/gitlab/client.rb, line 63 def list_pipelines(project_id, page: 1, per_page: 25) get("/api/v4/projects/#{project_id}/pipelines", params: { page: page, per_page: per_page }) end
GET /api/v4/projects/:project_id/pipelines: returns one page of pipeline Hashes.
Source
# File lib/warp_engine/ci/gitlab/client.rb, line 21 def list_repos get("/api/v4/projects", params: { membership: true, simple: true, per_page: 100 }) end
GET /api/v4/projects: returns up to 100 project Hashes the token is a member of.
Source
# File lib/warp_engine/ci/gitlab/client.rb, line 41 def list_secrets(project_id) get("/api/v4/projects/#{project_id}/variables") end
GET /api/v4/projects/:project_id/variables: returns the Array of CI/CD variable Hashes.
# File lib/warp_engine/ci/gitlab/client.rb, line 82 def trigger_pipeline(project_id, branch: "main") post("/api/v4/projects/#{project_id}/pipeline", body: { ref: branch }) end
POST /api/v4/projects/:project_id/pipeline: starts a pipeline on the branch ref and returns its Hash.
# File lib/warp_engine/ci/gitlab/client.rb, line 52 def update_secret(project_id, secret_name, value:) put("/api/v4/projects/#{project_id}/variables/#{secret_name}", body: { value: value }) end
PUT /api/v4/projects/:project_id/variables/:secret_name: sets a new value.