### Authenticate and List Projects Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/cli/README.md Example of retrieving all projects using a personal access token. ```bash # To get all the projects gitbeaker projects all --gb-token="personaltoken" ``` -------------------------------- ### Install and Import Gitbeaker REST Client in Node.js Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/rest/README.md Install the @gitbeaker/rest package using npm, yarn, or pnpm, then import the Gitlab class for use in Node.js environments. ```javascript import { Gitlab } from '@gitbeaker/rest'; ``` -------------------------------- ### Start Manual GitLab Instance Source: https://github.com/jdalrymple/gitbeaker/blob/main/docs/TESTING.md Manually start a GitLab instance using Docker Compose for local testing. Access GitLab at http://localhost:8080 with provided credentials. ```bash cd .docker && docker-compose up gitlab ``` -------------------------------- ### Execute Commands with Positional and Optional Arguments Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/cli/README.md Example of calling a service method with a specific project ID and an optional search parameter. ```bash # To get all the projects id=2 and optional parameter "search" = "cool" gitbeaker projects all --gb-token="personaltoken" 2 --search="cool" ``` -------------------------------- ### Run Integration Tests (Local) Source: https://github.com/jdalrymple/gitbeaker/blob/main/docs/TESTING.md Execute integration tests locally after starting a manual GitLab instance. Ensure the GITLAB_URL and GITLAB_PERSONAL_ACCESS_TOKEN environment variables are set. ```bash export GITLAB_URL="http://localhost:8080" export GITLAB_PERSONAL_ACCESS_TOKEN="superstrongpassword123" pnpm test:integration ``` -------------------------------- ### Run Full Test Suite (Containerized) Source: https://github.com/jdalrymple/gitbeaker/blob/main/docs/TESTING.md Execute all test types (unit, integration, e2e) using Docker Compose. This command starts a GitLab instance, builds the project, and runs tests sequentially. ```bash pnpm test:full ``` -------------------------------- ### Import Gitbeaker in Node.js Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/core/README.md Import the core SDK in Node.js environments after installing via a package manager. ```js import { Gitlab } from '@gitbeaker/core'; ``` -------------------------------- ### Example Expanded Response Structure Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/rest/README.md Illustrates the structure of the response when `showExpanded` is true, including data and pagination information. ```javascript data: [ ... ], paginationInfo: { next: 4, current: 2, previous: 1, perPage: 3, } ``` -------------------------------- ### Import Requester Utils in Node.js Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/requester-utils/README.md Import the package after installing it via npm, yarn, or pnpm. ```js import { RequesterUtils, BaseResource } from '@gitbeaker/requester-utils'; ``` -------------------------------- ### Polyfill fetch for Node.js v16.18+ Source: https://github.com/jdalrymple/gitbeaker/blob/main/docs/FAQ.md Enable support for Node.js versions older than v20 by installing and requiring the `node-fetch` package. This polyfill ensures that the `fetch` API is available in environments where it's not natively supported. ```javascript const semver = require('semver'); if (semver.lt(process.version, '20.0.0')) { global.fetch = require('node-fetch'); } ``` -------------------------------- ### Instantiate Projects API with Options Object Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/rest/README.md Initializes the Projects API with configuration options, suitable for creating new projects or other project-related actions. ```javascript import { Projects } from '@gitbeaker/rest'; const projectsAPI = new Projects({ host: 'http://example.com', token: 'personaltoken', }); projectsAPI.create({ //options defined in the GitLab API documentation }); ``` -------------------------------- ### Instantiate Gitlab API with Async/Await Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/rest/README.md Initializes the Gitlab API client with a host and token, demonstrating how to fetch users using async/await. ```javascript import { Gitlab } from '@gitbeaker/rest'; const api = new Gitlab({ host: 'http://example.com', token: 'personaltoken', }); // Listing users let users = await api.Users.all(); ``` -------------------------------- ### Instantiate Gitlab API with Promise-Then Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/rest/README.md Initializes the Gitlab API client and demonstrates fetching projects using Promise-then notation. ```javascript api.Projects.all().then((projects) => { console.log(projects); }); ``` -------------------------------- ### Fetch Projects with Keyset Pagination Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/rest/README.md Retrieves projects using keyset pagination, sorting results in ascending order by creation date. ```javascript const { data } = await api.Projects.all({ pagination: 'keyset', sort: 'asc', orderBy: 'created_at', }); ``` -------------------------------- ### Import Gitbeaker in Browsers Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/core/README.md Load the core SDK directly in a browser environment using an ESM module script. ```html ``` -------------------------------- ### API Client Instantiation Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/rest/README.md Instantiate the GitBeaker library using a personal access token. Ensure your token is created in your GitLab Profile. ```APIDOC ## API Client Instantiation Instantiate the library using a basic token created in your [GitLab Profile](https://docs.gitlab.com/user/profile/personal_access_tokens/) ```javascript const api = new Gitlab({ token: 'personaltoken', }); ``` ### Instantiating Options Available options for instantiating the client: | Name | Optional | Default | | -------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------- | | `host` | Yes | `https://gitlab.com` | | `token` | Yes* | N/A | | `oauthToken` | Yes* | N/A | | `jobToken` | Yes* | N/A | | `rejectUnauthorized` | Yes | `true` | | `sudo` | Yes | `false` | | `camelize` | Yes | `false` | | `requesterFn` | No | @gitbeaker/rest & @gitbeaker/cli : fetch-based, The @gitbeaker/core package **does not** have a default and thus must be set explicitly | | `queryTimeout` | Yes | `300000` | | `profileToken` | Yes | N/A | | `profileMode` | Yes | `execution` | | `rateLimits` | No | [DEFAULT_RATE_LIMITS](#rate-limits) | | `rateLimitDuration` | No | `60` | > *One of these options should be supplied, as most API requests require authentication. ``` -------------------------------- ### Import Gitbeaker in Deno Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/core/README.md Load the core SDK in Deno using the esm.sh registry with TypeScript definitions. ```ts import { Gitlab } from 'https://esm.sh/@gitbeaker/core?dts'; ``` -------------------------------- ### Instantiate GitLab API Client with Token Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/rest/README.md Use this to create an API client instance. A personal access token from your GitLab profile is required for authentication. Ensure the token is valid. ```javascript const api = new Gitlab({ token: 'personaltoken', }); ``` -------------------------------- ### Initialize Gitbeaker with Host and Token Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/rest/README.md Initializes the Gitbeaker API client with the host URL and a personal access token. ```javascript import { Gitlab } from '@gitbeaker/rest'; const api = new Gitlab({ host: 'http://example.com', token: 'personaltoken', }); ``` -------------------------------- ### Pagination Options Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/rest/README.md Details on using offset and keyset pagination to manage large result sets from GitLab resources. ```APIDOC ## Pagination ### Description Gitbeaker supports both Offset and Keyset pagination for resource retrieval. Offset pagination is used by default, while Keyset pagination can be enabled via the `pagination` parameter. ### Parameters #### Query Parameters - **pagination** (string) - Optional - Defines pagination type: 'offset' or 'keyset'. - **perPage** (number) - Optional - Amount of results per request (Default: 20). - **orderBy** (string) - Optional - Field to order results by. - **sort** (string) - Optional - Sort direction: 'asc' or 'desc'. - **maxPages** (number) - Optional - Maximum number of requests to make (Offset only). - **page** (number) - Optional - Specific page to retrieve (Offset only). - **showExpanded** (boolean) - Optional - Returns pagination metadata alongside data. ### Response #### Success Response (200) - **data** (array) - The list of resources. - **paginationInfo** (object) - Metadata including 'next', 'current', 'previous', and 'perPage' values. ``` -------------------------------- ### Import Gitbeaker REST Client in Browsers Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/rest/README.md Load the @gitbeaker/rest package directly from esm.sh for use in web browsers. ```html ``` -------------------------------- ### Configure via Environment Variables Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/cli/README.md Set persistent configuration using environment variables to avoid passing flags repeatedly. ```bash GITLAB_HOST=http://example.com GITLAB_TOKEN=personaltoken GITBEAKER_CAMELIZE=true ``` -------------------------------- ### Import Gitbeaker and Expose Globally Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/rest/test/assets/test-import.html This snippet demonstrates how to import the Gitbeaker library and assign it to the window object. This is noted as bad practice and is intended for testing purposes only. ```javascript import * as gitbeaker from '../../dist/index.mjs'; // BAD PRACTISE!!! - Just for testing purposes window.gitbeaker = gitbeaker; ``` -------------------------------- ### Run Unit Tests (Local) Source: https://github.com/jdalrymple/gitbeaker/blob/main/docs/TESTING.md Execute unit tests locally without Docker. This command is the same as the containerized version. ```bash pnpm test:unit ``` -------------------------------- ### Fetch Projects with Max Pages and Custom Per Page Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/rest/README.md Fetches projects, setting a maximum of 2 pages and overriding the default per page count to 40. ```javascript let projects = await api.Projects.all({ maxPages: 2, perPage: 40 }); ``` -------------------------------- ### Instantiate Gitlab with a Custom Requester Source: https://github.com/jdalrymple/gitbeaker/blob/main/docs/FAQ.md Specify a custom request library by setting the `requester` property during service instantiation. Ensure your custom requester is correctly imported. ```javascript import { Gitlab } from '@gitbeaker/rest'; import YourCustomRequester from 'custom-requester'; const api = new Gitlab({ host: 'http://example.com', token: 'personaltoken', requester: YourCustomRequester, }); ``` -------------------------------- ### Import Requester Utils in Browser Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/requester-utils/README.md Load the package as a module directly from esm.sh for browser environments. ```html ``` -------------------------------- ### Run Integration Tests (Inline Environment Variables) Source: https://github.com/jdalrymple/gitbeaker/blob/main/docs/TESTING.md Execute integration tests locally by defining environment variables inline. This avoids the need for separate export commands. ```bash GITLAB_URL='http://localhost:8080' GITLAB_PERSONAL_ACCESS_TOKEN='superstrongpassword123' pnpm test:integration ``` -------------------------------- ### Run End-to-End Tests (Local) Source: https://github.com/jdalrymple/gitbeaker/blob/main/docs/TESTING.md Execute end-to-end tests locally. This command is the same as the containerized version. ```bash pnpm test:e2e ``` -------------------------------- ### Import Requester Utils in Deno Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/requester-utils/README.md Load the package directly from esm.sh using the Deno-specific import URL. ```ts import { RequesterUtils, BaseResource } from 'https://esm.sh/@gitbeaker/requester-utils?dts'; ``` -------------------------------- ### Import Gitbeaker REST Client in Deno Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/rest/README.md Load the @gitbeaker/rest package directly from esm.sh for use in Deno environments. Ensure the ?dts flag is appended for TypeScript declarations. ```typescript import { Gitlab } from 'https://esm.sh/@gitbeaker/rest?dts'; ``` -------------------------------- ### Execute Gitbeaker CLI Commands Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/cli/README.md General syntax for invoking Gitbeaker services and methods via the command line. ```bash gitbeaker [service name] [method name] --config_args pos_arg1 pos_argN --opts_arg1 --opts_argN # A shorthand can also be used: gb [service name] [method name] --config_args pos_arg1 pos_argN --opts_arg1 --opts_argN ``` -------------------------------- ### Run Specific Test Types (Containerized) Source: https://github.com/jdalrymple/gitbeaker/blob/main/docs/TESTING.md Execute individual test suites. Ensure GitLab is running for integration and end-to-end tests. ```bash # 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 ``` -------------------------------- ### Fetch Projects with Expanded Payload and Pagination Info Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/rest/README.md Retrieves projects with custom per page and max pages settings, including expanded response data and pagination details. ```javascript const { data, paginationInfo } = await api.Projects.all({ perPage:40, maxPages:2, showExpanded: true }); ``` -------------------------------- ### Fetch Projects with Max Pages Limit Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/rest/README.md Retrieves projects from GitLab, limiting the number of requests to a maximum of 2 pages using offset pagination. ```javascript let projects = await api.Projects.all({ maxPages: 2 }); ``` -------------------------------- ### Clean Docker Cache and Rebuild Source: https://github.com/jdalrymple/gitbeaker/blob/main/docs/TESTING.md Troubleshoot Docker build issues by pruning the system cache and rebuilding containers without using the cache. ```bash # Clean Docker cache docker system prune -f # Rebuild containers cd .docker && docker-compose build --no-cache ``` -------------------------------- ### Default Rate Limits Configuration Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/rest/README.md Defines the default rate limits for various GitLab API endpoints. These can be overridden during API wrapper instantiation. ```javascript const DEFAULT_RATE_LIMITS = Object.freeze({ // Default rate limit '**': 3000, // Import/Export 'projects/import': 6, 'projects/*/export': 6, 'projects/*/download': 1, 'groups/import': 6, 'groups/*/export': 6, 'groups/*/download': 1, // Note creation 'projects/*/issues/*/notes': { method: 'post', limit: 300, }, 'projects/*/snippets/*/notes': { method: 'post', limit: 300, }, 'projects/*/merge_requests/*/notes': { method: 'post', limit: 300, }, 'groups/*/epics/*/notes': { method: 'post', limit: 300, }, // Repositories - get file archive 'projects/*/repository/archive*': 5, // Project Jobs 'projects/*/jobs': 600, // Member deletion 'projects/*/members': 60, 'groups/*/members': 60, }); ``` -------------------------------- ### Custom Rate Limits and Duration Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/rest/README.md Overrides default rate limits and sets a custom rate limit duration when instantiating the Gitlab API wrapper. ```javascript const api = new Gitlab({ token: 'token', rateLimits: { '**': 30, 'projects/import/*': 40, 'projects/*/issues/*/notes': { method: 'post', limit: 300, }, }, rateLimitDuration: 30, }); ``` -------------------------------- ### Expanded Payloads Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/rest/README.md Explains how to retrieve full response metadata including headers and status codes instead of just the response body. ```APIDOC ## Expanded Payloads ### Description By default, API methods return only the response body. Passing the `showExpanded` parameter allows the client to receive a structured object containing the body, headers, and status code. ### Parameters #### Query Parameters - **showExpanded** (boolean) - Optional - If true, returns an object containing the body, headers, and status. ### Response #### Success Response (200) - **body** (any) - The actual response data. - **headers** (object) - Key-value pairs of response headers. - **status** (number) - The HTTP status code. ``` -------------------------------- ### TypeScript Response Body Types Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/rest/README.md Defines the possible types for the response body when using Gitbeaker API methods. ```typescript type ResponseBodyTypes = | Record | Record[] | ReadableStream | Blob | string | string[] | number | void | null; interface FormattedResponse { body: T; headers: Record; status: number; } ``` -------------------------------- ### Override undici Dispatcher for Request Timeouts Source: https://github.com/jdalrymple/gitbeaker/blob/main/docs/FAQ.md Adjust the default headers and body timeouts for undici's fetch implementation by setting a global dispatcher. Setting `headersTimeout` and `bodyTimeout` to `0` effectively disables these timeouts. ```javascript import { Agent } from 'undici'; globalThis[Symbol.for('undici.globalDispatcher.1')] = new Agent({ headersTimeout: 0, bodyTimeout: 0, }); ``` -------------------------------- ### Set NODE_EXTRA_CA_CERTS for HTTPS Certificates Source: https://github.com/jdalrymple/gitbeaker/blob/main/docs/FAQ.md Configure Node.js to use custom CA certificates for HTTPS connections by setting the `NODE_EXTRA_CA_CERTS` environment variable in your npm scripts. This is the recommended method for handling self-signed or private certificates. ```bash "scripts": { "start": "NODE_EXTRA_CA_CERTS=./secrets/3ShapeCA.pem node bot.js" } ``` -------------------------------- ### Custom GitbeakerError Class Source: https://github.com/jdalrymple/gitbeaker/blob/main/packages/rest/README.md Defines a custom error class for Gitbeaker, extending the base Error class to include request and response details in the error cause. ```typescript class GitbeakerError extends Error { constructor( message: string, options?: { cause: { description: string; request: Request; response: Response; }; }, ) { super(message, options); this.name = 'GitbeakerError'; } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.