gitbeaker
repository·main·Indexed 23 days ago
https://github.com/jdalrymple/gitbeakerA comprehensive, typed GitLab SDK supporting Node.js, Deno, Bun, and browsers, providing complete coverage of GitLab APIs (up to version 16.5). The project includes @gitbeaker/rest for general use, @gitbeaker/core for API definitions, @gitbeaker/cli for terminal interaction, and @gitbeaker/requester-utils for creating custom SDK wrappers.
What's inside gitbeaker
- Gitbeaker is a typed GitLab SDK designed for use in modern environments including Browsers, Node.js, Deno, and Bun. It also provides a CLI for command-line interaction with GitLab. The SDK aims to provide complete coverage of GitLab's exposed APIs (up to version 16.5) with extensive TypeScript declarations and high test coverage.
Overview of @gitbeaker/requester-utils
main@gitbeaker/requester-utilsis a utility package designed to help developers create custom wrappers around the @gitbeaker/core GitLab SDK. It provides foundational classes likeRequesterUtilsandBaseResourceto streamline the creation of specialized GitLab API wrappers.Understand the Gitbeaker package structure
mainGitbeaker is distributed as several specialized packages. Depending on your needs, you should choose the appropriate package:
- @gitbeaker/rest: The primary library for most consumers. It is a wrapper around the core API that works in Node.js, Deno, Bun, and modern browsers using native
fetch. - @gitbeaker/core: Contains the core API definitions and details all GitLab resource support.
- @gitbeaker/cli: A CLI wrapper around the
@gitbeaker/restdistribution for terminal usage. - @gitbeaker/requester-utils: Low-level utilities for the underlying HTTP request functionality.
- @gitbeaker/rest: The primary library for most consumers. It is a wrapper around the core API that works in Node.js, Deno, Bun, and modern browsers using native
Install @gitbeaker/requester-utils
mainDepending on your runtime environment, you can install or load
@gitbeaker/requester-utilsusing the following methods:Node.js (18+)
Install via your preferred package manager:
npm install @gitbeaker/requester-utils yarn add @gitbeaker/requester-utils pnpm add @gitbeaker/requester-utilsThen import the utilities:
import { RequesterUtils, BaseResource } from '@gitbeaker/requester-utils';Deno
Load directly from
esm.shusing the?dtsquery parameter to include type definitions:import { RequesterUtils, BaseResource } from 'https://esm.sh/@gitbeaker/requester-utils?dts';Browsers
Load directly from
esm.shas an ES module:<script type="module"> import { RequesterUtils, BaseResource } from 'https://esm.sh/@gitbeaker/requester-utils'; </script>import { RequesterUtils, BaseResource } from '@gitbeaker/requester-utils';Run integration tests against a local GitLab instance
mainIf you want to run integration tests against a manually managed GitLab instance (instead of using the full
test:fullsuite), follow these steps:- Start GitLab: Navigate to the
.dockerdirectory and start the GitLab service.cd .docker && docker-compose up gitlab - Configure Environment: Set the
GITLAB_URLandGITLAB_PERSONAL_ACCESS_TOKENenvironment variables. - Execute Tests: Run the integration test command.
Default GitLab Credentials (for the containerized instance):
- URL:
http://localhost:8080 - Username:
root - Password:
gitbeaker - Personal Access Token:
superstrongpassword123
# Step 1: Start GitLab cd .docker && docker-compose up gitlab # Step 2 & 3: Set env vars and run tests export GITLAB_URL="http://localhost:8080" export GITLAB_PERSONAL_ACCESS_TOKEN="superstrongpassword123" pnpm test:integration- Start GitLab: Navigate to the
Install and use @gitbeaker/core
mainThe
@gitbeaker/corepackage is the core SDK for the GitLab API. Note that it is not intended for direct use; developers should instead use@gitbeaker/restor@gitbeaker/cli.Depending on your runtime, you can load the package as follows:
Node.js (18+)
Install via npm, yarn, or pnpm:
npm install @gitbeaker/core yarn add @gitbeaker/core pnpm add @gitbeaker/coreThen import the
Gitlabclass:import { Gitlab } from '@gitbeaker/core';Deno
Load directly from esm.sh:
import { Gitlab } from 'https://esm.sh/@gitbeaker/core?dts';Browsers
Load directly from esm.sh using a module script:
<script type="module"> import { Gitlab } from 'https://esm.sh/@gitbeaker/core'; </script>import { Gitlab } from '@gitbeaker/core';Handle HTTPS certificates for GitLab servers
mainIf your GitLab server uses HTTPS with custom certificates, the recommended approach is to use the
NODE_EXTRA_CA_CERTSenvironment variable to point to your certificate file.Warning: You can bypass certificate validation by setting
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0', but this is insecure and should be avoided."scripts": { "start": "NODE_EXTRA_CA_CERTS=./secrets/3ShapeCA.pem node bot.js" },Install the @gitbeaker/cli
mainThe
@gitbeaker/cliis a CLI wrapper for the@gitbeaker/restSDK. You can install it globally using npm, yarn, or pnpm. Requires Node 18+.npm install -g @gitbeaker/cli yarn add -g @gitbeaker/cli pnpm add -g @gitbeaker/cliEnable support for Node.js v16.18+
mainGitbeaker relies on
fetchsupport. Since nativefetchis standard in Node 18+, users on Node v16.18+ can enable compatibility by installingnode-fetchand polyfilling the globalfetchobject in their application's entry point.const semver = require('semver'); if (semver.lt(process.version, '20.0.0')) { global.fetch = require('node-fetch'); }Use the gitbeaker CLI
mainThe CLI follows a specific command structure to interact with the GitLab API services. You can use either the full
gitbeakercommand or the shorthandgb.Command Syntax
gitbeaker [service name] [method name] --config_args pos_arg1 pos_argN --opts_arg1 --opts_argNArgument Definitions
service name: Any supported API name from the@gitbeaker/restSDK.method name: Any supported command on that API service (e.g.,all,show,remove,update).--config_args: General configuration arguments (like personal tokens). These must include agborglprefix (e.g.,--gb-token).pos_arg1 ... pos_argN: Positional arguments required by the method. These must be provided in the correct order. They can also be provided as flags (e.g.,--pos_arg1), but order must be preserved.--opts_arg1 ... --opts_argN: Optional arguments as defined by the GitLab API documentation.
# To get all the projects gitbeaker projects all --gb-token="personaltoken" # To get all the projects id=2 and optional parameter "search" = "cool" gitbeaker projects all --gb-token="personaltoken" 2 --search="cool"Run the full test suite using Docker
mainThe recommended way to run the complete test suite (types, unit, integration, and e2e) is using the containerized approach. This starts a GitLab CE instance via Docker Compose, waits for it to be healthy, sets environment variables, and runs all tests sequentially.
Prerequisites:
- Docker and Docker Compose installed.
- At least 4GB of available RAM.
- Docker Desktop configured with sufficient memory allocation.
pnpm test:fullRun individual test types
mainYou can run specific subsets of the test suite using the following commands:
- Type tests:
pnpm test:types - Unit tests:
pnpm test:unit - Integration tests:
pnpm test:integration(requires a running GitLab instance) - End-to-end tests:
pnpm test:e2e
# Type tests only pnpm test:types # Unit tests only pnpm test:unit # Integration tests only (requires GitLab running) pnpm test:integration # End-to-end tests only pnpm test:e2e- Type tests: