@reelout/gitlab 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Gitlab } from "@gitbeaker/rest";
2
+ import { createHostReleasePlugin } from "@reelout/core";
2
3
  // src/isNotFoundError.ts
3
4
  /**
4
5
  * Check whether an error represents a GitLab API "not found" response.
@@ -119,7 +120,7 @@ async function createRelease(context, plan, token, repository) {
119
120
  return () => deleteRelease(plan, token, repository);
120
121
  }
121
122
  // package.json
122
- var version = "0.7.1";
123
+ var version = "0.8.0";
123
124
  // src/verifyToken.ts
124
125
  /**
125
126
  * Verify that a GitLab token can access the project it releases to.
@@ -148,25 +149,13 @@ async function verifyToken(token, repository) {
148
149
  }
149
150
  // src/gitlab.ts
150
151
  /**
151
- * Read the GitLab token from the release environment.
152
- *
153
- * Treats unset and whitespace-only values as missing.
154
- *
155
- * @param env Release environment variables
156
- * @returns The trimmed token, or undefined when it is not set
157
- */
158
- var readGitlabToken = (env) => {
159
- const token = env.GITLAB_TOKEN?.trim();
160
- return token ? token : void 0;
161
- };
162
- /**
163
152
  * Built-in plugin that creates GitLab releases for finalized release plans.
164
153
  *
165
154
  * @remarks
166
155
  * **Lifecycle Stages:**
167
156
  * - `configure`: Leaves the plugin inactive when no GitLab-hosted repository
168
157
  * was detected. Otherwise verifies the `GITLAB_TOKEN` environment variable:
169
- * a missing token skips the plugin's `publish` step with a warning — or
158
+ * a missing token skips the plugin's `publish` step with a debug message — or
170
159
  * fails the run in strict mode — and a provided token is verified against
171
160
  * the release repository so an invalid token fails before any mutation,
172
161
  * including under dry-run.
@@ -179,49 +168,14 @@ var readGitlabToken = (env) => {
179
168
  *
180
169
  * @returns A release plugin configured for GitLab release creation.
181
170
  */
182
- var gitlab = () => ({
171
+ var gitlab = () => createHostReleasePlugin({
183
172
  name: "@reelout/gitlab",
184
173
  version,
185
- configure: async (context, next) => {
186
- const repository = context.repository;
187
- if (repository?.host !== "gitlab") {
188
- context.logger.debug("GitLab releases will not be created: no GitLab-hosted repository was detected.");
189
- return next(context);
190
- }
191
- const token = readGitlabToken(context.env);
192
- if (!token) {
193
- if (context.strict) throw new Error("The GITLAB_TOKEN environment variable is required in strict mode.");
194
- context.logger.warn("GitLab releases will not be created: GITLAB_TOKEN is not set.");
195
- return next(context);
196
- }
197
- await verifyToken(token, repository);
198
- return next(context);
199
- },
200
- publish: async (context, next) => {
201
- if (context.repository?.host !== "gitlab") {
202
- context.logger.debug("GitLab publishing was skipped: no GitLab-hosted repository was detected.");
203
- return next(context);
204
- }
205
- const token = readGitlabToken(context.env);
206
- if (!token) return next(context);
207
- if (context.dryRun) {
208
- context.logger.debug("[DRY RUN] GitLab releases will not be created.");
209
- return next(context);
210
- }
211
- const plans = context.plans.toSorted((a, b) => (a.package.name || "").localeCompare(b.package.name || ""));
212
- const repository = context.repository;
213
- const rollbacks = [];
214
- for (const plan of plans.toReversed()) {
215
- const rollback = await createRelease(context, plan, token, repository);
216
- if (rollback) rollbacks.push(rollback);
217
- }
218
- try {
219
- return await next(context);
220
- } catch (err) {
221
- await Promise.allSettled(rollbacks.map((rollback) => rollback()));
222
- throw err;
223
- }
224
- }
174
+ host: "gitlab",
175
+ displayName: "GitLab",
176
+ tokenEnvKey: "GITLAB_TOKEN",
177
+ verifyToken,
178
+ createRelease
225
179
  });
226
180
  // src/isRepositoryPublic.ts
227
181
  /**
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/isNotFoundError.ts","../src/deleteRelease.ts","../src/fetchRelease.ts","../src/restoreRelease.ts","../src/createRelease.ts","../src/verifyToken.ts","../src/gitlab.ts","../src/isRepositoryPublic.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\n/**\n * Check whether an error represents a GitLab API \"not found\" response.\n *\n * GitBeaker exposes the HTTP status of a failed request on the `cause`\n * property of the thrown error.\n *\n * @param err Error thrown by a GitBeaker API call\n * @returns True when the error represents a 404 response\n */\nexport function isNotFoundError(err: unknown): boolean {\n const status = (err as { cause?: { response?: { status?: number } } })?.cause\n ?.response?.status\n\n return status === 404\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { Gitlab } from '@gitbeaker/rest'\nimport type { GitRepository, ReleasePlan } from '@reelout/core'\nimport { isNotFoundError } from './isNotFoundError'\n\n/**\n * Delete a GitLab release associated with a package tag.\n *\n * Skips deletion if the plan does not contain a valid tag name. Resolves gracefully\n * if the release does not exist on GitLab (e.g., 404 status).\n *\n * @param plan Release plan containing the tag associated with the release to delete\n * @param token GitLab authentication token\n * @param repository Target repository\n * @returns Promise that resolves when the release is deleted\n */\nexport async function deleteRelease(\n plan: ReleasePlan,\n token: string,\n repository: GitRepository\n): Promise<void> {\n if (!plan.release?.tag?.name) {\n return\n }\n\n try {\n const api = new Gitlab({ token })\n\n const projectId = encodeURIComponent(\n `${repository.owner}/${repository.repo}`\n )\n\n await api.ProjectReleases.remove(projectId, plan.release.tag.name)\n } catch (err) {\n if (isNotFoundError(err)) {\n return\n }\n\n throw err\n }\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { Gitlab } from '@gitbeaker/rest'\nimport { isNotFoundError } from './isNotFoundError'\n\n/**\n * GitLab release content captured before an overwrite.\n */\nexport interface GitLabRelease {\n /** Release name as it existed before the overwrite. */\n name: string | null\n /** Release description as it existed before the overwrite. */\n description: string | null\n}\n\n/**\n * Fetch the GitLab release that exists for a tag.\n *\n * @param api Authenticated GitLab client\n * @param projectId Encoded project id the release belongs to\n * @param tagName Tag the release is looked up by\n * @returns The GitLab release content, or null when the tag has no release\n */\nexport async function fetchRelease(\n api: Gitlab,\n projectId: string,\n tagName: string\n): Promise<GitLabRelease | null> {\n try {\n const release = await api.ProjectReleases.show(projectId, tagName)\n\n return { name: release.name, description: release.description }\n } catch (err) {\n if (isNotFoundError(err)) {\n return null\n }\n\n throw err\n }\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { Gitlab } from '@gitbeaker/rest'\nimport type { GitRepository, ReleasePlan } from '@reelout/core'\nimport type { GitLabRelease } from './fetchRelease'\n\n/**\n * Restore an overwritten GitLab release to its original content.\n *\n * Reapplies the captured original name and description via the update\n * endpoint. Skips the restore when the plan does not contain a valid tag\n * name.\n *\n * @param plan Release plan containing the tag associated with the release to restore\n * @param original Original release content captured before the overwrite\n * @param token GitLab authentication token\n * @param repository Target repository\n * @returns Promise that resolves when the release is restored\n */\nexport async function restoreRelease(\n plan: ReleasePlan,\n original: GitLabRelease,\n token: string,\n repository: GitRepository\n): Promise<void> {\n if (!plan.release?.tag?.name) {\n return\n }\n\n const api = new Gitlab({ token })\n\n const projectId = encodeURIComponent(`${repository.owner}/${repository.repo}`)\n\n await api.ProjectReleases.edit(projectId, plan.release.tag.name, {\n name: original.name,\n description: original.description,\n })\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { Gitlab } from '@gitbeaker/rest'\nimport type { GitRepository, ReleaseContext, ReleasePlan } from '@reelout/core'\nimport { deleteRelease } from './deleteRelease'\nimport { fetchRelease } from './fetchRelease'\nimport { restoreRelease } from './restoreRelease'\n\n/**\n * Rollback callback returned after a release was created or overwritten.\n */\nexport type ReleaseRollback = () => Promise<void>\n\n/**\n * Create or overwrite a GitLab release for a package tag.\n *\n * Skips the write when the tag has no message. Fetches the release for the\n * tag first: an existing release is overwritten with the generated content\n * via the update endpoint, and a missing release is created. Returns a\n * rollback callback that restores an overwritten release or deletes a\n * release created by this call.\n *\n * @param context Release context containing commit and prerelease information\n * @param plan Release plan containing the tag to publish\n * @param token GitLab authentication token\n * @param repository Target repository\n * @returns Promise that resolves to a rollback callback for the release, or\n * undefined when the write was skipped\n */\nexport async function createRelease(\n context: ReleaseContext,\n plan: ReleasePlan,\n token: string,\n repository: GitRepository\n): Promise<ReleaseRollback | void> {\n if (!plan.release?.tag?.message) {\n return\n }\n\n const api = new Gitlab({ token })\n\n const projectId = encodeURIComponent(`${repository.owner}/${repository.repo}`)\n\n const tagName = plan.release.tag.name\n\n const existing = await fetchRelease(api, projectId, tagName)\n\n if (existing) {\n await api.ProjectReleases.edit(projectId, tagName, {\n name: tagName,\n description: plan.release.tag.message,\n })\n\n context.logger.warn(\n `GitLab release for tag \"${tagName}\" already exists: its name and description were overwritten with the freshly generated content.`\n )\n\n return () => restoreRelease(plan, existing, token, repository)\n }\n\n await api.ProjectReleases.create(projectId, {\n name: tagName,\n tag_name: tagName,\n description: plan.release.tag.message,\n ref: context.commit.hash,\n })\n\n return () => deleteRelease(plan, token, repository)\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { Gitlab } from '@gitbeaker/rest'\nimport type { GitRepository } from '@reelout/core'\n\n/**\n * Verify that a GitLab token can access the project it releases to.\n *\n * Performs the token pre-flight for the GitLab plugin by reading the target\n * project, so a provided-but-invalid or expired token fails during the\n * configure stage, before any release is created. The project is read\n * instead of the current user because tokens scoped to a project or a CI\n * job are not always permitted to read the current user while still being\n * able to create releases for the project. The check runs identically\n * under dry-run.\n *\n * @param token GitLab authentication token\n * @param repository Target repository\n * @returns A promise that resolves when GitLab accepts the token\n * @throws If reading the project fails, carrying the original error as the cause\n */\nexport async function verifyToken(\n token: string,\n repository: GitRepository\n): Promise<void> {\n const api = new Gitlab({ token })\n\n const projectId = encodeURIComponent(`${repository.owner}/${repository.repo}`)\n\n try {\n await api.Projects.show(projectId)\n } catch (err) {\n throw new Error(\n 'The GITLAB_TOKEN environment variable could not be verified.',\n { cause: err }\n )\n }\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { ReleaseContext, ReleasePlugin } from '@reelout/core'\nimport { version } from '../package.json'\nimport { createRelease, type ReleaseRollback } from './createRelease'\nimport { verifyToken } from './verifyToken'\n\n/**\n * Read the GitLab token from the release environment.\n *\n * Treats unset and whitespace-only values as missing.\n *\n * @param env Release environment variables\n * @returns The trimmed token, or undefined when it is not set\n */\nconst readGitlabToken = (env: ReleaseContext['env']): string | undefined => {\n const token = env.GITLAB_TOKEN?.trim()\n\n return token ? token : undefined\n}\n\n/**\n * Built-in plugin that creates GitLab releases for finalized release plans.\n *\n * @remarks\n * **Lifecycle Stages:**\n * - `configure`: Leaves the plugin inactive when no GitLab-hosted repository\n * was detected. Otherwise verifies the `GITLAB_TOKEN` environment variable:\n * a missing token skips the plugin's `publish` step with a warning — or\n * fails the run in strict mode — and a provided token is verified against\n * the release repository so an invalid token fails before any mutation,\n * including under dry-run.\n * - `publish`: Skips release creation when the plugin is inactive. Creates\n * GitLab releases in reverse alphabetical package order (ensuring the root\n * package release is created last), overwriting the name and notes of any\n * existing release for a planned tag. Automatically rolls back when\n * subsequent publishing stages fail: releases created by this run are\n * deleted and overwritten releases are restored to their original content.\n *\n * @returns A release plugin configured for GitLab release creation.\n */\nconst gitlab = (): ReleasePlugin => ({\n name: '@reelout/gitlab',\n version,\n configure: async (context, next) => {\n const repository = context.repository\n\n if (repository?.host !== 'gitlab') {\n context.logger.debug(\n 'GitLab releases will not be created: no GitLab-hosted repository was detected.'\n )\n\n return next(context)\n }\n\n const token = readGitlabToken(context.env)\n\n if (!token) {\n if (context.strict) {\n throw new Error(\n 'The GITLAB_TOKEN environment variable is required in strict mode.'\n )\n }\n\n context.logger.warn(\n 'GitLab releases will not be created: GITLAB_TOKEN is not set.'\n )\n\n return next(context)\n }\n\n await verifyToken(token, repository)\n\n return next(context)\n },\n publish: async (context, next) => {\n if (context.repository?.host !== 'gitlab') {\n context.logger.debug(\n 'GitLab publishing was skipped: no GitLab-hosted repository was detected.'\n )\n\n return next(context)\n }\n\n const token = readGitlabToken(context.env)\n\n if (!token) {\n return next(context)\n }\n\n if (context.dryRun) {\n context.logger.debug('[DRY RUN] GitLab releases will not be created.')\n return next(context)\n }\n\n const plans = context.plans.toSorted((a, b) =>\n (a.package.name || '').localeCompare(b.package.name || '')\n )\n\n const repository = context.repository\n\n const rollbacks: ReleaseRollback[] = []\n\n // Create releases in reverse order\n // so that the root package release is created last,\n // as it is often the most important one.\n for (const plan of plans.toReversed()) {\n const rollback = await createRelease(context, plan, token, repository)\n\n if (rollback) {\n rollbacks.push(rollback)\n }\n }\n\n try {\n return await next(context)\n } catch (err) {\n await Promise.allSettled(rollbacks.map((rollback) => rollback()))\n\n throw err\n }\n },\n})\n\nexport default gitlab\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { Gitlab } from '@gitbeaker/rest'\nimport type { GitRepository } from '@reelout/core'\n\n/**\n * Check if the target GitLab repository is public.\n *\n * Uses the GitBeaker REST API with the provided token to fetch the\n * visibility status of the specified repository.\n *\n * @param token GitLab authentication token\n * @param repository Target repository\n * @returns Promise that resolves to `true` if the repository is public\n */\nexport async function isRepositoryPublic(\n token: string,\n repository: GitRepository\n): Promise<boolean> {\n const api = new Gitlab({ token })\n\n const projectId = encodeURIComponent(`${repository.owner}/${repository.repo}`)\n\n const project = await api.Projects.show(projectId)\n\n return project.visibility === 'public'\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAgB,gBAAgB,KAAuB;CAIrD,OAHgB,KAAwD,OACpE,UAAU,WAEI;AACpB;;;;;;;;;;;;;ACCA,eAAsB,cACpB,MACA,OACA,YACe;CACf,IAAI,CAAC,KAAK,SAAS,KAAK,MACtB;CAGF,IAAI;EACF,MAAM,MAAM,IAAI,OAAO,EAAE,MAAM,CAAC;EAEhC,MAAM,YAAY,mBAChB,GAAG,WAAW,MAAM,GAAG,WAAW,MACpC;EAEA,MAAM,IAAI,gBAAgB,OAAO,WAAW,KAAK,QAAQ,IAAI,IAAI;CACnE,SAAS,KAAK;EACZ,IAAI,gBAAgB,GAAG,GACrB;EAGF,MAAM;CACR;AACF;;;;;;;;;;AClBA,eAAsB,aACpB,KACA,WACA,SAC+B;CAC/B,IAAI;EACF,MAAM,UAAU,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EA,MAAM,aAAa,QAAQ;EAE3B,MAAM,YAA+B,CAAC;EAKtC,KAAK,MAAM,QAAQ,MAAM,WAAW,GAAG;GACrC,MAAM,WAAW,MAAM,cAAc,SAAS,MAAM,OAAO,UAAU;GAErE,IAAI,UACF,UAAU,KAAK,QAAQ;EAE3B;EAEA,IAAI;GACF,OAAO,MAAM,KAAK,OAAO;EAC3B,SAAS,KAAK;GACZ,MAAM,QAAQ,WAAW,UAAU,KAAK,aAAa,SAAS,CAAC,CAAC;GAEhE,MAAM;EACR;CACF;AACF;;;;;;;;;;;;AC3GA,eAAsB,mBACpB,OACA,YACkB;CAClB,MAAM,MAAM,IAAI,OAAO,EAAE,MAAM,CAAC;CAEhC,MAAM,YAAY,mBAAmB,GAAG,WAAW,MAAM,GAAG,WAAW,MAAM;CAI7E,QAAO,MAFe,IAAI,SAAS,KAAK,SAAS,EAAA,CAElC,eAAe;AAChC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/isNotFoundError.ts","../src/deleteRelease.ts","../src/fetchRelease.ts","../src/restoreRelease.ts","../src/createRelease.ts","../src/verifyToken.ts","../src/gitlab.ts","../src/isRepositoryPublic.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\n/**\n * Check whether an error represents a GitLab API \"not found\" response.\n *\n * GitBeaker exposes the HTTP status of a failed request on the `cause`\n * property of the thrown error.\n *\n * @param err Error thrown by a GitBeaker API call\n * @returns True when the error represents a 404 response\n */\nexport function isNotFoundError(err: unknown): boolean {\n const status = (err as { cause?: { response?: { status?: number } } })?.cause\n ?.response?.status\n\n return status === 404\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { Gitlab } from '@gitbeaker/rest'\nimport type { GitRepository, ReleasePlan } from '@reelout/core'\nimport { isNotFoundError } from './isNotFoundError'\n\n/**\n * Delete a GitLab release associated with a package tag.\n *\n * Skips deletion if the plan does not contain a valid tag name. Resolves gracefully\n * if the release does not exist on GitLab (e.g., 404 status).\n *\n * @param plan Release plan containing the tag associated with the release to delete\n * @param token GitLab authentication token\n * @param repository Target repository\n * @returns Promise that resolves when the release is deleted\n */\nexport async function deleteRelease(\n plan: ReleasePlan,\n token: string,\n repository: GitRepository\n): Promise<void> {\n if (!plan.release?.tag?.name) {\n return\n }\n\n try {\n const api = new Gitlab({ token })\n\n const projectId = encodeURIComponent(\n `${repository.owner}/${repository.repo}`\n )\n\n await api.ProjectReleases.remove(projectId, plan.release.tag.name)\n } catch (err) {\n if (isNotFoundError(err)) {\n return\n }\n\n throw err\n }\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { Gitlab } from '@gitbeaker/rest'\nimport { isNotFoundError } from './isNotFoundError'\n\n/**\n * GitLab release content captured before an overwrite.\n */\nexport interface GitLabRelease {\n /** Release name as it existed before the overwrite. */\n name: string | null\n /** Release description as it existed before the overwrite. */\n description: string | null\n}\n\n/**\n * Fetch the GitLab release that exists for a tag.\n *\n * @param api Authenticated GitLab client\n * @param projectId Encoded project id the release belongs to\n * @param tagName Tag the release is looked up by\n * @returns The GitLab release content, or null when the tag has no release\n */\nexport async function fetchRelease(\n api: Gitlab,\n projectId: string,\n tagName: string\n): Promise<GitLabRelease | null> {\n try {\n const release = await api.ProjectReleases.show(projectId, tagName)\n\n return { name: release.name, description: release.description }\n } catch (err) {\n if (isNotFoundError(err)) {\n return null\n }\n\n throw err\n }\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { Gitlab } from '@gitbeaker/rest'\nimport type { GitRepository, ReleasePlan } from '@reelout/core'\nimport type { GitLabRelease } from './fetchRelease'\n\n/**\n * Restore an overwritten GitLab release to its original content.\n *\n * Reapplies the captured original name and description via the update\n * endpoint. Skips the restore when the plan does not contain a valid tag\n * name.\n *\n * @param plan Release plan containing the tag associated with the release to restore\n * @param original Original release content captured before the overwrite\n * @param token GitLab authentication token\n * @param repository Target repository\n * @returns Promise that resolves when the release is restored\n */\nexport async function restoreRelease(\n plan: ReleasePlan,\n original: GitLabRelease,\n token: string,\n repository: GitRepository\n): Promise<void> {\n if (!plan.release?.tag?.name) {\n return\n }\n\n const api = new Gitlab({ token })\n\n const projectId = encodeURIComponent(`${repository.owner}/${repository.repo}`)\n\n await api.ProjectReleases.edit(projectId, plan.release.tag.name, {\n name: original.name,\n description: original.description,\n })\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { Gitlab } from '@gitbeaker/rest'\nimport type { GitRepository, ReleaseContext, ReleasePlan } from '@reelout/core'\nimport { deleteRelease } from './deleteRelease'\nimport { fetchRelease } from './fetchRelease'\nimport { restoreRelease } from './restoreRelease'\n\n/**\n * Rollback callback returned after a release was created or overwritten.\n */\nexport type ReleaseRollback = () => Promise<void>\n\n/**\n * Create or overwrite a GitLab release for a package tag.\n *\n * Skips the write when the tag has no message. Fetches the release for the\n * tag first: an existing release is overwritten with the generated content\n * via the update endpoint, and a missing release is created. Returns a\n * rollback callback that restores an overwritten release or deletes a\n * release created by this call.\n *\n * @param context Release context containing commit and prerelease information\n * @param plan Release plan containing the tag to publish\n * @param token GitLab authentication token\n * @param repository Target repository\n * @returns Promise that resolves to a rollback callback for the release, or\n * undefined when the write was skipped\n */\nexport async function createRelease(\n context: ReleaseContext,\n plan: ReleasePlan,\n token: string,\n repository: GitRepository\n): Promise<ReleaseRollback | void> {\n if (!plan.release?.tag?.message) {\n return\n }\n\n const api = new Gitlab({ token })\n\n const projectId = encodeURIComponent(`${repository.owner}/${repository.repo}`)\n\n const tagName = plan.release.tag.name\n\n const existing = await fetchRelease(api, projectId, tagName)\n\n if (existing) {\n await api.ProjectReleases.edit(projectId, tagName, {\n name: tagName,\n description: plan.release.tag.message,\n })\n\n context.logger.warn(\n `GitLab release for tag \"${tagName}\" already exists: its name and description were overwritten with the freshly generated content.`\n )\n\n return () => restoreRelease(plan, existing, token, repository)\n }\n\n await api.ProjectReleases.create(projectId, {\n name: tagName,\n tag_name: tagName,\n description: plan.release.tag.message,\n ref: context.commit.hash,\n })\n\n return () => deleteRelease(plan, token, repository)\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { Gitlab } from '@gitbeaker/rest'\nimport type { GitRepository } from '@reelout/core'\n\n/**\n * Verify that a GitLab token can access the project it releases to.\n *\n * Performs the token pre-flight for the GitLab plugin by reading the target\n * project, so a provided-but-invalid or expired token fails during the\n * configure stage, before any release is created. The project is read\n * instead of the current user because tokens scoped to a project or a CI\n * job are not always permitted to read the current user while still being\n * able to create releases for the project. The check runs identically\n * under dry-run.\n *\n * @param token GitLab authentication token\n * @param repository Target repository\n * @returns A promise that resolves when GitLab accepts the token\n * @throws If reading the project fails, carrying the original error as the cause\n */\nexport async function verifyToken(\n token: string,\n repository: GitRepository\n): Promise<void> {\n const api = new Gitlab({ token })\n\n const projectId = encodeURIComponent(`${repository.owner}/${repository.repo}`)\n\n try {\n await api.Projects.show(projectId)\n } catch (err) {\n throw new Error(\n 'The GITLAB_TOKEN environment variable could not be verified.',\n { cause: err }\n )\n }\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { createHostReleasePlugin } from '@reelout/core'\nimport type { ReleasePlugin } from '@reelout/core'\nimport { version } from '../package.json'\nimport { createRelease } from './createRelease'\nimport { verifyToken } from './verifyToken'\n\n/**\n * Built-in plugin that creates GitLab releases for finalized release plans.\n *\n * @remarks\n * **Lifecycle Stages:**\n * - `configure`: Leaves the plugin inactive when no GitLab-hosted repository\n * was detected. Otherwise verifies the `GITLAB_TOKEN` environment variable:\n * a missing token skips the plugin's `publish` step with a debug message — or\n * fails the run in strict mode — and a provided token is verified against\n * the release repository so an invalid token fails before any mutation,\n * including under dry-run.\n * - `publish`: Skips release creation when the plugin is inactive. Creates\n * GitLab releases in reverse alphabetical package order (ensuring the root\n * package release is created last), overwriting the name and notes of any\n * existing release for a planned tag. Automatically rolls back when\n * subsequent publishing stages fail: releases created by this run are\n * deleted and overwritten releases are restored to their original content.\n *\n * @returns A release plugin configured for GitLab release creation.\n */\nconst gitlab = (): ReleasePlugin =>\n createHostReleasePlugin({\n name: '@reelout/gitlab',\n version,\n host: 'gitlab',\n displayName: 'GitLab',\n tokenEnvKey: 'GITLAB_TOKEN',\n verifyToken,\n createRelease,\n })\n\nexport default gitlab\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { Gitlab } from '@gitbeaker/rest'\nimport type { GitRepository } from '@reelout/core'\n\n/**\n * Check if the target GitLab repository is public.\n *\n * Uses the GitBeaker REST API with the provided token to fetch the\n * visibility status of the specified repository.\n *\n * @param token GitLab authentication token\n * @param repository Target repository\n * @returns Promise that resolves to `true` if the repository is public\n */\nexport async function isRepositoryPublic(\n token: string,\n repository: GitRepository\n): Promise<boolean> {\n const api = new Gitlab({ token })\n\n const projectId = encodeURIComponent(`${repository.owner}/${repository.repo}`)\n\n const project = await api.Projects.show(projectId)\n\n return project.visibility === 'public'\n}\n"],"mappings":";;;;;;;;;;;;AAYA,SAAgB,gBAAgB,KAAuB;CAIrD,OAHgB,KAAwD,OACpE,UAAU,WAEI;AACpB;;;;;;;;;;;;;ACCA,eAAsB,cACpB,MACA,OACA,YACe;CACf,IAAI,CAAC,KAAK,SAAS,KAAK,MACtB;CAGF,IAAI;EACF,MAAM,MAAM,IAAI,OAAO,EAAE,MAAM,CAAC;EAEhC,MAAM,YAAY,mBAChB,GAAG,WAAW,MAAM,GAAG,WAAW,MACpC;EAEA,MAAM,IAAI,gBAAgB,OAAO,WAAW,KAAK,QAAQ,IAAI,IAAI;CACnE,SAAS,KAAK;EACZ,IAAI,gBAAgB,GAAG,GACrB;EAGF,MAAM;CACR;AACF;;;;;;;;;;AClBA,eAAsB,aACpB,KACA,WACA,SAC+B;CAC/B,IAAI;EACF,MAAM,UAAU,MAAM,IAAI,gBAAgB,KAAK,WAAW,OAAO;EAEjE,OAAO;GAAE,MAAM,QAAQ;GAAM,aAAa,QAAQ;EAA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W,MAAM,GAAG,WAAW,MAAM;CAE7E,IAAI;EACF,MAAM,IAAI,SAAS,KAAK,SAAS;CACnC,SAAS,KAAK;EACZ,MAAM,IAAI,MACR,gEACA,EAAE,OAAO,IAAI,CACf;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;ACTA,IAAM,eACJ,wBAAwB;CACtB,MAAM;CACN;CACA,MAAM;CACN,aAAa;CACb,aAAa;CACb;CACA;AACF,CAAC;;;;;;;;;;;;ACtBH,eAAsB,mBACpB,OACA,YACkB;CAClB,MAAM,MAAM,IAAI,OAAO,EAAE,MAAM,CAAC;CAEhC,MAAM,YAAY,mBAAmB,GAAG,WAAW,MAAM,GAAG,WAAW,MAAM;CAI7E,QAAO,MAFe,IAAI,SAAS,KAAK,SAAS,EAAA,CAElC,eAAe;AAChC"}
package/package.json CHANGED
@@ -1,15 +1,21 @@
1
1
  {
2
2
  "name": "@reelout/gitlab",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "GitLab plugin for publishing releases from ReelOut release plans.",
5
+ "keywords": [
6
+ "release",
7
+ "versioning",
8
+ "gitlab",
9
+ "releases"
10
+ ],
5
11
  "repository": {
6
12
  "type": "git",
7
13
  "url": "git+https://github.com/reelout/reelout.git",
8
14
  "directory": "packages/gitlab"
9
15
  },
10
16
  "license": "MIT",
17
+ "sideEffects": false,
11
18
  "type": "module",
12
- "imports": {},
13
19
  "exports": {
14
20
  "./package.json": {
15
21
  "default": "./package.json"
@@ -33,11 +39,14 @@
33
39
  ],
34
40
  "dependencies": {
35
41
  "@gitbeaker/rest": "^43.8.0",
36
- "@reelout/core": "^0.13.0"
42
+ "@reelout/core": "^0.14.0"
37
43
  },
38
44
  "engines": {
39
45
  "node": ">=24.15"
40
46
  },
47
+ "publishConfig": {
48
+ "access": "public"
49
+ },
41
50
  "scripts": {
42
51
  "build": "vite build --ssr --sourcemap",
43
52
  "dev": "vite build --ssr --watch"
package/src/gitlab.ts CHANGED
@@ -1,25 +1,12 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  // Copyright (c) 2026 Fai
3
3
 
4
- import type { ReleaseContext, ReleasePlugin } from '@reelout/core'
4
+ import { createHostReleasePlugin } from '@reelout/core'
5
+ import type { ReleasePlugin } from '@reelout/core'
5
6
  import { version } from '../package.json'
6
- import { createRelease, type ReleaseRollback } from './createRelease'
7
+ import { createRelease } from './createRelease'
7
8
  import { verifyToken } from './verifyToken'
8
9
 
9
- /**
10
- * Read the GitLab token from the release environment.
11
- *
12
- * Treats unset and whitespace-only values as missing.
13
- *
14
- * @param env Release environment variables
15
- * @returns The trimmed token, or undefined when it is not set
16
- */
17
- const readGitlabToken = (env: ReleaseContext['env']): string | undefined => {
18
- const token = env.GITLAB_TOKEN?.trim()
19
-
20
- return token ? token : undefined
21
- }
22
-
23
10
  /**
24
11
  * Built-in plugin that creates GitLab releases for finalized release plans.
25
12
  *
@@ -27,7 +14,7 @@ const readGitlabToken = (env: ReleaseContext['env']): string | undefined => {
27
14
  * **Lifecycle Stages:**
28
15
  * - `configure`: Leaves the plugin inactive when no GitLab-hosted repository
29
16
  * was detected. Otherwise verifies the `GITLAB_TOKEN` environment variable:
30
- * a missing token skips the plugin's `publish` step with a warning — or
17
+ * a missing token skips the plugin's `publish` step with a debug message — or
31
18
  * fails the run in strict mode — and a provided token is verified against
32
19
  * the release repository so an invalid token fails before any mutation,
33
20
  * including under dry-run.
@@ -40,87 +27,15 @@ const readGitlabToken = (env: ReleaseContext['env']): string | undefined => {
40
27
  *
41
28
  * @returns A release plugin configured for GitLab release creation.
42
29
  */
43
- const gitlab = (): ReleasePlugin => ({
44
- name: '@reelout/gitlab',
45
- version,
46
- configure: async (context, next) => {
47
- const repository = context.repository
48
-
49
- if (repository?.host !== 'gitlab') {
50
- context.logger.debug(
51
- 'GitLab releases will not be created: no GitLab-hosted repository was detected.'
52
- )
53
-
54
- return next(context)
55
- }
56
-
57
- const token = readGitlabToken(context.env)
58
-
59
- if (!token) {
60
- if (context.strict) {
61
- throw new Error(
62
- 'The GITLAB_TOKEN environment variable is required in strict mode.'
63
- )
64
- }
65
-
66
- context.logger.warn(
67
- 'GitLab releases will not be created: GITLAB_TOKEN is not set.'
68
- )
69
-
70
- return next(context)
71
- }
72
-
73
- await verifyToken(token, repository)
74
-
75
- return next(context)
76
- },
77
- publish: async (context, next) => {
78
- if (context.repository?.host !== 'gitlab') {
79
- context.logger.debug(
80
- 'GitLab publishing was skipped: no GitLab-hosted repository was detected.'
81
- )
82
-
83
- return next(context)
84
- }
85
-
86
- const token = readGitlabToken(context.env)
87
-
88
- if (!token) {
89
- return next(context)
90
- }
91
-
92
- if (context.dryRun) {
93
- context.logger.debug('[DRY RUN] GitLab releases will not be created.')
94
- return next(context)
95
- }
96
-
97
- const plans = context.plans.toSorted((a, b) =>
98
- (a.package.name || '').localeCompare(b.package.name || '')
99
- )
100
-
101
- const repository = context.repository
102
-
103
- const rollbacks: ReleaseRollback[] = []
104
-
105
- // Create releases in reverse order
106
- // so that the root package release is created last,
107
- // as it is often the most important one.
108
- for (const plan of plans.toReversed()) {
109
- const rollback = await createRelease(context, plan, token, repository)
110
-
111
- if (rollback) {
112
- rollbacks.push(rollback)
113
- }
114
- }
115
-
116
- try {
117
- return await next(context)
118
- } catch (err) {
119
- await Promise.allSettled(rollbacks.map((rollback) => rollback()))
120
-
121
- throw err
122
- }
123
- },
124
- })
30
+ const gitlab = (): ReleasePlugin =>
31
+ createHostReleasePlugin({
32
+ name: '@reelout/gitlab',
33
+ version,
34
+ host: 'gitlab',
35
+ displayName: 'GitLab',
36
+ tokenEnvKey: 'GITLAB_TOKEN',
37
+ verifyToken,
38
+ createRelease,
39
+ })
125
40
 
126
41
  export default gitlab