opencode-gitlab-plugin 3.2.0 → 3.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
4
4
 
5
+ ## [3.2.1](https://gitlab.com/vglafirov/opencode-gitlab-plugin/compare/v3.2.0...v3.2.1) (2026-10-25)
6
+
7
+
8
+ ### 🐛 Bug Fixes
9
+
10
+ * **auth:** read GitLab credentials from the OpenCode v2 store ([a039ea3](https://gitlab.com/vglafirov/opencode-gitlab-plugin/commit/a039ea3345db77973791d36f77716b9cd6e7bdc3))
11
+
5
12
  ## [3.2.0](https://gitlab.com/vglafirov/opencode-gitlab-plugin/compare/v3.1.0...v3.2.0) (2026-10-25)
6
13
 
7
14
 
package/dist/index.js CHANGED
@@ -2819,36 +2819,70 @@ applyMixins(UnifiedGitLabClient, [
2819
2819
  ]);
2820
2820
 
2821
2821
  // src/utils.ts
2822
+ var integrationToken;
2823
+ function setIntegrationToken(token) {
2824
+ integrationToken = token || void 0;
2825
+ }
2826
+ function credentialToToken(value) {
2827
+ if (!value || typeof value !== "object") {
2828
+ return void 0;
2829
+ }
2830
+ const credential = value;
2831
+ if (credential["type"] === "oauth") {
2832
+ const access = credential["access"];
2833
+ if (typeof access !== "string" || !access) {
2834
+ return void 0;
2835
+ }
2836
+ return isExpired(credential["expires"]) ? void 0 : access;
2837
+ }
2838
+ if (typeof credential["key"] === "string" && credential["key"]) {
2839
+ return credential["key"];
2840
+ }
2841
+ if (typeof credential["token"] === "string" && credential["token"]) {
2842
+ return credential["token"];
2843
+ }
2844
+ return void 0;
2845
+ }
2846
+ function isExpired(expires) {
2847
+ return typeof expires === "number" && expires > 0 && expires <= Date.now();
2848
+ }
2822
2849
  function readTokenFromAuthStorage() {
2823
2850
  try {
2824
2851
  const authPath = path.join(os.homedir(), ".local", "share", "opencode", "auth.json");
2825
2852
  if (!fs.existsSync(authPath)) {
2826
- return void 0;
2853
+ return {};
2827
2854
  }
2828
2855
  const authData = JSON.parse(fs.readFileSync(authPath, "utf-8"));
2829
2856
  const gitlabAuth = authData?.gitlab;
2830
2857
  if (!gitlabAuth) {
2831
- return void 0;
2858
+ return {};
2832
2859
  }
2833
- if (gitlabAuth.type === "oauth" && gitlabAuth.access) {
2834
- return gitlabAuth.access;
2860
+ const token = credentialToToken(gitlabAuth);
2861
+ if (token) {
2862
+ return { token };
2835
2863
  }
2836
- if (gitlabAuth.type === "api" && gitlabAuth.key) {
2837
- return gitlabAuth.key;
2864
+ if (gitlabAuth.type === "oauth" && isExpired(gitlabAuth.expires)) {
2865
+ return { expired: new Date(gitlabAuth.expires) };
2838
2866
  }
2839
- return gitlabAuth.token || void 0;
2867
+ return {};
2840
2868
  } catch (error) {
2841
- return void 0;
2869
+ return {};
2842
2870
  }
2843
2871
  }
2844
2872
  function getGitLabClient() {
2845
- let token = process.env["GITLAB_TOKEN"];
2873
+ let token = process.env["GITLAB_TOKEN"] || integrationToken;
2874
+ let expired;
2846
2875
  if (!token) {
2847
- token = readTokenFromAuthStorage();
2876
+ ({ token, expired } = readTokenFromAuthStorage());
2848
2877
  }
2849
2878
  if (!token) {
2879
+ if (expired) {
2880
+ throw new Error(
2881
+ `GitLab OAuth token in ~/.local/share/opencode/auth.json expired on ${expired.toISOString()}. Re-authenticate GitLab in OpenCode or set the GITLAB_TOKEN environment variable.`
2882
+ );
2883
+ }
2850
2884
  throw new Error(
2851
- "GitLab API token not found. Set GITLAB_TOKEN environment variable or configure it in OpenCode auth storage (~/.local/share/opencode/auth.json)."
2885
+ "GitLab API token not found. Set GITLAB_TOKEN environment variable or connect GitLab in OpenCode."
2852
2886
  );
2853
2887
  }
2854
2888
  const instanceUrl = process.env["GITLAB_INSTANCE_URL"] || "https://gitlab.com";
@@ -6070,6 +6104,7 @@ function adaptTool(name, definition, options) {
6070
6104
  input: toInputSchema(definition.args),
6071
6105
  async execute(input, context) {
6072
6106
  const parsed = validator.parse(input ?? {});
6107
+ await options.beforeExecute?.(context);
6073
6108
  const legacyContext = toLegacyContext(context, options.directory, options.worktree);
6074
6109
  const result = await definition.execute(
6075
6110
  parsed,
@@ -6085,6 +6120,19 @@ function adaptTools(tools, options) {
6085
6120
 
6086
6121
  // src/v2/plugin.ts
6087
6122
  var PLUGIN_ID = "gitlab";
6123
+ var GITLAB_INTEGRATION_ID = "gitlab";
6124
+ async function refreshIntegrationToken(ctx) {
6125
+ const integration = ctx.integration;
6126
+ if (!integration?.connection) {
6127
+ return;
6128
+ }
6129
+ try {
6130
+ const connection = await integration.connection.active(GITLAB_INTEGRATION_ID);
6131
+ const resolved = connection ? await integration.connection.resolve(connection) : void 0;
6132
+ setIntegrationToken(credentialToToken(resolved));
6133
+ } catch {
6134
+ }
6135
+ }
6088
6136
  var LAZY_MCP_HINT = `## GitLab Tools via lazy-mcp
6089
6137
  GitLab API tools (MRs, issues, pipelines, security, search, repos, users, todos, work items, discussions, notes, audit, git, award emoji) are served via the "gitlab" MCP server through lazy-mcp. Use lazy-mcp_list_commands with server "gitlab" to discover and call them.
6090
6138
  DAP tools (agents, flows, memory, skills) are on the "gitlab-dap" server instead.`;
@@ -6099,7 +6147,11 @@ var gitlabPluginV2 = Plugin.define({
6099
6147
  }
6100
6148
  const directory = ctx.location.directory;
6101
6149
  const worktree = ctx.location.project.directory ?? directory;
6102
- const tools = adaptTools(allTools, { directory, worktree });
6150
+ const tools = adaptTools(allTools, {
6151
+ directory,
6152
+ worktree,
6153
+ beforeExecute: () => refreshIntegrationToken(ctx)
6154
+ });
6103
6155
  await ctx.tool.transform((editor) => {
6104
6156
  for (const definition of tools) {
6105
6157
  editor.add(definition);