@reelout/gitlab 0.0.0 → 0.4.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Fai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.js CHANGED
@@ -1 +1,105 @@
1
- export {};
1
+ import { Gitlab } from "@gitbeaker/rest";
2
+ //#region src/createRelease.ts
3
+ /**
4
+ * Create a GitLab release for a package tag.
5
+ *
6
+ * Skips creation when the tag has no message. Uses the GitBeaker REST API
7
+ * with the provided token to create the release.
8
+ *
9
+ * @param context Release context containing commit and prerelease information
10
+ * @param plan Release plan containing the tag to publish
11
+ * @param token GitLab authentication token
12
+ * @param repository Target repository
13
+ * @returns Promise that resolves when the release is created
14
+ */
15
+ async function createRelease(context, plan, token, repository) {
16
+ if (!plan.release?.tag?.message) return;
17
+ const api = new Gitlab({ token });
18
+ const projectId = encodeURIComponent(`${repository.owner}/${repository.repo}`);
19
+ await api.ProjectReleases.create(projectId, {
20
+ name: plan.release.tag.name,
21
+ tag_name: plan.release.tag.name,
22
+ description: plan.release.tag.message,
23
+ ref: context.commit.hash
24
+ });
25
+ }
26
+ //#endregion
27
+ //#region src/deleteRelease.ts
28
+ /**
29
+ * Delete a GitLab release associated with a package tag.
30
+ *
31
+ * Skips deletion if the plan does not contain a valid tag name. Resolves gracefully
32
+ * if the release does not exist on GitLab (e.g., 404 status).
33
+ *
34
+ * @param plan Release plan containing the tag associated with the release to delete
35
+ * @param token GitLab authentication token
36
+ * @param repository Target repository
37
+ * @returns Promise that resolves when the release is deleted
38
+ */
39
+ async function deleteRelease(plan, token, repository) {
40
+ if (!plan.release?.tag?.name) return;
41
+ try {
42
+ const api = new Gitlab({ token });
43
+ const projectId = encodeURIComponent(`${repository.owner}/${repository.repo}`);
44
+ await api.ProjectReleases.remove(projectId, plan.release.tag.name);
45
+ } catch (err) {
46
+ if (err?.cause?.response?.status === 404) return;
47
+ throw err;
48
+ }
49
+ }
50
+ //#endregion
51
+ //#region package.json
52
+ var version = "0.4.0";
53
+ //#endregion
54
+ //#region src/gitlab.ts
55
+ /**
56
+ * Built-in plugin that creates GitLab releases for finalized release plans.
57
+ *
58
+ * @remarks
59
+ * **Lifecycle Stages:**
60
+ * - `publish`: Creates GitLab releases in reverse alphabetical package order (ensuring the root package release
61
+ * is created last). Automatically rolls back and deletes created releases if subsequent publishing stages fail.
62
+ *
63
+ * @throws {Error} If `context.repository` is not configured or `GITLAB_TOKEN` environment variable is missing.
64
+ * @returns A release plugin configured for GitLab release creation.
65
+ */
66
+ var gitlab = () => ({
67
+ name: "@reelout/gitlab",
68
+ version,
69
+ publish: async (context, next) => {
70
+ if (!context.repository) throw new Error("A Git repository is required to create a GitLab release.");
71
+ if (!context.env.GITLAB_TOKEN) throw new Error("The GITLAB_TOKEN environment variable is required.");
72
+ if (context.dryRun) return next(context);
73
+ const plans = context.plans.toSorted((a, b) => (a.package.name || "").localeCompare(b.package.name || ""));
74
+ const token = context.env.GITLAB_TOKEN;
75
+ const repository = context.repository;
76
+ for (const plan of plans.toReversed()) await createRelease(context, plan, token, repository);
77
+ try {
78
+ return await next(context);
79
+ } catch (err) {
80
+ await Promise.allSettled(plans.map((plan) => deleteRelease(plan, token, repository)));
81
+ throw err;
82
+ }
83
+ }
84
+ });
85
+ //#endregion
86
+ //#region src/isRepositoryPublic.ts
87
+ /**
88
+ * Check if the target GitLab repository is public.
89
+ *
90
+ * Uses the GitBeaker REST API with the provided token to fetch the
91
+ * visibility status of the specified repository.
92
+ *
93
+ * @param token GitLab authentication token
94
+ * @param repository Target repository
95
+ * @returns Promise that resolves to `true` if the repository is public
96
+ */
97
+ async function isRepositoryPublic(token, repository) {
98
+ const api = new Gitlab({ token });
99
+ const projectId = encodeURIComponent(`${repository.owner}/${repository.repo}`);
100
+ return (await api.Projects.show(projectId)).visibility === "public";
101
+ }
102
+ //#endregion
103
+ export { createRelease, gitlab as default, deleteRelease, isRepositoryPublic };
104
+
105
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/createRelease.ts","../src/deleteRelease.ts","../package.json","../src/gitlab.ts","../src/isRepositoryPublic.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport { Gitlab } from '@gitbeaker/rest'\nimport type { GitRepository, ReleaseContext, ReleasePlan } from '@reelout/core'\n\n/**\n * Create a GitLab release for a package tag.\n *\n * Skips creation when the tag has no message. Uses the GitBeaker REST API\n * with the provided token to create the release.\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 when the release is created\n */\nexport async function createRelease(\n context: ReleaseContext,\n plan: ReleasePlan,\n token: string,\n repository: GitRepository\n): Promise<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 await api.ProjectReleases.create(projectId, {\n name: plan.release.tag.name,\n tag_name: plan.release.tag.name,\n description: plan.release.tag.message,\n ref: context.commit.hash,\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'\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 const status = (err as { cause?: { response?: { status?: number } } })\n ?.cause?.response?.status\n\n if (status === 404) {\n return\n }\n\n throw err\n }\n}\n","{\n \"name\": \"@reelout/gitlab\",\n \"version\": \"0.4.0\",\n \"description\": \"GitLab integration for automating releases.\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/aicest/reelout.git\",\n \"directory\": \"packages/gitlab\"\n },\n \"license\": \"MIT\",\n \"type\": \"module\",\n \"imports\": {},\n \"exports\": {\n \"./package.json\": {\n \"default\": \"./package.json\"\n },\n \".\": {\n \"module\": \"./src/index.ts\",\n \"development\": \"./src/index.ts\",\n \"types\": \"./src/index.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"./*\": {\n \"module\": \"./src/*.ts\",\n \"development\": \"./src/*.ts\",\n \"types\": \"./src/*.ts\",\n \"default\": \"./dist/*.js\"\n }\n },\n \"files\": [\n \"./dist\",\n \"./src\"\n ],\n \"scripts\": {\n \"build\": \"vite build --ssr --sourcemap\",\n \"dev\": \"vite build --ssr --watch\"\n },\n \"dependencies\": {\n \"@gitbeaker/rest\": \"catalog:\",\n \"@reelout/core\": \"workspace:^\"\n },\n \"engines\": {\n \"node\": \">=24.15\"\n }\n}\n","// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport type { ReleasePlugin } from '@reelout/core'\nimport { version } from '../package.json'\nimport { createRelease } from './createRelease'\nimport { deleteRelease } from './deleteRelease'\n\n/**\n * Built-in plugin that creates GitLab releases for finalized release plans.\n *\n * @remarks\n * **Lifecycle Stages:**\n * - `publish`: Creates GitLab releases in reverse alphabetical package order (ensuring the root package release\n * is created last). Automatically rolls back and deletes created releases if subsequent publishing stages fail.\n *\n * @throws {Error} If `context.repository` is not configured or `GITLAB_TOKEN` environment variable is missing.\n * @returns A release plugin configured for GitLab release creation.\n */\nconst gitlab = (): ReleasePlugin => ({\n name: '@reelout/gitlab',\n version,\n publish: async (context, next) => {\n if (!context.repository) {\n throw new Error(\n 'A Git repository is required to create a GitLab release.'\n )\n }\n\n if (!context.env.GITLAB_TOKEN) {\n throw new Error('The GITLAB_TOKEN environment variable is required.')\n }\n\n if (context.dryRun) {\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 token = context.env.GITLAB_TOKEN\n\n const repository = context.repository\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 await createRelease(context, plan, token, repository)\n }\n\n try {\n return await next(context)\n } catch (err) {\n await Promise.allSettled(\n plans.map((plan) => deleteRelease(plan, token, repository))\n )\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":";;;;;;;;;;;;;;AAkBA,eAAsB,cACpB,SACA,MACA,OACA,YACe;CACf,IAAI,CAAC,KAAK,SAAS,KAAK,SACtB;CAGF,MAAM,MAAM,IAAI,OAAO,EAAE,MAAM,CAAC;CAEhC,MAAM,YAAY,mBAAmB,GAAG,WAAW,MAAM,GAAG,WAAW,MAAM;CAE7E,MAAM,IAAI,gBAAgB,OAAO,WAAW;EAC1C,MAAM,KAAK,QAAQ,IAAI;EACvB,UAAU,KAAK,QAAQ,IAAI;EAC3B,aAAa,KAAK,QAAQ,IAAI;EAC9B,KAAK,QAAQ,OAAO;CACtB,CAAC;AACH;;;;;;;;;;;;;;ACrBA,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;EAIZ,IAHgB,KACZ,OAAO,UAAU,WAEN,KACb;EAGF,MAAM;CACR;AACF;;;;;;;;;;;;;;;;;AEzBA,IAAM,gBAA+B;CACnC,MAAM;CACN;CACA,SAAS,OAAO,SAAS,SAAS;EAChC,IAAI,CAAC,QAAQ,YACX,MAAM,IAAI,MACR,0DACF;EAGF,IAAI,CAAC,QAAQ,IAAI,cACf,MAAM,IAAI,MAAM,oDAAoD;EAGtE,IAAI,QAAQ,QACV,OAAO,KAAK,OAAO;EAGrB,MAAM,QAAQ,QAAQ,MAAM,UAAU,GAAG,OACtC,EAAE,QAAQ,QAAQ,GAAA,CAAI,cAAc,EAAE,QAAQ,QAAQ,EAAE,CAC3D;EAEA,MAAM,QAAQ,QAAQ,IAAI;EAE1B,MAAM,aAAa,QAAQ;EAK3B,KAAK,MAAM,QAAQ,MAAM,WAAW,GAClC,MAAM,cAAc,SAAS,MAAM,OAAO,UAAU;EAGtD,IAAI;GACF,OAAO,MAAM,KAAK,OAAO;EAC3B,SAAS,KAAK;GACZ,MAAM,QAAQ,WACZ,MAAM,KAAK,SAAS,cAAc,MAAM,OAAO,UAAU,CAAC,CAC5D;GAEA,MAAM;EACR;CACF;AACF;;;;;;;;;;;;;AC9CA,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,6 +1,12 @@
1
1
  {
2
2
  "name": "@reelout/gitlab",
3
- "version": "0.0.0",
3
+ "version": "0.4.1",
4
+ "description": "GitLab integration for automating releases.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/aicest/reelout.git",
8
+ "directory": "packages/gitlab"
9
+ },
4
10
  "license": "MIT",
5
11
  "type": "module",
6
12
  "imports": {},
@@ -25,11 +31,15 @@
25
31
  "./dist",
26
32
  "./src"
27
33
  ],
34
+ "dependencies": {
35
+ "@gitbeaker/rest": "^43.8.0",
36
+ "@reelout/core": "^0.5.0"
37
+ },
38
+ "engines": {
39
+ "node": ">=24.15"
40
+ },
28
41
  "scripts": {
29
42
  "build": "vite build --ssr --sourcemap",
30
43
  "dev": "vite build --ssr --watch"
31
- },
32
- "engines": {
33
- "node": ">=24.11"
34
44
  }
35
- }
45
+ }
@@ -0,0 +1,39 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import { Gitlab } from '@gitbeaker/rest'
5
+ import type { GitRepository, ReleaseContext, ReleasePlan } from '@reelout/core'
6
+
7
+ /**
8
+ * Create a GitLab release for a package tag.
9
+ *
10
+ * Skips creation when the tag has no message. Uses the GitBeaker REST API
11
+ * with the provided token to create the release.
12
+ *
13
+ * @param context Release context containing commit and prerelease information
14
+ * @param plan Release plan containing the tag to publish
15
+ * @param token GitLab authentication token
16
+ * @param repository Target repository
17
+ * @returns Promise that resolves when the release is created
18
+ */
19
+ export async function createRelease(
20
+ context: ReleaseContext,
21
+ plan: ReleasePlan,
22
+ token: string,
23
+ repository: GitRepository
24
+ ): Promise<void> {
25
+ if (!plan.release?.tag?.message) {
26
+ return
27
+ }
28
+
29
+ const api = new Gitlab({ token })
30
+
31
+ const projectId = encodeURIComponent(`${repository.owner}/${repository.repo}`)
32
+
33
+ await api.ProjectReleases.create(projectId, {
34
+ name: plan.release.tag.name,
35
+ tag_name: plan.release.tag.name,
36
+ description: plan.release.tag.message,
37
+ ref: context.commit.hash,
38
+ })
39
+ }
@@ -0,0 +1,45 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import { Gitlab } from '@gitbeaker/rest'
5
+ import type { GitRepository, ReleasePlan } from '@reelout/core'
6
+
7
+ /**
8
+ * Delete a GitLab release associated with a package tag.
9
+ *
10
+ * Skips deletion if the plan does not contain a valid tag name. Resolves gracefully
11
+ * if the release does not exist on GitLab (e.g., 404 status).
12
+ *
13
+ * @param plan Release plan containing the tag associated with the release to delete
14
+ * @param token GitLab authentication token
15
+ * @param repository Target repository
16
+ * @returns Promise that resolves when the release is deleted
17
+ */
18
+ export async function deleteRelease(
19
+ plan: ReleasePlan,
20
+ token: string,
21
+ repository: GitRepository
22
+ ): Promise<void> {
23
+ if (!plan.release?.tag?.name) {
24
+ return
25
+ }
26
+
27
+ try {
28
+ const api = new Gitlab({ token })
29
+
30
+ const projectId = encodeURIComponent(
31
+ `${repository.owner}/${repository.repo}`
32
+ )
33
+
34
+ await api.ProjectReleases.remove(projectId, plan.release.tag.name)
35
+ } catch (err) {
36
+ const status = (err as { cause?: { response?: { status?: number } } })
37
+ ?.cause?.response?.status
38
+
39
+ if (status === 404) {
40
+ return
41
+ }
42
+
43
+ throw err
44
+ }
45
+ }
package/src/gitlab.ts ADDED
@@ -0,0 +1,65 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import type { ReleasePlugin } from '@reelout/core'
5
+ import { version } from '../package.json'
6
+ import { createRelease } from './createRelease'
7
+ import { deleteRelease } from './deleteRelease'
8
+
9
+ /**
10
+ * Built-in plugin that creates GitLab releases for finalized release plans.
11
+ *
12
+ * @remarks
13
+ * **Lifecycle Stages:**
14
+ * - `publish`: Creates GitLab releases in reverse alphabetical package order (ensuring the root package release
15
+ * is created last). Automatically rolls back and deletes created releases if subsequent publishing stages fail.
16
+ *
17
+ * @throws {Error} If `context.repository` is not configured or `GITLAB_TOKEN` environment variable is missing.
18
+ * @returns A release plugin configured for GitLab release creation.
19
+ */
20
+ const gitlab = (): ReleasePlugin => ({
21
+ name: '@reelout/gitlab',
22
+ version,
23
+ publish: async (context, next) => {
24
+ if (!context.repository) {
25
+ throw new Error(
26
+ 'A Git repository is required to create a GitLab release.'
27
+ )
28
+ }
29
+
30
+ if (!context.env.GITLAB_TOKEN) {
31
+ throw new Error('The GITLAB_TOKEN environment variable is required.')
32
+ }
33
+
34
+ if (context.dryRun) {
35
+ return next(context)
36
+ }
37
+
38
+ const plans = context.plans.toSorted((a, b) =>
39
+ (a.package.name || '').localeCompare(b.package.name || '')
40
+ )
41
+
42
+ const token = context.env.GITLAB_TOKEN
43
+
44
+ const repository = context.repository
45
+
46
+ // Create releases in reverse order
47
+ // so that the root package release is created last,
48
+ // as it is often the most important one.
49
+ for (const plan of plans.toReversed()) {
50
+ await createRelease(context, plan, token, repository)
51
+ }
52
+
53
+ try {
54
+ return await next(context)
55
+ } catch (err) {
56
+ await Promise.allSettled(
57
+ plans.map((plan) => deleteRelease(plan, token, repository))
58
+ )
59
+
60
+ throw err
61
+ }
62
+ },
63
+ })
64
+
65
+ export default gitlab
package/src/index.ts CHANGED
@@ -1,3 +1,8 @@
1
- // Copyright (c) 2026 Fai Chen. Licensed under the MIT License.
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
2
3
 
3
- export {}
4
+ export * from './createRelease'
5
+ export * from './deleteRelease'
6
+ export * from './gitlab'
7
+ export { default } from './gitlab'
8
+ export * from './isRepositoryPublic'
@@ -0,0 +1,28 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import { Gitlab } from '@gitbeaker/rest'
5
+ import type { GitRepository } from '@reelout/core'
6
+
7
+ /**
8
+ * Check if the target GitLab repository is public.
9
+ *
10
+ * Uses the GitBeaker REST API with the provided token to fetch the
11
+ * visibility status of the specified repository.
12
+ *
13
+ * @param token GitLab authentication token
14
+ * @param repository Target repository
15
+ * @returns Promise that resolves to `true` if the repository is public
16
+ */
17
+ export async function isRepositoryPublic(
18
+ token: string,
19
+ repository: GitRepository
20
+ ): Promise<boolean> {
21
+ const api = new Gitlab({ token })
22
+
23
+ const projectId = encodeURIComponent(`${repository.owner}/${repository.repo}`)
24
+
25
+ const project = await api.Projects.show(projectId)
26
+
27
+ return project.visibility === 'public'
28
+ }