@foundation0/git 1.2.1 → 1.2.2

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/mcp/src/cli.ts CHANGED
@@ -41,14 +41,18 @@ if (hasFlag('--help') || hasFlag('-h')) {
41
41
  process.exit(0)
42
42
  }
43
43
 
44
- const owner = getArgValue('--default-owner', process.env.GITEA_TEST_OWNER ?? 'example-org')
45
- const repo = getArgValue('--default-repo', process.env.GITEA_TEST_REPO ?? 'example-repo')
46
- const host = getArgValue('--gitea-host', process.env.GITEA_HOST ?? process.env.EXAMPLE_GITEA_HOST ?? 'https://gitea.example.com')?.trim()
44
+ const owner = getArgValue('--default-owner')?.trim()
45
+ const repo = getArgValue('--default-repo')?.trim()
46
+ const host = getArgValue('--gitea-host', process.env.GITEA_HOST)?.trim()
47
47
  const token = process.env.GITEA_TOKEN
48
48
  const serverName = getArgValue('--server-name', 'f0-git-mcp')
49
49
  const serverVersion = getArgValue('--server-version', '1.0.0')
50
50
  const toolsPrefix = getArgValue('--tools-prefix') ?? process.env.MCP_TOOLS_PREFIX
51
51
 
52
+ if (!host) {
53
+ throw new Error('GITEA_HOST is required. Set process.env.GITEA_HOST or pass --gitea-host.')
54
+ }
55
+
52
56
  if (isInsecureHttpUrl(host) && !hasFlag('--allow-insecure-http')) {
53
57
  throw new Error(
54
58
  'Refusing to send requests to an insecure http:// Gitea host. Use https:// or pass --allow-insecure-http if you really need this for local testing.',
@@ -63,8 +67,8 @@ void runGitMcpServer({
63
67
  giteaHost: host,
64
68
  giteaToken: token,
65
69
  },
66
- defaultOwner: owner,
67
- defaultRepo: repo,
70
+ ...(owner ? { defaultOwner: owner } : {}),
71
+ ...(repo ? { defaultRepo: repo } : {}),
68
72
  toolsPrefix,
69
73
  }).catch((error) => {
70
74
  console.error('Failed to start MCP git server', error)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foundation0/git",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Foundation 0 Git API and MCP server",
5
5
  "type": "module",
6
6
  "bin": {
@@ -218,6 +218,22 @@ const buildUrl = (
218
218
  return url.toString()
219
219
  }
220
220
 
221
+ const unresolvedPathParamPattern = /^\{[^{}]+\}$/
222
+
223
+ const assertResolvedMappedPath = (
224
+ mappedPath: string[],
225
+ featurePath: string[],
226
+ ): void => {
227
+ const unresolved = mappedPath.filter((segment) => unresolvedPathParamPattern.test(segment))
228
+ if (unresolved.length === 0) {
229
+ return
230
+ }
231
+
232
+ throw new Error(
233
+ `Missing required path arguments for "${featurePath.join('.')}". Unresolved parameters: ${unresolved.join(', ')}`,
234
+ )
235
+ }
236
+
221
237
  const canUseAbortSignalTimeout = (): boolean =>
222
238
  typeof AbortSignal !== 'undefined' && typeof (AbortSignal as unknown as { timeout?: unknown }).timeout === 'function'
223
239
 
@@ -369,6 +385,7 @@ const createMethod = (
369
385
 
370
386
  return segment
371
387
  })
388
+ assertResolvedMappedPath(hydratedPath, feature.path)
372
389
 
373
390
  const requestBody = buildRequestBody(mapping.method, bodyOptions, unhandled)
374
391
  const headers = {
@@ -530,8 +547,8 @@ export const createGitServiceApi = (options: GitServiceApiFactoryOptions = {}):
530
547
  const log = options.log
531
548
 
532
549
  const defaults = {
533
- defaultOwner: options.defaultOwner ?? process.env.GITEA_TEST_OWNER ?? 'example-org',
534
- defaultRepo: options.defaultRepo ?? process.env.GITEA_TEST_REPO ?? 'example-repo',
550
+ defaultOwner: options.defaultOwner,
551
+ defaultRepo: options.defaultRepo,
535
552
  }
536
553
 
537
554
  const root: GitServiceApi = {}
@@ -562,4 +579,24 @@ export const createGitServiceApi = (options: GitServiceApiFactoryOptions = {}):
562
579
  return root
563
580
  }
564
581
 
565
- export const gitServiceApi = createGitServiceApi()
582
+ const createUnavailableGitServiceApi = (error: Error): GitServiceApi => {
583
+ return new Proxy(
584
+ {},
585
+ {
586
+ get: (): never => {
587
+ throw error
588
+ },
589
+ },
590
+ ) as GitServiceApi
591
+ }
592
+
593
+ export const gitServiceApi: GitServiceApi = (() => {
594
+ try {
595
+ return createGitServiceApi()
596
+ } catch (error) {
597
+ const message = error instanceof Error ? error.message : String(error)
598
+ return createUnavailableGitServiceApi(
599
+ new Error(`Failed to initialize gitServiceApi singleton: ${message}`),
600
+ )
601
+ }
602
+ })()
@@ -2,7 +2,6 @@ import type { GitServiceApiExecutionResult } from './git-service-api'
2
2
  import { spawn } from 'node:child_process'
3
3
  import crypto from 'node:crypto'
4
4
 
5
- const DEFAULT_GITEA_HOST = 'https://gitea.example.com'
6
5
  const DEFAULT_REQUEST_TIMEOUT_MS = 60_000
7
6
 
8
7
  const parseRequestTimeoutMs = (value: unknown): number | null => {
@@ -274,6 +273,14 @@ const resolveGiteaApiBase = (host: string): string => {
274
273
  return trimmed.endsWith('/api/v1') ? trimmed : `${trimmed}/api/v1`
275
274
  }
276
275
 
276
+ const resolveRequiredGiteaHost = (host: string | undefined): string => {
277
+ const resolved = host?.trim() ?? process.env.GITEA_HOST?.trim()
278
+ if (!resolved) {
279
+ throw new Error('GITEA_HOST is required. Pass host explicitly or set process.env.GITEA_HOST.')
280
+ }
281
+ return resolved
282
+ }
283
+
277
284
  const buildIssueDependenciesUrl = (host: string, owner: string, repo: string, issueNumber: number): string => {
278
285
  return `${resolveGiteaApiBase(host)}/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/issues/${issueNumber}/dependencies`
279
286
  }
@@ -283,11 +290,12 @@ export async function callIssueDependenciesApi(
283
290
  owner: string,
284
291
  repo: string,
285
292
  issueNumber: number,
286
- host: string = DEFAULT_GITEA_HOST,
293
+ host: string | undefined,
287
294
  token: string | undefined,
288
295
  payload?: GitIssueDependencyPayload
289
296
  ): Promise<GitServiceApiExecutionResult<unknown>> {
290
- const requestUrl = buildIssueDependenciesUrl(host, owner, repo, issueNumber)
297
+ const resolvedHost = resolveRequiredGiteaHost(host)
298
+ const requestUrl = buildIssueDependenciesUrl(resolvedHost, owner, repo, issueNumber)
291
299
  const headers = {
292
300
  Accept: 'application/json',
293
301
  ...(token ? { Authorization: `token ${token}` } : {}),
@@ -343,7 +351,7 @@ export async function callIssueDependenciesApi(
343
351
  method,
344
352
  query: [],
345
353
  headers: [],
346
- apiBase: resolveGiteaApiBase(host),
354
+ apiBase: resolveGiteaApiBase(resolvedHost),
347
355
  swaggerPath: '/repos/{owner}/{repo}/issues/{index}/dependencies',
348
356
  mapped: true,
349
357
  },
@@ -8,7 +8,6 @@ export interface GitPlatformConfig {
8
8
  giteaSwaggerPath?: string
9
9
  }
10
10
 
11
- const DEFAULT_GITEA_HOST = 'https://gitea.example.com'
12
11
  const DEFAULT_PLATFORM: PlatformName = 'GITEA'
13
12
  const DEFAULT_GITEA_SWAGGER_PATH = '/swagger.v1.json'
14
13
 
@@ -34,8 +33,7 @@ export const getGitPlatformConfig = (overrides: Partial<GitPlatformConfig> = {})
34
33
 
35
34
  const giteaHost =
36
35
  overrides.giteaHost ??
37
- process.env.GITEA_HOST ??
38
- DEFAULT_GITEA_HOST
36
+ process.env.GITEA_HOST
39
37
 
40
38
  const giteaToken =
41
39
  overrides.giteaToken ??
@@ -50,9 +48,13 @@ export const getGitPlatformConfig = (overrides: Partial<GitPlatformConfig> = {})
50
48
  process.env.GITEA_SWAGGER_PATH ??
51
49
  DEFAULT_GITEA_SWAGGER_PATH
52
50
 
51
+ if (!giteaHost || giteaHost.trim().length === 0) {
52
+ throw new Error('GITEA_HOST is required. Set process.env.GITEA_HOST or pass config.giteaHost explicitly.')
53
+ }
54
+
53
55
  return {
54
56
  platform,
55
- giteaHost,
57
+ giteaHost: giteaHost.trim(),
56
58
  giteaToken,
57
59
  giteaApiVersion,
58
60
  giteaSwaggerPath,