From 82940c7c0fc343dc4c4c9d0727acc1955bfee9af Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Sat, 28 Feb 2026 16:59:43 +0000 Subject: [PATCH] feat(gitlab): add support for GitLab protected branches (list and unprotect) --- changelog.md | 9 +++++++++ ts/00_commitinfo_data.ts | 2 +- ts/gitlab.classes.gitlabclient.ts | 19 +++++++++++++++++++ ts/gitlab.interfaces.ts | 6 ++++++ ts/index.ts | 1 + 5 files changed, 36 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index adbfc84..6bfaf96 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,14 @@ # Changelog +## 2026-02-28 - 2.3.0 - feat(gitlab) +add support for GitLab protected branches (list and unprotect) + +- Added IGitLabProtectedBranch interface +- Added GitLabClient.getProtectedBranches(projectId) returning IGitLabProtectedBranch[] +- Added GitLabClient.unprotectBranch(projectId, branchName) to remove branch protection +- Exported IGitLabProtectedBranch from index.ts +- Non-breaking API additions; recommended minor version bump + ## 2026-02-28 - 2.2.0 - feat(gitlabclient) add deleteProject method to delete a project using GitLab API DELETE /api/v4/projects/:id diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 042cc66..d22c3d8 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@apiclient.xyz/gitlab', - version: '2.2.0', + version: '2.3.0', description: 'A TypeScript client for the GitLab API, providing easy access to projects, groups, CI/CD variables, and pipelines.' } diff --git a/ts/gitlab.classes.gitlabclient.ts b/ts/gitlab.classes.gitlabclient.ts index 9cf78cf..57826bd 100644 --- a/ts/gitlab.classes.gitlabclient.ts +++ b/ts/gitlab.classes.gitlabclient.ts @@ -6,6 +6,7 @@ import type { IGitLabGroup, IGitLabVariable, IVariableOptions, + IGitLabProtectedBranch, IGitLabPipeline, IGitLabJob, ITestConnectionResult, @@ -369,6 +370,24 @@ export class GitLabClient { ); } + // --------------------------------------------------------------------------- + // Protected Branches + // --------------------------------------------------------------------------- + + public async getProtectedBranches(projectId: number | string): Promise { + return this.request( + 'GET', + `/api/v4/projects/${encodeURIComponent(projectId)}/protected_branches`, + ); + } + + public async unprotectBranch(projectId: number | string, branchName: string): Promise { + await this.request( + 'DELETE', + `/api/v4/projects/${encodeURIComponent(projectId)}/protected_branches/${encodeURIComponent(branchName)}`, + ); + } + // --------------------------------------------------------------------------- // Project Deletion // --------------------------------------------------------------------------- diff --git a/ts/gitlab.interfaces.ts b/ts/gitlab.interfaces.ts index fb4508e..1d1a977 100644 --- a/ts/gitlab.interfaces.ts +++ b/ts/gitlab.interfaces.ts @@ -44,6 +44,12 @@ export interface IVariableOptions { environment_scope?: string; } +export interface IGitLabProtectedBranch { + id: number; + name: string; + allow_force_push: boolean; +} + export interface IGitLabPipeline { id: number; project_id: number; diff --git a/ts/index.ts b/ts/index.ts index a5b86a5..2704a56 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -4,6 +4,7 @@ export type { IGitLabProject, IGitLabGroup, IGitLabVariable, + IGitLabProtectedBranch, IVariableOptions, IGitLabPipeline, IGitLabJob,