@bonvoy/plugin-gitlab 0.2.0 → 0.2.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.
@@ -0,0 +1,43 @@
1
+ import { BonvoyPlugin } from "@bonvoy/core";
2
+
3
+ //#region src/operations.d.ts
4
+ interface GitLabReleaseParams {
5
+ projectId: string | number;
6
+ tagName: string;
7
+ name: string;
8
+ description: string;
9
+ }
10
+ interface GitLabMRParams {
11
+ projectId: string | number;
12
+ title: string;
13
+ description: string;
14
+ sourceBranch: string;
15
+ targetBranch: string;
16
+ }
17
+ interface GitLabMRResult {
18
+ url: string;
19
+ iid: number;
20
+ }
21
+ interface GitLabOperations {
22
+ createRelease(token: string, host: string, params: GitLabReleaseParams): Promise<void>;
23
+ createMR(token: string, host: string, params: GitLabMRParams): Promise<GitLabMRResult>;
24
+ }
25
+ declare const defaultGitLabOperations: GitLabOperations;
26
+ //#endregion
27
+ //#region src/gitlab.d.ts
28
+ interface GitLabPluginOptions {
29
+ token?: string;
30
+ host?: string;
31
+ projectId?: string | number;
32
+ }
33
+ declare class GitLabPlugin implements BonvoyPlugin {
34
+ name: string;
35
+ private options;
36
+ private ops;
37
+ constructor(options?: GitLabPluginOptions, ops?: GitLabOperations);
38
+ apply(bonvoy: any): void;
39
+ private getProjectId;
40
+ }
41
+ //#endregion
42
+ export { type GitLabOperations, type GitLabPluginOptions, type GitLabReleaseParams, GitLabPlugin as default, defaultGitLabOperations };
43
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs ADDED
@@ -0,0 +1,118 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { Gitlab } from "@gitbeaker/rest";
4
+
5
+ //#region src/operations.ts
6
+ const defaultGitLabOperations = {
7
+ async createRelease(token, host, params) {
8
+ await new Gitlab({
9
+ token,
10
+ host
11
+ }).ProjectReleases.create(params.projectId, {
12
+ tagName: params.tagName,
13
+ name: params.name,
14
+ description: params.description
15
+ });
16
+ },
17
+ async createMR(token, host, params) {
18
+ const mr = await new Gitlab({
19
+ token,
20
+ host
21
+ }).MergeRequests.create(params.projectId, params.sourceBranch, params.targetBranch, params.title, { description: params.description });
22
+ return {
23
+ url: mr.web_url,
24
+ iid: mr.iid
25
+ };
26
+ }
27
+ };
28
+
29
+ //#endregion
30
+ //#region src/gitlab.ts
31
+ var GitLabPlugin = class {
32
+ name = "gitlab";
33
+ options;
34
+ ops;
35
+ constructor(options = {}, ops) {
36
+ this.options = options;
37
+ this.ops = ops ?? defaultGitLabOperations;
38
+ }
39
+ apply(bonvoy) {
40
+ bonvoy.hooks.makeRelease.tapPromise(this.name, async (context) => {
41
+ if (context.isDryRun) {
42
+ context.logger.info("🔍 [dry-run] Would create GitLab releases");
43
+ return;
44
+ }
45
+ const token = this.options.token || process.env.GITLAB_TOKEN;
46
+ if (!token) {
47
+ context.logger.warn("⚠️ GITLAB_TOKEN not found, skipping GitLab releases");
48
+ return;
49
+ }
50
+ const host = this.options.host || process.env.GITLAB_HOST || "https://gitlab.com";
51
+ const projectId = this.getProjectId(context.rootPath);
52
+ for (const pkg of context.changedPackages) {
53
+ const version = context.versions[pkg.name];
54
+ const changelog = context.changelogs[pkg.name] || "";
55
+ const tagName = `${pkg.name}@${version}`;
56
+ try {
57
+ await this.ops.createRelease(token, host, {
58
+ projectId,
59
+ tagName,
60
+ name: `${pkg.name} v${version}`,
61
+ description: changelog
62
+ });
63
+ context.logger.info(`✅ Created GitLab release: ${tagName}`);
64
+ } catch (error) {
65
+ const errorMessage = error instanceof Error ? error.message : String(error);
66
+ context.logger.error(`❌ Failed to create release for ${tagName}: ${errorMessage}`);
67
+ throw error;
68
+ }
69
+ }
70
+ });
71
+ bonvoy.hooks.createPR.tapPromise(this.name, async (context) => {
72
+ if (context.isDryRun) {
73
+ context.logger.info("🔍 [dry-run] Would create GitLab MR");
74
+ return;
75
+ }
76
+ const token = this.options.token || process.env.GITLAB_TOKEN;
77
+ if (!token) {
78
+ context.logger.warn("⚠️ GITLAB_TOKEN not found, skipping MR creation");
79
+ return;
80
+ }
81
+ const host = this.options.host || process.env.GITLAB_HOST || "https://gitlab.com";
82
+ const projectId = this.getProjectId(context.rootPath);
83
+ try {
84
+ const result = await this.ops.createMR(token, host, {
85
+ projectId,
86
+ title: context.title,
87
+ description: context.body,
88
+ sourceBranch: context.branchName,
89
+ targetBranch: context.baseBranch
90
+ });
91
+ context.prUrl = result.url;
92
+ context.prNumber = result.iid;
93
+ context.logger.info(`✅ Created GitLab MR: ${result.url}`);
94
+ } catch (error) {
95
+ const errorMessage = error instanceof Error ? error.message : String(error);
96
+ context.logger.error(`❌ Failed to create MR: ${errorMessage}`);
97
+ throw error;
98
+ }
99
+ });
100
+ }
101
+ getProjectId(rootPath) {
102
+ if (this.options.projectId) return this.options.projectId;
103
+ try {
104
+ const pkgPath = join(rootPath, "package.json");
105
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
106
+ const repoUrl = typeof pkg.repository === "string" ? pkg.repository : pkg.repository?.url;
107
+ if (repoUrl) {
108
+ const match = repoUrl.match(/gitlab\.com[:/](.+?)(?:\.git)?$/);
109
+ if (match) return encodeURIComponent(match[1]);
110
+ }
111
+ } catch {}
112
+ throw new Error("Could not determine GitLab project. Please set \"repository\" in package.json or provide projectId in plugin options.");
113
+ }
114
+ };
115
+
116
+ //#endregion
117
+ export { GitLabPlugin as default, defaultGitLabOperations };
118
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/operations.ts","../src/gitlab.ts"],"sourcesContent":["import { Gitlab } from '@gitbeaker/rest';\n\nexport interface GitLabReleaseParams {\n projectId: string | number;\n tagName: string;\n name: string;\n description: string;\n}\n\nexport interface GitLabMRParams {\n projectId: string | number;\n title: string;\n description: string;\n sourceBranch: string;\n targetBranch: string;\n}\n\nexport interface GitLabMRResult {\n url: string;\n iid: number;\n}\n\nexport interface GitLabOperations {\n createRelease(token: string, host: string, params: GitLabReleaseParams): Promise<void>;\n createMR(token: string, host: string, params: GitLabMRParams): Promise<GitLabMRResult>;\n}\n\nexport const defaultGitLabOperations: GitLabOperations = {\n /* v8 ignore start */\n async createRelease(token, host, params) {\n const api = new Gitlab({ token, host });\n await api.ProjectReleases.create(params.projectId, {\n tagName: params.tagName,\n name: params.name,\n description: params.description,\n });\n },\n\n async createMR(token, host, params) {\n const api = new Gitlab({ token, host });\n const mr = await api.MergeRequests.create(\n params.projectId,\n params.sourceBranch,\n params.targetBranch,\n params.title,\n {\n description: params.description,\n },\n );\n return { url: mr.web_url, iid: mr.iid };\n },\n /* v8 ignore stop */\n};\n","import { readFileSync } from 'node:fs';\nimport { join } from 'node:path';\n\nimport type { BonvoyPlugin, PRContext, ReleaseContext } from '@bonvoy/core';\n\nimport { defaultGitLabOperations, type GitLabOperations } from './operations.js';\n\nexport interface GitLabPluginOptions {\n token?: string;\n host?: string;\n projectId?: string | number;\n}\n\nexport default class GitLabPlugin implements BonvoyPlugin {\n name = 'gitlab';\n private options: GitLabPluginOptions;\n private ops: GitLabOperations;\n\n constructor(options: GitLabPluginOptions = {}, ops?: GitLabOperations) {\n this.options = options;\n this.ops = ops ?? defaultGitLabOperations;\n }\n\n // biome-ignore lint/suspicious/noExplicitAny: Bonvoy type causes circular dependency\n apply(bonvoy: any): void {\n bonvoy.hooks.makeRelease.tapPromise(this.name, async (context: ReleaseContext) => {\n if (context.isDryRun) {\n context.logger.info('🔍 [dry-run] Would create GitLab releases');\n return;\n }\n\n const token = this.options.token || process.env.GITLAB_TOKEN;\n if (!token) {\n context.logger.warn('⚠️ GITLAB_TOKEN not found, skipping GitLab releases');\n return;\n }\n\n const host = this.options.host || process.env.GITLAB_HOST || 'https://gitlab.com';\n const projectId = this.getProjectId(context.rootPath);\n\n for (const pkg of context.changedPackages) {\n const version = context.versions[pkg.name];\n const changelog = context.changelogs[pkg.name] || '';\n const tagName = `${pkg.name}@${version}`;\n\n try {\n await this.ops.createRelease(token, host, {\n projectId,\n tagName,\n name: `${pkg.name} v${version}`,\n description: changelog,\n });\n\n context.logger.info(`✅ Created GitLab release: ${tagName}`);\n } catch (error: unknown) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n context.logger.error(`❌ Failed to create release for ${tagName}: ${errorMessage}`);\n throw error;\n }\n }\n });\n\n // MR creation hook\n bonvoy.hooks.createPR.tapPromise(this.name, async (context: PRContext) => {\n if (context.isDryRun) {\n context.logger.info('🔍 [dry-run] Would create GitLab MR');\n return;\n }\n\n const token = this.options.token || process.env.GITLAB_TOKEN;\n if (!token) {\n context.logger.warn('⚠️ GITLAB_TOKEN not found, skipping MR creation');\n return;\n }\n\n const host = this.options.host || process.env.GITLAB_HOST || 'https://gitlab.com';\n const projectId = this.getProjectId(context.rootPath);\n\n try {\n const result = await this.ops.createMR(token, host, {\n projectId,\n title: context.title,\n description: context.body,\n sourceBranch: context.branchName,\n targetBranch: context.baseBranch,\n });\n\n context.prUrl = result.url;\n context.prNumber = result.iid;\n context.logger.info(`✅ Created GitLab MR: ${result.url}`);\n } catch (error: unknown) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n context.logger.error(`❌ Failed to create MR: ${errorMessage}`);\n throw error;\n }\n });\n }\n\n private getProjectId(rootPath: string): string | number {\n if (this.options.projectId) {\n return this.options.projectId;\n }\n\n // Try to read from package.json repository field\n try {\n const pkgPath = join(rootPath, 'package.json');\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));\n const repoUrl = typeof pkg.repository === 'string' ? pkg.repository : pkg.repository?.url;\n\n if (repoUrl) {\n // Match gitlab.com/group/project or gitlab.com/group/subgroup/project\n const match = repoUrl.match(/gitlab\\.com[:/](.+?)(?:\\.git)?$/);\n if (match) {\n return encodeURIComponent(match[1]);\n }\n }\n } catch {\n // Ignore error\n }\n\n throw new Error(\n 'Could not determine GitLab project. Please set \"repository\" in package.json or provide projectId in plugin options.',\n );\n }\n}\n\nexport {\n defaultGitLabOperations,\n type GitLabMRParams,\n type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Aa,IAAI,YAAY;AAEtF,OAAI,SAAS;IAEX,MAAM,QAAQ,QAAQ,MAAM,kCAAkC;AAC9D,QAAI,MACF,QAAO,mBAAmB,MAAM,GAAG;;UAGjC;AAIR,QAAM,IAAI,MACR,wHACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bonvoy/plugin-gitlab",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "🚢 GitLab releases plugin for bonvoy",
5
5
  "keywords": [
6
6
  "bonvoy",
@@ -35,7 +35,7 @@
35
35
  "test": "vitest"
36
36
  },
37
37
  "dependencies": {
38
- "@bonvoy/core": "^0.1.0",
38
+ "@bonvoy/core": "^0.3.0",
39
39
  "@gitbeaker/rest": "^42.5.0"
40
40
  },
41
41
  "engines": {