@gitkraken/core-gitlens 0.46.0 → 0.48.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/CHANGELOG.md +19 -1
- package/dist/git-cli/providers/branches.js +8 -4
- package/dist/git-cli/providers/branches.js.map +1 -1
- package/dist/plus/ai/providers/anthropicProvider.js +0 -20
- package/dist/plus/ai/providers/anthropicProvider.js.map +1 -1
- package/dist/plus/git-github/api/enterprisePullRequestMergePolicy.d.ts +31 -0
- package/dist/plus/git-github/api/enterprisePullRequestMergePolicy.js +166 -0
- package/dist/plus/git-github/api/enterprisePullRequestMergePolicy.js.map +1 -0
- package/dist/plus/git-github/api/github.d.ts +7 -4
- package/dist/plus/git-github/api/github.js +44 -14
- package/dist/plus/git-github/api/github.js.map +1 -1
- package/dist/plus/git-github/api/issueWrites.d.ts +1 -0
- package/dist/plus/git-github/api/issueWrites.js +5 -5
- package/dist/plus/git-github/api/issueWrites.js.map +1 -1
- package/dist/plus/git-github/api/pullRequestWrites.d.ts +7 -3
- package/dist/plus/git-github/api/pullRequestWrites.js +120 -67
- package/dist/plus/git-github/api/pullRequestWrites.js.map +1 -1
- package/dist/plus/integrations/authentication/configuredIntegrationService.d.ts +4 -4
- package/dist/plus/integrations/authentication/configuredIntegrationService.js +14 -14
- package/dist/plus/integrations/authentication/configuredIntegrationService.js.map +1 -1
- package/dist/plus/integrations/authentication/integrationAuthenticationService.js +3 -3
- package/dist/plus/integrations/authentication/integrationAuthenticationService.js.map +1 -1
- package/dist/plus/integrations/context.d.ts +4 -4
- package/dist/plus/integrations/index.d.ts +8 -4
- package/dist/plus/integrations/index.js +2 -1
- package/dist/plus/integrations/index.js.map +1 -1
- package/dist/plus/integrations/integrationService.d.ts +9 -2
- package/dist/plus/integrations/integrationService.js +95 -31
- package/dist/plus/integrations/integrationService.js.map +1 -1
- package/dist/plus/integrations/manager.d.ts +16 -4
- package/dist/plus/integrations/models/gitHostIntegration.js +7 -4
- package/dist/plus/integrations/models/gitHostIntegration.js.map +1 -1
- package/dist/plus/integrations/models/integration.d.ts +2 -1
- package/dist/plus/integrations/models/integration.js +11 -4
- package/dist/plus/integrations/models/integration.js.map +1 -1
- package/dist/plus/integrations/models/issueTrackerWrites.d.ts +128 -0
- package/dist/plus/integrations/models/issueTrackerWrites.js +0 -0
- package/dist/plus/integrations/models/publicIntegration.d.ts +4 -0
- package/dist/plus/integrations/models/publicIntegration.js.map +1 -1
- package/dist/plus/integrations/providers/github.d.ts +19 -6
- package/dist/plus/integrations/providers/github.js +126 -53
- package/dist/plus/integrations/providers/github.js.map +1 -1
- package/dist/plus/integrations/providers/jira.js +1 -1
- package/dist/plus/integrations/providers/jiraIssueByKey.d.ts +2 -0
- package/dist/plus/integrations/providers/jiraIssueByKey.js +1 -1
- package/dist/plus/integrations/providers/jiraIssueByKey.js.map +1 -1
- package/dist/plus/integrations/providers/jiraIssueWriteErrors.d.ts +10 -0
- package/dist/plus/integrations/providers/jiraIssueWriteErrors.js +68 -0
- package/dist/plus/integrations/providers/jiraIssueWriteErrors.js.map +1 -0
- package/dist/plus/integrations/providers/jiraIssueWrites.d.ts +40 -0
- package/dist/plus/integrations/providers/jiraIssueWrites.js +397 -0
- package/dist/plus/integrations/providers/jiraIssueWrites.js.map +1 -0
- package/dist/plus/integrations/providers/providersApi.d.ts +4 -1
- package/dist/plus/integrations/providers/providersApi.js +21 -10
- package/dist/plus/integrations/providers/providersApi.js.map +1 -1
- package/dist/plus/integrations/utils/integration.utils.d.ts +1 -0
- package/dist/plus/integrations/utils/integration.utils.js +7 -1
- package/dist/plus/integrations/utils/integration.utils.js.map +1 -1
- package/dist/utils/date.d.ts +1 -0
- package/dist/utils/date.js +10 -1
- package/dist/utils/date.js.map +1 -1
- package/dist/utils/keys/keymapDispatcher.d.ts +12 -0
- package/dist/utils/keys/keymapDispatcher.js +33 -1
- package/dist/utils/keys/keymapDispatcher.js.map +1 -1
- package/dist/utils/pausedOperation.js +48 -16
- package/dist/utils/pausedOperation.js.map +1 -1
- package/dist/utils/plural.d.ts +1 -0
- package/dist/utils/plural.js +7 -2
- package/dist/utils/plural.js.map +1 -1
- package/dist/utils/wheel.d.ts +8 -0
- package/dist/utils/wheel.js +12 -0
- package/dist/utils/wheel.js.map +1 -0
- package/docs/integrations.md +80 -8
- package/package.json +1 -1
|
@@ -147,26 +147,6 @@ const models = [
|
|
|
147
147
|
provider: anthropicProviderDescriptor,
|
|
148
148
|
hidden: true
|
|
149
149
|
},
|
|
150
|
-
{
|
|
151
|
-
id: "claude-sonnet-4-5",
|
|
152
|
-
name: "Claude Sonnet 4.5",
|
|
153
|
-
maxTokens: {
|
|
154
|
-
input: 2e5,
|
|
155
|
-
output: 64e3
|
|
156
|
-
},
|
|
157
|
-
provider: anthropicProviderDescriptor,
|
|
158
|
-
hidden: true
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
id: "claude-sonnet-4-5-20250929",
|
|
162
|
-
name: "Claude Sonnet 4.5",
|
|
163
|
-
maxTokens: {
|
|
164
|
-
input: 2e5,
|
|
165
|
-
output: 64e3
|
|
166
|
-
},
|
|
167
|
-
provider: anthropicProviderDescriptor,
|
|
168
|
-
hidden: true
|
|
169
|
-
},
|
|
170
150
|
{
|
|
171
151
|
id: "claude-opus-4-5",
|
|
172
152
|
name: "Claude Opus 4.5",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropicProvider.js","names":["provider"],"sources":["../../../../../plus/ai/src/providers/anthropicProvider.ts"],"sourcesContent":["import { anthropicProviderDescriptor as provider } from '../constants.js';\nimport { AIError, AIErrorReason } from '../errors.js';\nimport type { AIActionType, AIModel } from '../models/model.js';\nimport type { AIChatMessage, AIChatMessageRole, AIResponseFormat, AIToolDefinition } from '../models/provider.js';\nimport { getReducedMaxInputTokens } from '../utils/ai.utils.js';\nimport type { ChatCompletionRequest } from './openAICompatibleProviderBase.js';\nimport { OpenAICompatibleProviderBase } from './openAICompatibleProviderBase.js';\n\ntype AnthropicModel = AIModel<typeof provider.id>;\nconst models: AnthropicModel[] = [\n\t{\n\t\tid: 'claude-fable-5-2',\n\t\tname: 'Claude Fable 5.2',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\t// Requires 30-day data retention; ZDR orgs get a 400 on every request\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-opus-5-5',\n\t\tname: 'Claude Opus 5.5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-sonnet-5-5',\n\t\tname: 'Claude Sonnet 5.5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-haiku-5-5',\n\t\tname: 'Claude Haiku 5.5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\tdefault: true,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-fable-5-1',\n\t\tname: 'Claude Fable 5.1',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\t// Requires 30-day data retention; ZDR orgs get a 400 on every request\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-opus-5',\n\t\tname: 'Claude Opus 5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-fable-5',\n\t\tname: 'Claude Fable 5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\t// Requires 30-day data retention; ZDR orgs get a 400 on every request\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-sonnet-5',\n\t\tname: 'Claude Sonnet 5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-opus-4-8',\n\t\tname: 'Claude Opus 4.8',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-opus-4-7',\n\t\tname: 'Claude Opus 4.7',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-sonnet-4-6',\n\t\tname: 'Claude Sonnet 4.6',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t{\n\t\tid: 'claude-opus-4-6',\n\t\tname: 'Claude Opus 4.6',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t{\n\t\tid: 'claude-haiku-4-5',\n\t\tname: 'Claude Haiku 4.5',\n\t\tmaxTokens: { input: 200000, output: 64000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t{\n\t\tid: 'claude-haiku-4-5-20251001',\n\t\tname: 'Claude Haiku 4.5',\n\t\tmaxTokens: { input: 200000, output: 64000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t// Anthropic retires Sonnet 4.5 on 2026-11-30 — remove both entries after that date (#6164)\n\t{\n\t\tid: 'claude-sonnet-4-5',\n\t\tname: 'Claude Sonnet 4.5',\n\t\tmaxTokens: { input: 200000, output: 64000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t{\n\t\tid: 'claude-sonnet-4-5-20250929',\n\t\tname: 'Claude Sonnet 4.5',\n\t\tmaxTokens: { input: 200000, output: 64000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t{\n\t\tid: 'claude-opus-4-5',\n\t\tname: 'Claude Opus 4.5',\n\t\tmaxTokens: { input: 200000, output: 64000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t{\n\t\tid: 'claude-opus-4-5-20251101',\n\t\tname: 'Claude Opus 4.5',\n\t\tmaxTokens: { input: 200000, output: 64000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n];\n\nexport class AnthropicProvider extends OpenAICompatibleProviderBase<typeof provider.id> {\n\treadonly id = provider.id;\n\treadonly name = provider.name;\n\treadonly supportsTools = true;\n\tprotected readonly descriptor = provider;\n\tprotected readonly config = {\n\t\tkeyUrl: 'https://console.anthropic.com/account/keys',\n\t\tkeyValidator: /(?:sk-)?[a-zA-Z0-9-_]{32,}/,\n\t};\n\n\tgetModels(): Promise<readonly AIModel<typeof provider.id>[]> {\n\t\treturn Promise.resolve(models);\n\t}\n\n\tprotected getUrl(_model: AIModel<typeof provider.id>): string {\n\t\treturn 'https://api.anthropic.com/v1/messages';\n\t}\n\n\t// Anthropic uses `output_config.format` (no name/strict — enforcement is unconditional) and\n\t// rejects unknown fields, so this must fully replace the base's `response_format` translation\n\tprotected override applyResponseFormat(\n\t\trequest: ChatCompletionRequest,\n\t\t_model: AIModel<typeof provider.id>,\n\t\tresponseFormat: AIResponseFormat,\n\t): void {\n\t\trequest.output_config = { format: { type: 'json_schema', schema: responseFormat.schema } };\n\t}\n\n\tprotected override getHeaders<TAction extends AIActionType>(\n\t\t_action: TAction,\n\t\tapiKey: string,\n\t\t_model: AIModel<typeof provider.id>,\n\t\t_url: string,\n\t): Record<string, string> {\n\t\treturn {\n\t\t\tAccept: 'application/json',\n\t\t\t'Content-Type': 'application/json',\n\t\t\tAuthorization: `Bearer ${apiKey}`,\n\t\t\t'x-api-key': apiKey,\n\t\t\t'anthropic-version': '2023-06-01',\n\t\t};\n\t}\n\n\tprotected override fetchCore<TAction extends AIActionType>(\n\t\taction: TAction,\n\t\tmodel: AIModel<typeof provider.id>,\n\t\tapiKey: string,\n\t\trequest: object,\n\t\tsignal: AbortSignal | undefined,\n\t): Promise<Response> {\n\t\tif ('max_completion_tokens' in request) {\n\t\t\tconst { max_completion_tokens: max, ...rest } = request;\n\t\t\trequest = max ? { max_tokens: max, ...rest } : rest;\n\t\t}\n\t\treturn super.fetchCore(action, model, apiKey, request, signal);\n\t}\n\n\tprotected override extractSystemPrompt(messages: AIChatMessage<AIChatMessageRole>[]): {\n\t\tmessages: AIChatMessage<AIChatMessageRole>[];\n\t\tsystem?: string;\n\t} {\n\t\t// Anthropic's Messages API rejects `system`-role entries in `messages` and requires the initial\n\t\t// system prompt in the top-level `system` field, so pull any such messages out.\n\t\tconst systemMessages = messages.filter(m => m.role === 'system');\n\t\tif (!systemMessages.length) return { messages: messages };\n\n\t\treturn {\n\t\t\tsystem: systemMessages.map(m => m.content).join('\\n\\n'),\n\t\t\tmessages: messages.filter(m => m.role !== 'system'),\n\t\t};\n\t}\n\n\tprotected override async handleFetchFailure<TAction extends AIActionType>(\n\t\trsp: Response,\n\t\taction: TAction,\n\t\tmodel: AIModel<typeof provider.id>,\n\t\tretries: number,\n\t\tmaxInputTokens: number,\n\t\tbody?: string,\n\t\tsentTools?: boolean,\n\t): Promise<{ retry: true; maxInputTokens: number; withoutTools?: boolean }> {\n\t\tif (rsp.status !== 404 && rsp.status !== 429) {\n\t\t\t// Read into `body` (not the response) so `super.handleFetchFailure` below can still\n\t\t\t// use it; consuming the response here would lose Anthropic's error for the fallback.\n\t\t\tbody ??= await rsp\n\t\t\t\t.clone()\n\t\t\t\t.text()\n\t\t\t\t.catch(() => undefined);\n\t\t\tlet json;\n\t\t\ttry {\n\t\t\t\tjson = (body != null ? JSON.parse(body) : undefined) as AnthropicError | undefined;\n\t\t\t} catch {}\n\n\t\t\tdebugger;\n\n\t\t\tif (json?.error?.type === 'invalid_request_error') {\n\t\t\t\tif (json?.error?.message?.includes('prompt is too long')) {\n\t\t\t\t\tif (retries < 3) {\n\t\t\t\t\t\t// Extract actual token count from error to calculate smarter reduction\n\t\t\t\t\t\tconst match = /prompt is too long: (\\d+) tokens/.exec(json?.error?.message);\n\t\t\t\t\t\tconst estimatedTokens = match?.[1] != null ? parseInt(match[1], 10) : undefined;\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tretry: true,\n\t\t\t\t\t\t\tmaxInputTokens: getReducedMaxInputTokens(maxInputTokens, retries + 1, estimatedTokens),\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow new AIError(\n\t\t\t\t\t\tAIErrorReason.RequestTooLarge,\n\t\t\t\t\t\tnew Error(`(${this.name}) ${rsp.status}: ${json?.error?.message || rsp.statusText}`),\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (json?.error?.message?.includes('balance is too low')) {\n\t\t\t\t\tthrow new AIError(\n\t\t\t\t\t\tAIErrorReason.RateLimitOrFundsExceeded,\n\t\t\t\t\t\tnew Error(`(${this.name}) ${rsp.status}: ${json?.error?.message || rsp.statusText}`),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn super.handleFetchFailure(rsp, action, model, retries, maxInputTokens, body, sentTools);\n\t}\n\n\tprotected override serializeTools(tools: readonly AIToolDefinition[]): { tools: unknown[] } {\n\t\t// Anthropic names the schema field `input_schema` and has no `function` envelope.\n\t\treturn {\n\t\t\ttools: tools.map(t => ({ name: t.name, description: t.description, input_schema: t.parameters })),\n\t\t};\n\t}\n\n\tprotected override serializeMessages(messages: AIChatMessage<AIChatMessageRole>[]): unknown[] {\n\t\tconst out: unknown[] = [];\n\n\t\tfor (const m of messages) {\n\t\t\t// Anthropic carries tool results as `tool_result` blocks on a *user* message, not a\n\t\t\t// `tool`-role message. Consecutive results are batched into one user turn, matching how the\n\t\t\t// API expects a multi-tool-call round to be answered.\n\t\t\tif (m.role === 'tool') {\n\t\t\t\t// See the base provider: a result with no call id can't be addressed, so it goes as plain\n\t\t\t\t// text instead of a `tool_use_id: undefined` block the API rejects.\n\t\t\t\tif (m.toolCallId == null) {\n\t\t\t\t\tout.push({ role: 'user', content: m.content });\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst block = { type: 'tool_result', tool_use_id: m.toolCallId, content: m.content };\n\t\t\t\tconst last = out.at(-1) as { role?: string; content?: unknown[] } | undefined;\n\t\t\t\tif (last?.role === 'user' && Array.isArray(last.content) && isToolResultBlocks(last.content)) {\n\t\t\t\t\tlast.content.push(block);\n\t\t\t\t} else {\n\t\t\t\t\tout.push({ role: 'user', content: [block] });\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (m.role === 'assistant' && m.toolCalls?.length) {\n\t\t\t\tout.push({\n\t\t\t\t\trole: 'assistant',\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t...(m.content ? [{ type: 'text', text: m.content }] : []),\n\t\t\t\t\t\t...m.toolCalls.map(c => ({ type: 'tool_use', id: c.id, name: c.name, input: c.args })),\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tout.push({ role: m.role, content: m.content });\n\t\t}\n\n\t\treturn out;\n\t}\n}\n\n/** Whether an assembled user message's content is a batch of `tool_result` blocks we can append to. */\nfunction isToolResultBlocks(content: unknown[]): content is { type: string }[] {\n\treturn content.every(b => (b as { type?: string })?.type === 'tool_result');\n}\n\ninterface AnthropicError {\n\ttype: 'error';\n\terror: {\n\t\ttype:\n\t\t\t| 'invalid_request_error'\n\t\t\t| 'authentication_error'\n\t\t\t| 'permission_error'\n\t\t\t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IACD;GACD;GAEA,IAAI,KAAK;IAAE,MAAM,EAAE;IAAM,SAAS,EAAE;GAAQ,CAAC;EAC9C;EAEA,OAAO;CACR;AACD;;AAGA,SAAS,mBAAmB,SAAmD;CAC9E,OAAO,QAAQ,OAAM,MAAM,GAAyB,SAAS,aAAa;AAC3E"}
|
|
1
|
+
{"version":3,"file":"anthropicProvider.js","names":["provider"],"sources":["../../../../../plus/ai/src/providers/anthropicProvider.ts"],"sourcesContent":["import { anthropicProviderDescriptor as provider } from '../constants.js';\nimport { AIError, AIErrorReason } from '../errors.js';\nimport type { AIActionType, AIModel } from '../models/model.js';\nimport type { AIChatMessage, AIChatMessageRole, AIResponseFormat, AIToolDefinition } from '../models/provider.js';\nimport { getReducedMaxInputTokens } from '../utils/ai.utils.js';\nimport type { ChatCompletionRequest } from './openAICompatibleProviderBase.js';\nimport { OpenAICompatibleProviderBase } from './openAICompatibleProviderBase.js';\n\ntype AnthropicModel = AIModel<typeof provider.id>;\nconst models: AnthropicModel[] = [\n\t{\n\t\tid: 'claude-fable-5-2',\n\t\tname: 'Claude Fable 5.2',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\t// Requires 30-day data retention; ZDR orgs get a 400 on every request\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-opus-5-5',\n\t\tname: 'Claude Opus 5.5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-sonnet-5-5',\n\t\tname: 'Claude Sonnet 5.5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-haiku-5-5',\n\t\tname: 'Claude Haiku 5.5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\tdefault: true,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-fable-5-1',\n\t\tname: 'Claude Fable 5.1',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\t// Requires 30-day data retention; ZDR orgs get a 400 on every request\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-opus-5',\n\t\tname: 'Claude Opus 5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-fable-5',\n\t\tname: 'Claude Fable 5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\t// Requires 30-day data retention; ZDR orgs get a 400 on every request\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-sonnet-5',\n\t\tname: 'Claude Sonnet 5',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-opus-4-8',\n\t\tname: 'Claude Opus 4.8',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-opus-4-7',\n\t\tname: 'Claude Opus 4.7',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t\ttemperature: null, // Sampling params removed on Opus 4.7+/Sonnet 5 (rejected with 400)\n\t},\n\t{\n\t\tid: 'claude-sonnet-4-6',\n\t\tname: 'Claude Sonnet 4.6',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t{\n\t\tid: 'claude-opus-4-6',\n\t\tname: 'Claude Opus 4.6',\n\t\tmaxTokens: { input: 1000000, output: 128000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t{\n\t\tid: 'claude-haiku-4-5',\n\t\tname: 'Claude Haiku 4.5',\n\t\tmaxTokens: { input: 200000, output: 64000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t{\n\t\tid: 'claude-haiku-4-5-20251001',\n\t\tname: 'Claude Haiku 4.5',\n\t\tmaxTokens: { input: 200000, output: 64000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t{\n\t\tid: 'claude-opus-4-5',\n\t\tname: 'Claude Opus 4.5',\n\t\tmaxTokens: { input: 200000, output: 64000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n\t{\n\t\tid: 'claude-opus-4-5-20251101',\n\t\tname: 'Claude Opus 4.5',\n\t\tmaxTokens: { input: 200000, output: 64000 },\n\t\tprovider: provider,\n\t\thidden: true,\n\t},\n];\n\nexport class AnthropicProvider extends OpenAICompatibleProviderBase<typeof provider.id> {\n\treadonly id = provider.id;\n\treadonly name = provider.name;\n\treadonly supportsTools = true;\n\tprotected readonly descriptor = provider;\n\tprotected readonly config = {\n\t\tkeyUrl: 'https://console.anthropic.com/account/keys',\n\t\tkeyValidator: /(?:sk-)?[a-zA-Z0-9-_]{32,}/,\n\t};\n\n\tgetModels(): Promise<readonly AIModel<typeof provider.id>[]> {\n\t\treturn Promise.resolve(models);\n\t}\n\n\tprotected getUrl(_model: AIModel<typeof provider.id>): string {\n\t\treturn 'https://api.anthropic.com/v1/messages';\n\t}\n\n\t// Anthropic uses `output_config.format` (no name/strict — enforcement is unconditional) and\n\t// rejects unknown fields, so this must fully replace the base's `response_format` translation\n\tprotected override applyResponseFormat(\n\t\trequest: ChatCompletionRequest,\n\t\t_model: AIModel<typeof provider.id>,\n\t\tresponseFormat: AIResponseFormat,\n\t): void {\n\t\trequest.output_config = { format: { type: 'json_schema', schema: responseFormat.schema } };\n\t}\n\n\tprotected override getHeaders<TAction extends AIActionType>(\n\t\t_action: TAction,\n\t\tapiKey: string,\n\t\t_model: AIModel<typeof provider.id>,\n\t\t_url: string,\n\t): Record<string, string> {\n\t\treturn {\n\t\t\tAccept: 'application/json',\n\t\t\t'Content-Type': 'application/json',\n\t\t\tAuthorization: `Bearer ${apiKey}`,\n\t\t\t'x-api-key': apiKey,\n\t\t\t'anthropic-version': '2023-06-01',\n\t\t};\n\t}\n\n\tprotected override fetchCore<TAction extends AIActionType>(\n\t\taction: TAction,\n\t\tmodel: AIModel<typeof provider.id>,\n\t\tapiKey: string,\n\t\trequest: object,\n\t\tsignal: AbortSignal | undefined,\n\t): Promise<Response> {\n\t\tif ('max_completion_tokens' in request) {\n\t\t\tconst { max_completion_tokens: max, ...rest } = request;\n\t\t\trequest = max ? { max_tokens: max, ...rest } : rest;\n\t\t}\n\t\treturn super.fetchCore(action, model, apiKey, request, signal);\n\t}\n\n\tprotected override extractSystemPrompt(messages: AIChatMessage<AIChatMessageRole>[]): {\n\t\tmessages: AIChatMessage<AIChatMessageRole>[];\n\t\tsystem?: string;\n\t} {\n\t\t// Anthropic's Messages API rejects `system`-role entries in `messages` and requires the initial\n\t\t// system prompt in the top-level `system` field, so pull any such messages out.\n\t\tconst systemMessages = messages.filter(m => m.role === 'system');\n\t\tif (!systemMessages.length) return { messages: messages };\n\n\t\treturn {\n\t\t\tsystem: systemMessages.map(m => m.content).join('\\n\\n'),\n\t\t\tmessages: messages.filter(m => m.role !== 'system'),\n\t\t};\n\t}\n\n\tprotected override async handleFetchFailure<TAction extends AIActionType>(\n\t\trsp: Response,\n\t\taction: TAction,\n\t\tmodel: AIModel<typeof provider.id>,\n\t\tretries: number,\n\t\tmaxInputTokens: number,\n\t\tbody?: string,\n\t\tsentTools?: boolean,\n\t): Promise<{ retry: true; maxInputTokens: number; withoutTools?: boolean }> {\n\t\tif (rsp.status !== 404 && rsp.status !== 429) {\n\t\t\t// Read into `body` (not the response) so `super.handleFetchFailure` below can still\n\t\t\t// use it; consuming the response here would lose Anthropic's error for the fallback.\n\t\t\tbody ??= await rsp\n\t\t\t\t.clone()\n\t\t\t\t.text()\n\t\t\t\t.catch(() => undefined);\n\t\t\tlet json;\n\t\t\ttry {\n\t\t\t\tjson = (body != null ? JSON.parse(body) : undefined) as AnthropicError | undefined;\n\t\t\t} catch {}\n\n\t\t\tdebugger;\n\n\t\t\tif (json?.error?.type === 'invalid_request_error') {\n\t\t\t\tif (json?.error?.message?.includes('prompt is too long')) {\n\t\t\t\t\tif (retries < 3) {\n\t\t\t\t\t\t// Extract actual token count from error to calculate smarter reduction\n\t\t\t\t\t\tconst match = /prompt is too long: (\\d+) tokens/.exec(json?.error?.message);\n\t\t\t\t\t\tconst estimatedTokens = match?.[1] != null ? parseInt(match[1], 10) : undefined;\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tretry: true,\n\t\t\t\t\t\t\tmaxInputTokens: getReducedMaxInputTokens(maxInputTokens, retries + 1, estimatedTokens),\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow new AIError(\n\t\t\t\t\t\tAIErrorReason.RequestTooLarge,\n\t\t\t\t\t\tnew Error(`(${this.name}) ${rsp.status}: ${json?.error?.message || rsp.statusText}`),\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif (json?.error?.message?.includes('balance is too low')) {\n\t\t\t\t\tthrow new AIError(\n\t\t\t\t\t\tAIErrorReason.RateLimitOrFundsExceeded,\n\t\t\t\t\t\tnew Error(`(${this.name}) ${rsp.status}: ${json?.error?.message || rsp.statusText}`),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn super.handleFetchFailure(rsp, action, model, retries, maxInputTokens, body, sentTools);\n\t}\n\n\tprotected override serializeTools(tools: readonly AIToolDefinition[]): { tools: unknown[] } {\n\t\t// Anthropic names the schema field `input_schema` and has no `function` envelope.\n\t\treturn {\n\t\t\ttools: tools.map(t => ({ name: t.name, description: t.description, input_schema: t.parameters })),\n\t\t};\n\t}\n\n\tprotected override serializeMessages(messages: AIChatMessage<AIChatMessageRole>[]): unknown[] {\n\t\tconst out: unknown[] = [];\n\n\t\tfor (const m of messages) {\n\t\t\t// Anthropic carries tool results as `tool_result` blocks on a *user* message, not a\n\t\t\t// `tool`-role message. Consecutive results are batched into one user turn, matching how the\n\t\t\t// API expects a multi-tool-call round to be answered.\n\t\t\tif (m.role === 'tool') {\n\t\t\t\t// See the base provider: a result with no call id can't be addressed, so it goes as plain\n\t\t\t\t// text instead of a `tool_use_id: undefined` block the API rejects.\n\t\t\t\tif (m.toolCallId == null) {\n\t\t\t\t\tout.push({ role: 'user', content: m.content });\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst block = { type: 'tool_result', tool_use_id: m.toolCallId, content: m.content };\n\t\t\t\tconst last = out.at(-1) as { role?: string; content?: unknown[] } | undefined;\n\t\t\t\tif (last?.role === 'user' && Array.isArray(last.content) && isToolResultBlocks(last.content)) {\n\t\t\t\t\tlast.content.push(block);\n\t\t\t\t} else {\n\t\t\t\t\tout.push({ role: 'user', content: [block] });\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (m.role === 'assistant' && m.toolCalls?.length) {\n\t\t\t\tout.push({\n\t\t\t\t\trole: 'assistant',\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t...(m.content ? [{ type: 'text', text: m.content }] : []),\n\t\t\t\t\t\t...m.toolCalls.map(c => ({ type: 'tool_use', id: c.id, name: c.name, input: c.args })),\n\t\t\t\t\t],\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tout.push({ role: m.role, content: m.content });\n\t\t}\n\n\t\treturn out;\n\t}\n}\n\n/** Whether an assembled user message's content is a batch of `tool_result` blocks we can append to. */\nfunction isToolResultBlocks(content: unknown[]): content is { type: string }[] {\n\treturn content.every(b => (b as { type?: string })?.type === 'tool_result');\n}\n\ninterface AnthropicError {\n\ttype: 'error';\n\terror: {\n\t\ttype:\n\t\t\t| 'invalid_request_error'\n\t\t\t| 'authentication_error'\n\t\t\t| 'permission_error'\n\t\t\t| 'not_found_error'\n\t\t\t| 'rate_limit_error'\n\t\t\t| 'api_error'\n\t\t\t| 'overloaded_error';\n\t\tmessage: string;\n\t};\n}\n"],"mappings":";;;;;AASA,MAAM,SAA2B;CAChC;EACC,IAAI;EACJ,MAAM;EACN,WAAW;GAAE,OAAO;GAAS,QAAQ;EAAO;EAC5C,UAAUA;EAEV,aAAa;CACd;CACA;EACC,IAAI;EACJ,MAAM;EACN,WAAW;GAAE,OAAO;GAAS,QAAQ;EAAO;EAC5C,UAAUA;EACV,aAAa;CACd;CACA;EACC,IAAI;EACJ,MAAM;EACN,WAAW;GAAE,OAAO;GAAS,QAAQ;EAAO;EAC5C,UAAUA;EACV,aAAa;CACd;CACA;EACC,IAAI;EACJ,MAAM;EACN,WAAW;GAAE,OAAO;GAAS,QAAQ;EAAO;EAC5C,UAAUA;EACV,SAAS;EACT,aAAa;CACd;CACA;EACC,IAAI;EACJ,MAAM;EACN,WAAW;GAAE,OAAO;GAAS,QAAQ;EAAO;EAC5C,UAAUA;EAEV,aAAa;CACd;CACA;EACC,IAAI;EACJ,MAAM;EACN,WAAW;GAAE,OAAO;GAAS,QAAQ;EAAO;EAC5C,UAAUA;EACV,aAAa;CACd;CACA;EACC,IAAI;EACJ,MAAM;EACN,WAAW;GAAE,OAAO;GAAS,QAAQ;EAAO;EAC5C,UAAUA;EAEV,aAAa;CACd;CACA;EACC,IAAI;EACJ,MAAM;EACN,WAAW;GAAE,OAAO;GAAS,QAAQ;EAAO;EAC5C,UAAUA;EACV,aAAa;CACd;CACA;EACC,IAAI;EACJ,MAA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,EAAE;MAAM,OAAO,EAAE;KAAK,EAAE,CACtF;IACD,CAAC;IACD;GACD;GAEA,IAAI,KAAK;IAAE,MAAM,EAAE;IAAM,SAAS,EAAE;GAAQ,CAAC;EAC9C;EAEA,OAAO;CACR;AACD;;AAGA,SAAS,mBAAmB,SAAmD;CAC9E,OAAO,QAAQ,OAAM,MAAM,GAAyB,SAAS,aAAa;AAC3E"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { GitHubPullRequestCreateTarget, PullRequestWriteFailure } from "./pullRequestWrites.js";
|
|
2
|
+
import { RequestParameters } from "@octokit/types";
|
|
3
|
+
//#region ../plus/git-github/src/api/enterprisePullRequestMergePolicy.d.ts
|
|
4
|
+
export type GraphqlRequest = <T>(query: string, variables: RequestParameters) => Promise<T | undefined>;
|
|
5
|
+
export type BranchRule = {
|
|
6
|
+
type: string;
|
|
7
|
+
parameters?: {
|
|
8
|
+
allowedMergeMethods?: readonly string[] | null;
|
|
9
|
+
} | null;
|
|
10
|
+
};
|
|
11
|
+
export type BranchPolicy = {
|
|
12
|
+
rules: BranchRule[];
|
|
13
|
+
requiresLinearHistory: boolean;
|
|
14
|
+
};
|
|
15
|
+
export type EnterprisePullRequestWriteOptions = {
|
|
16
|
+
origin: string;
|
|
17
|
+
readBranchRules: (target: GitHubPullRequestCreateTarget, branch: string) => Promise<unknown[] | undefined>;
|
|
18
|
+
};
|
|
19
|
+
type MergePolicy = BranchPolicy | {
|
|
20
|
+
kind: 'queue';
|
|
21
|
+
} | {
|
|
22
|
+
kind: 'unavailable';
|
|
23
|
+
reason: PullRequestWriteFailure['reason'];
|
|
24
|
+
};
|
|
25
|
+
export declare function readEnterprisePullRequestMergePolicy({ id, baseRef, baseRefId }: {
|
|
26
|
+
id: string;
|
|
27
|
+
baseRef: string;
|
|
28
|
+
baseRefId: string;
|
|
29
|
+
}, repository: GitHubPullRequestCreateTarget, graphql: GraphqlRequest, readBranchRules: EnterprisePullRequestWriteOptions['readBranchRules']): Promise<MergePolicy>;
|
|
30
|
+
//#endregion
|
|
31
|
+
//# sourceMappingURL=enterprisePullRequestMergePolicy.d.ts.map
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { RequestError } from "@octokit/request-error";
|
|
2
|
+
//#region ../plus/git-github/src/api/enterprisePullRequestMergePolicy.ts
|
|
3
|
+
async function readEnterprisePullRequestMergePolicy({ id, baseRef, baseRefId }, repository, graphql, readBranchRules) {
|
|
4
|
+
const schema = await readEnterpriseMergeSchema(graphql);
|
|
5
|
+
if (schema == null) return {
|
|
6
|
+
kind: "unavailable",
|
|
7
|
+
reason: "unknown"
|
|
8
|
+
};
|
|
9
|
+
if (schema.hasQueue && !schema.queueFields) return {
|
|
10
|
+
kind: "unavailable",
|
|
11
|
+
reason: "unknown"
|
|
12
|
+
};
|
|
13
|
+
if (schema.queueFields || schema.stack) {
|
|
14
|
+
const current = (await graphql(`query PullRequestMergeFeatures($id: ID!) {
|
|
15
|
+
node(id: $id) {
|
|
16
|
+
... on PullRequest {
|
|
17
|
+
id baseRefName baseRef { id }
|
|
18
|
+
${schema.queueFields ? "isInMergeQueue isMergeQueueEnabled" : ""}
|
|
19
|
+
${schema.stack ? "stack { id }" : ""}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}`, { id }))?.node;
|
|
23
|
+
if (current?.id !== id || current.baseRefName !== baseRef || current.baseRef?.id !== baseRefId || schema.queueFields && (typeof current.isInMergeQueue !== "boolean" || typeof current.isMergeQueueEnabled !== "boolean") || schema.stack && current.stack === void 0) return {
|
|
24
|
+
kind: "unavailable",
|
|
25
|
+
reason: "unknown"
|
|
26
|
+
};
|
|
27
|
+
if (current.isInMergeQueue) return {
|
|
28
|
+
kind: "unavailable",
|
|
29
|
+
reason: "blocked"
|
|
30
|
+
};
|
|
31
|
+
if (current.stack != null) return {
|
|
32
|
+
kind: "unavailable",
|
|
33
|
+
reason: "unsupported"
|
|
34
|
+
};
|
|
35
|
+
if (current.isMergeQueueEnabled) return enterpriseQueueCapability(schema.canEnqueue);
|
|
36
|
+
}
|
|
37
|
+
const activeRules = normalizeEnterpriseBranchRules(await readBranchRules(repository, baseRef).catch((ex) => {
|
|
38
|
+
if (ex instanceof RequestError && ex.status === 404) return void 0;
|
|
39
|
+
throw ex;
|
|
40
|
+
}));
|
|
41
|
+
if (activeRules == null) return {
|
|
42
|
+
kind: "unavailable",
|
|
43
|
+
reason: "unknown"
|
|
44
|
+
};
|
|
45
|
+
if (activeRules.some((rule) => rule.type === "MERGE_QUEUE")) return enterpriseQueueCapability(schema.queueFields && schema.canEnqueue);
|
|
46
|
+
if (!schema.canMerge || !schema.linearHistory) return {
|
|
47
|
+
kind: "unavailable",
|
|
48
|
+
reason: "unsupported"
|
|
49
|
+
};
|
|
50
|
+
const ref = (await graphql(`
|
|
51
|
+
query PullRequestLegacyBranchRule($id: ID!) {
|
|
52
|
+
node(id: $id) {
|
|
53
|
+
... on Ref {
|
|
54
|
+
id
|
|
55
|
+
refUpdateRule {
|
|
56
|
+
requiresLinearHistory
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
`, { id: baseRefId }))?.node;
|
|
62
|
+
if (ref?.id !== baseRefId || ref.refUpdateRule !== null && typeof ref.refUpdateRule?.requiresLinearHistory !== "boolean") return {
|
|
63
|
+
kind: "unavailable",
|
|
64
|
+
reason: "unknown"
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
rules: activeRules,
|
|
68
|
+
requiresLinearHistory: ref.refUpdateRule?.requiresLinearHistory === true
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function normalizeEnterpriseBranchRules(data) {
|
|
72
|
+
if (data == null) return void 0;
|
|
73
|
+
const rules = [];
|
|
74
|
+
for (const value of data) {
|
|
75
|
+
const rule = value;
|
|
76
|
+
if (typeof rule?.type !== "string" || !rule.type) return void 0;
|
|
77
|
+
const type = rule.type.toUpperCase();
|
|
78
|
+
const parameters = type === "PULL_REQUEST" ? rule.parameters : void 0;
|
|
79
|
+
if (parameters != null && (typeof parameters !== "object" || Array.isArray(parameters))) return void 0;
|
|
80
|
+
const methods = parameters?.allowed_merge_methods;
|
|
81
|
+
if (methods == null) rules.push({ type });
|
|
82
|
+
else if (Array.isArray(methods) && methods.every((method) => typeof method === "string")) rules.push({
|
|
83
|
+
type,
|
|
84
|
+
parameters: { allowedMergeMethods: methods }
|
|
85
|
+
});
|
|
86
|
+
else return;
|
|
87
|
+
}
|
|
88
|
+
return rules;
|
|
89
|
+
}
|
|
90
|
+
function enterpriseQueueCapability(supported) {
|
|
91
|
+
return supported ? { kind: "queue" } : {
|
|
92
|
+
kind: "unavailable",
|
|
93
|
+
reason: "unsupported"
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
async function readEnterpriseMergeSchema(graphql) {
|
|
97
|
+
const [operations, branch, queue] = await Promise.all([
|
|
98
|
+
graphql(`
|
|
99
|
+
query PullRequestMergeSchemaOperations {
|
|
100
|
+
mutation: __type(name: "Mutation") {
|
|
101
|
+
fields {
|
|
102
|
+
name
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
pr: __type(name: "PullRequest") {
|
|
106
|
+
fields {
|
|
107
|
+
name
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
enqueue: __type(name: "EnqueuePullRequestInput") {
|
|
111
|
+
inputFields {
|
|
112
|
+
name
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
merge: __type(name: "MergePullRequestInput") {
|
|
116
|
+
inputFields {
|
|
117
|
+
name
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
`, {}),
|
|
122
|
+
graphql(`
|
|
123
|
+
query PullRequestMergeSchemaBranch {
|
|
124
|
+
ref: __type(name: "Ref") {
|
|
125
|
+
fields {
|
|
126
|
+
name
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
legacy: __type(name: "RefUpdateRule") {
|
|
130
|
+
fields {
|
|
131
|
+
name
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
`, {}),
|
|
136
|
+
graphql(`
|
|
137
|
+
query PullRequestMergeSchemaQueue {
|
|
138
|
+
enqueuePayload: __type(name: "EnqueuePullRequestPayload") {
|
|
139
|
+
fields {
|
|
140
|
+
name
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
entry: __type(name: "MergeQueueEntry") {
|
|
144
|
+
fields {
|
|
145
|
+
name
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
`, {})
|
|
150
|
+
]);
|
|
151
|
+
if (!Array.isArray(operations?.mutation?.fields) || !Array.isArray(operations.pr?.fields) || operations.enqueue === void 0 || operations.merge === void 0 || branch?.ref === void 0 || branch.legacy === void 0 || queue?.enqueuePayload === void 0 || queue.entry === void 0) return;
|
|
152
|
+
const has = (members, ...names) => names.every((name) => members?.some((member) => member.name === name) === true);
|
|
153
|
+
const hasEnqueue = has(operations.mutation.fields, "enqueuePullRequest");
|
|
154
|
+
return {
|
|
155
|
+
stack: has(operations.pr.fields, "stack"),
|
|
156
|
+
queueFields: has(operations.pr.fields, "isInMergeQueue", "isMergeQueueEnabled"),
|
|
157
|
+
hasQueue: hasEnqueue || has(operations.pr.fields, "isInMergeQueue") || has(operations.pr.fields, "isMergeQueueEnabled"),
|
|
158
|
+
canEnqueue: hasEnqueue && has(operations.enqueue?.inputFields, "pullRequestId", "expectedHeadOid") && has(queue.enqueuePayload?.fields, "mergeQueueEntry") && has(queue.entry?.fields, "id", "pullRequest"),
|
|
159
|
+
canMerge: has(operations.mutation.fields, "mergePullRequest") && has(operations.merge?.inputFields, "pullRequestId", "expectedHeadOid", "mergeMethod"),
|
|
160
|
+
linearHistory: has(branch.ref?.fields, "refUpdateRule") && has(branch.legacy?.fields, "requiresLinearHistory")
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
//#endregion
|
|
164
|
+
export { readEnterprisePullRequestMergePolicy };
|
|
165
|
+
|
|
166
|
+
//# sourceMappingURL=enterprisePullRequestMergePolicy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enterprisePullRequestMergePolicy.js","names":[],"sources":["../../../../../plus/git-github/src/api/enterprisePullRequestMergePolicy.ts"],"sourcesContent":["import { RequestError } from '@octokit/request-error';\nimport type { RequestParameters } from '@octokit/types';\nimport type { GitHubPullRequestCreateTarget, PullRequestWriteFailure } from './pullRequestWrites.js';\n\nexport type GraphqlRequest = <T>(query: string, variables: RequestParameters) => Promise<T | undefined>;\nexport type BranchRule = {\n\ttype: string;\n\tparameters?: { allowedMergeMethods?: readonly string[] | null } | null;\n};\nexport type BranchPolicy = { rules: BranchRule[]; requiresLinearHistory: boolean };\n\nexport type EnterprisePullRequestWriteOptions = {\n\torigin: string;\n\treadBranchRules: (target: GitHubPullRequestCreateTarget, branch: string) => Promise<unknown[] | undefined>;\n};\n\ntype MergePolicy =\n\t| BranchPolicy\n\t| { kind: 'queue' }\n\t| { kind: 'unavailable'; reason: PullRequestWriteFailure['reason'] };\n\nexport async function readEnterprisePullRequestMergePolicy(\n\t{ id, baseRef, baseRefId }: { id: string; baseRef: string; baseRefId: string },\n\trepository: GitHubPullRequestCreateTarget,\n\tgraphql: GraphqlRequest,\n\treadBranchRules: EnterprisePullRequestWriteOptions['readBranchRules'],\n): Promise<MergePolicy> {\n\tconst schema = await readEnterpriseMergeSchema(graphql);\n\tif (schema == null) return { kind: 'unavailable', reason: 'unknown' };\n\tif (schema.hasQueue && !schema.queueFields) return { kind: 'unavailable', reason: 'unknown' };\n\n\tif (schema.queueFields || schema.stack) {\n\t\tconst result = await graphql<{\n\t\t\tnode: {\n\t\t\t\tid: string;\n\t\t\t\tbaseRefName: string;\n\t\t\t\tbaseRef: { id: string } | null;\n\t\t\t\tisInMergeQueue?: boolean;\n\t\t\t\tisMergeQueueEnabled?: boolean;\n\t\t\t\tstack?: { id: string } | null;\n\t\t\t} | null;\n\t\t}>(\n\t\t\t`query PullRequestMergeFeatures($id: ID!) {\n\t\t\t\tnode(id: $id) {\n\t\t\t\t\t... on PullRequest {\n\t\t\t\t\t\tid baseRefName baseRef { id }\n\t\t\t\t\t\t${schema.queueFields ? 'isInMergeQueue isMergeQueueEnabled' : ''}\n\t\t\t\t\t\t${schema.stack ? 'stack { id }' : ''}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}`,\n\t\t\t{ id: id },\n\t\t);\n\t\tconst current = result?.node;\n\t\tif (\n\t\t\tcurrent?.id !== id ||\n\t\t\tcurrent.baseRefName !== baseRef ||\n\t\t\tcurrent.baseRef?.id !== baseRefId ||\n\t\t\t(schema.queueFields &&\n\t\t\t\t(typeof current.isInMergeQueue !== 'boolean' || typeof current.isMergeQueueEnabled !== 'boolean')) ||\n\t\t\t(schema.stack && current.stack === undefined)\n\t\t) {\n\t\t\treturn { kind: 'unavailable', reason: 'unknown' };\n\t\t}\n\n\t\tif (current.isInMergeQueue) return { kind: 'unavailable', reason: 'blocked' };\n\t\tif (current.stack != null) return { kind: 'unavailable', reason: 'unsupported' };\n\t\tif (current.isMergeQueueEnabled) return enterpriseQueueCapability(schema.canEnqueue);\n\t}\n\n\tconst activeRules = normalizeEnterpriseBranchRules(\n\t\tawait readBranchRules(repository, baseRef).catch((ex: unknown) => {\n\t\t\tif (ex instanceof RequestError && ex.status === 404) return undefined;\n\n\t\t\tthrow ex;\n\t\t}),\n\t);\n\tif (activeRules == null) return { kind: 'unavailable', reason: 'unknown' };\n\tif (activeRules.some(rule => rule.type === 'MERGE_QUEUE')) {\n\t\treturn enterpriseQueueCapability(schema.queueFields && schema.canEnqueue);\n\t}\n\n\tif (!schema.canMerge || !schema.linearHistory) return { kind: 'unavailable', reason: 'unsupported' };\n\n\tconst response = await graphql<{\n\t\tnode: { id: string; refUpdateRule: { requiresLinearHistory: boolean } | null } | null;\n\t}>(\n\t\t`\n\t\t\tquery PullRequestLegacyBranchRule($id: ID!) {\n\t\t\t\tnode(id: $id) {\n\t\t\t\t\t... on Ref {\n\t\t\t\t\t\tid\n\t\t\t\t\t\trefUpdateRule {\n\t\t\t\t\t\t\trequiresLinearHistory\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t`,\n\t\t{ id: baseRefId },\n\t);\n\tconst ref = response?.node;\n\tif (\n\t\tref?.id !== baseRefId ||\n\t\t(ref.refUpdateRule !== null && typeof ref.refUpdateRule?.requiresLinearHistory !== 'boolean')\n\t) {\n\t\treturn { kind: 'unavailable', reason: 'unknown' };\n\t}\n\n\treturn {\n\t\trules: activeRules,\n\t\trequiresLinearHistory: ref.refUpdateRule?.requiresLinearHistory === true,\n\t};\n}\n\nfunction normalizeEnterpriseBranchRules(data: unknown[] | undefined): BranchRule[] | undefined {\n\tif (data == null) return undefined;\n\n\tconst rules: BranchRule[] = [];\n\tfor (const value of data) {\n\t\tconst rule = value as { type?: unknown; parameters?: { allowed_merge_methods?: unknown } } | null;\n\t\tif (typeof rule?.type !== 'string' || !rule.type) return undefined;\n\n\t\tconst type = rule.type.toUpperCase();\n\t\tconst parameters = type === 'PULL_REQUEST' ? rule.parameters : undefined;\n\t\tif (parameters != null && (typeof parameters !== 'object' || Array.isArray(parameters))) return undefined;\n\n\t\tconst methods = parameters?.allowed_merge_methods;\n\t\tif (methods == null) {\n\t\t\trules.push({ type: type });\n\t\t} else if (Array.isArray(methods) && methods.every(method => typeof method === 'string')) {\n\t\t\trules.push({ type: type, parameters: { allowedMergeMethods: methods } });\n\t\t} else {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\treturn rules;\n}\n\nfunction enterpriseQueueCapability(supported: boolean): MergePolicy {\n\treturn supported ? { kind: 'queue' } : { kind: 'unavailable', reason: 'unsupported' };\n}\n\nasync function readEnterpriseMergeSchema(graphql: GraphqlRequest) {\n\ttype Member = { name: string };\n\ttype Response = {\n\t\tmutation: { fields: Member[] } | null;\n\t\tpr: { fields: Member[] } | null;\n\t\tref: { fields: Member[] } | null;\n\t\tlegacy: { fields: Member[] } | null;\n\t\tenqueue: { inputFields: Member[] } | null;\n\t\tenqueuePayload: { fields: Member[] } | null;\n\t\tentry: { fields: Member[] } | null;\n\t\tmerge: { inputFields: Member[] } | null;\n\t};\n\tconst [operations, branch, queue] = await Promise.all([\n\t\tgraphql<Pick<Response, 'mutation' | 'pr' | 'enqueue' | 'merge'>>(\n\t\t\t`\n\t\t\t\tquery PullRequestMergeSchemaOperations {\n\t\t\t\t\tmutation: __type(name: \"Mutation\") {\n\t\t\t\t\t\tfields {\n\t\t\t\t\t\t\tname\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tpr: __type(name: \"PullRequest\") {\n\t\t\t\t\t\tfields {\n\t\t\t\t\t\t\tname\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tenqueue: __type(name: \"EnqueuePullRequestInput\") {\n\t\t\t\t\t\tinputFields {\n\t\t\t\t\t\t\tname\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tmerge: __type(name: \"MergePullRequestInput\") {\n\t\t\t\t\t\tinputFields {\n\t\t\t\t\t\t\tname\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t`,\n\t\t\t{},\n\t\t),\n\t\tgraphql<Pick<Response, 'ref' | 'legacy'>>(\n\t\t\t`\n\t\t\t\tquery PullRequestMergeSchemaBranch {\n\t\t\t\t\tref: __type(name: \"Ref\") {\n\t\t\t\t\t\tfields {\n\t\t\t\t\t\t\tname\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tlegacy: __type(name: \"RefUpdateRule\") {\n\t\t\t\t\t\tfields {\n\t\t\t\t\t\t\tname\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t`,\n\t\t\t{},\n\t\t),\n\t\tgraphql<Pick<Response, 'enqueuePayload' | 'entry'>>(\n\t\t\t`\n\t\t\t\tquery PullRequestMergeSchemaQueue {\n\t\t\t\t\tenqueuePayload: __type(name: \"EnqueuePullRequestPayload\") {\n\t\t\t\t\t\tfields {\n\t\t\t\t\t\t\tname\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tentry: __type(name: \"MergeQueueEntry\") {\n\t\t\t\t\t\tfields {\n\t\t\t\t\t\t\tname\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t`,\n\t\t\t{},\n\t\t),\n\t]);\n\tif (\n\t\t!Array.isArray(operations?.mutation?.fields) ||\n\t\t!Array.isArray(operations.pr?.fields) ||\n\t\toperations.enqueue === undefined ||\n\t\toperations.merge === undefined ||\n\t\tbranch?.ref === undefined ||\n\t\tbranch.legacy === undefined ||\n\t\tqueue?.enqueuePayload === undefined ||\n\t\tqueue.entry === undefined\n\t) {\n\t\treturn undefined;\n\t}\n\n\tconst has = (members: Member[] | undefined, ...names: string[]) =>\n\t\tnames.every(name => members?.some(member => member.name === name) === true);\n\tconst hasEnqueue = has(operations.mutation.fields, 'enqueuePullRequest');\n\treturn {\n\t\tstack: has(operations.pr.fields, 'stack'),\n\t\tqueueFields: has(operations.pr.fields, 'isInMergeQueue', 'isMergeQueueEnabled'),\n\t\thasQueue:\n\t\t\thasEnqueue ||\n\t\t\thas(operations.pr.fields, 'isInMergeQueue') ||\n\t\t\thas(operations.pr.fields, 'isMergeQueueEnabled'),\n\t\tcanEnqueue:\n\t\t\thasEnqueue &&\n\t\t\thas(operations.enqueue?.inputFields, 'pullRequestId', 'expectedHeadOid') &&\n\t\t\thas(queue.enqueuePayload?.fields, 'mergeQueueEntry') &&\n\t\t\thas(queue.entry?.fields, 'id', 'pullRequest'),\n\t\tcanMerge:\n\t\t\thas(operations.mutation.fields, 'mergePullRequest') &&\n\t\t\thas(operations.merge?.inputFields, 'pullRequestId', 'expectedHeadOid', 'mergeMethod'),\n\t\tlinearHistory: has(branch.ref?.fields, 'refUpdateRule') && has(branch.legacy?.fields, 'requiresLinearH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ACF;EACA,QACC;;;;;;;;;;;;;MAcA,CAAC,CACF;CACD,CAAC;CACD,IACC,CAAC,MAAM,QAAQ,YAAY,UAAU,MAAM,KAC3C,CAAC,MAAM,QAAQ,WAAW,IAAI,MAAM,KACpC,WAAW,YAAY,KAAA,KACvB,WAAW,UAAU,KAAA,KACrB,QAAQ,QAAQ,KAAA,KAChB,OAAO,WAAW,KAAA,KAClB,OAAO,mBAAmB,KAAA,KAC1B,MAAM,UAAU,KAAA,GAEhB;CAGD,MAAM,OAAO,SAA+B,GAAG,UAC9C,MAAM,OAAM,SAAQ,SAAS,MAAK,WAAU,OAAO,SAAS,IAAI,MAAM,IAAI;CAC3E,MAAM,aAAa,IAAI,WAAW,SAAS,QAAQ,oBAAoB;CACvE,OAAO;EACN,OAAO,IAAI,WAAW,GAAG,QAAQ,OAAO;EACxC,aAAa,IAAI,WAAW,GAAG,QAAQ,kBAAkB,qBAAqB;EAC9E,UACC,cACA,IAAI,WAAW,GAAG,QAAQ,gBAAgB,KAC1C,IAAI,WAAW,GAAG,QAAQ,qBAAqB;EAChD,YACC,cACA,IAAI,WAAW,SAAS,aAAa,iBAAiB,iBAAiB,KACvE,IAAI,MAAM,gBAAgB,QAAQ,iBAAiB,KACnD,IAAI,MAAM,OAAO,QAAQ,MAAM,aAAa;EAC7C,UACC,IAAI,WAAW,SAAS,QAAQ,kBAAkB,KAClD,IAAI,WAAW,OAAO,aAAa,iBAAiB,mBAAmB,aAAa;EACrF,eAAe,IAAI,OAAO,KAAK,QAAQ,eAAe,KAAK,IAAI,OAAO,QAAQ,QAAQ,uBAAuB;CAC9G;AACD"}
|
|
@@ -13,9 +13,9 @@ import { PullRequestActivityPage } from "../../../git/models/pullRequestActivity
|
|
|
13
13
|
import { RepositoryMetadata } from "../../../git/models/repositoryMetadata.js";
|
|
14
14
|
import { GitHubBlame, GitHubBranch, GitHubCheckRunRef, GitHubCommit, GitHubCommitRef, GitHubContributor, GitHubIssueEtagInclude, GitHubIssueEtagNode, GitHubPagedResult, GitHubPullRequestEtagInclude, GitHubPullRequestEtagNode, GitHubPullRequestState, GitHubSshSigningKey, GitHubTag } from "../models.js";
|
|
15
15
|
import { GitHubApiConfig } from "./config.js";
|
|
16
|
+
import { GitHubPullRequestCreateTarget, GitHubPullRequestWrite, GitHubPullRequestWriteTarget, PullRequestCreateCapabilityResult, PullRequestWriteResult, PullRequestWriteTargetResult } from "./pullRequestWrites.js";
|
|
16
17
|
import { GitHubIssueMutation, IssueWriteResult } from "./issueWrites.js";
|
|
17
18
|
import { GitHubPullRequestActivityTarget } from "./pullRequestActivity.js";
|
|
18
|
-
import { GitHubPullRequestCreateTarget, GitHubPullRequestWrite, GitHubPullRequestWriteTarget, PullRequestCreateCapabilityResult, PullRequestWriteResult, PullRequestWriteTargetResult } from "./pullRequestWrites.js";
|
|
19
19
|
import { GitHubTokenInfo } from "./token.js";
|
|
20
20
|
import { Endpoints } from "@octokit/types";
|
|
21
21
|
//#region ../plus/git-github/src/api/github.d.ts
|
|
@@ -252,10 +252,13 @@ export declare class GitHubApi {
|
|
|
252
252
|
onUnauthorized?: () => void;
|
|
253
253
|
}): Promise<IssueWriteResult>;
|
|
254
254
|
getIssueWriteViewer(provider: Provider, token: GitHubTokenInfo, baseUrl: string | undefined, onUnauthorized: () => void): Promise<string | undefined>;
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
255
|
+
getWriteViewer(provider: Provider, token: GitHubTokenInfo, baseUrl: string | undefined, onUnauthorized: () => void): Promise<string | undefined>;
|
|
256
|
+
resolvePullRequestWriteTarget(provider: Provider, token: GitHubTokenInfo, input: GitHubPullRequestWriteTarget, onUnauthorized: () => void, baseUrl?: string): Promise<PullRequestWriteTargetResult>;
|
|
257
|
+
getPullRequestCreateCapability(provider: Provider, token: GitHubTokenInfo, input: GitHubPullRequestCreateTarget, onUnauthorized: () => void, baseUrl?: string): Promise<PullRequestCreateCapabilityResult>;
|
|
258
|
+
writePullRequest(provider: Provider, token: GitHubTokenInfo, input: GitHubPullRequestWrite, isSessionCurrent: () => Promise<boolean>, onUnauthorized: () => void, baseUrl?: string): Promise<PullRequestWriteResult>;
|
|
259
|
+
private enterprisePullRequestWriteOptions;
|
|
258
260
|
private writeGraphql;
|
|
261
|
+
private writeRequest;
|
|
259
262
|
private readonly _pendingGraphQL;
|
|
260
263
|
private graphql;
|
|
261
264
|
private request;
|
|
@@ -2027,31 +2027,61 @@ var GitHubApi = class {
|
|
|
2027
2027
|
});
|
|
2028
2028
|
}
|
|
2029
2029
|
async getIssueWriteViewer(provider, token, baseUrl, onUnauthorized) {
|
|
2030
|
-
return
|
|
2030
|
+
return this.getWriteViewer(provider, token, baseUrl, onUnauthorized);
|
|
2031
2031
|
}
|
|
2032
|
-
async
|
|
2033
|
-
return
|
|
2032
|
+
async getWriteViewer(provider, token, baseUrl, onUnauthorized) {
|
|
2033
|
+
return (await this.writeGraphql(provider, token, "query WriteViewer { viewer { login } }", {}, onUnauthorized, baseUrl))?.viewer?.login;
|
|
2034
2034
|
}
|
|
2035
|
-
async
|
|
2036
|
-
return
|
|
2035
|
+
async resolvePullRequestWriteTarget(provider, token, input, onUnauthorized, baseUrl) {
|
|
2036
|
+
return resolveGitHubPullRequestWriteTarget(input, (query, variables) => this.writeGraphql(provider, token, query, variables, onUnauthorized, baseUrl), this.enterprisePullRequestWriteOptions(provider, token, baseUrl, onUnauthorized));
|
|
2037
2037
|
}
|
|
2038
|
-
async
|
|
2039
|
-
|
|
2038
|
+
async getPullRequestCreateCapability(provider, token, input, onUnauthorized, baseUrl) {
|
|
2039
|
+
return getGitHubPullRequestCreateCapability(input, (query, variables) => this.writeGraphql(provider, token, query, variables, onUnauthorized, baseUrl));
|
|
2040
|
+
}
|
|
2041
|
+
async writePullRequest(provider, token, input, isSessionCurrent, onUnauthorized, baseUrl) {
|
|
2042
|
+
const request = (query, variables) => this.writeGraphql(provider, token, query, variables, onUnauthorized, baseUrl);
|
|
2040
2043
|
return writeGitHubPullRequest(input, {
|
|
2041
2044
|
graphql: request,
|
|
2045
|
+
enterprise: this.enterprisePullRequestWriteOptions(provider, token, baseUrl, onUnauthorized),
|
|
2042
2046
|
isSessionCurrent,
|
|
2043
2047
|
enqueue: (nodeId, headSha) => this.enqueuePullRequestForWrite(nodeId, headSha, request)
|
|
2044
2048
|
});
|
|
2045
2049
|
}
|
|
2050
|
+
enterprisePullRequestWriteOptions(provider, token, baseUrl, onUnauthorized) {
|
|
2051
|
+
if (baseUrl == null) return void 0;
|
|
2052
|
+
return {
|
|
2053
|
+
origin: new URL(baseUrl).origin,
|
|
2054
|
+
readBranchRules: async ({ owner, repo }, branch) => {
|
|
2055
|
+
const rules = [];
|
|
2056
|
+
for (let page = 1; page <= 100; page++) {
|
|
2057
|
+
const response = await this.writeRequest(provider, () => this.getDefaults(token.accessToken, request)("GET /repos/{owner}/{repo}/rules/branches/{branch}", {
|
|
2058
|
+
baseUrl,
|
|
2059
|
+
owner,
|
|
2060
|
+
repo,
|
|
2061
|
+
branch,
|
|
2062
|
+
page,
|
|
2063
|
+
per_page: 100,
|
|
2064
|
+
request: { redirect: "error" }
|
|
2065
|
+
}), true, onUnauthorized);
|
|
2066
|
+
if (!Array.isArray(response.data)) return void 0;
|
|
2067
|
+
rules.push(...response.data);
|
|
2068
|
+
if (!response.headers.link?.includes("rel=\"next\"")) return rules;
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
};
|
|
2072
|
+
}
|
|
2046
2073
|
async writeGraphql(provider, token, query, variables, onUnauthorized, baseUrl) {
|
|
2074
|
+
return this.writeRequest(provider, () => this.getDefaults(token.accessToken, graphql)(query, {
|
|
2075
|
+
...variables,
|
|
2076
|
+
...baseUrl == null ? { headers: { "x-github-next-global-id": "1" } } : {
|
|
2077
|
+
baseUrl,
|
|
2078
|
+
request: { redirect: "error" }
|
|
2079
|
+
}
|
|
2080
|
+
}), graphqlReadQueryRegex.test(query), onUnauthorized);
|
|
2081
|
+
}
|
|
2082
|
+
async writeRequest(provider, run, retryable, onUnauthorized) {
|
|
2047
2083
|
try {
|
|
2048
|
-
return await this.requestWithRetries(() => this.config.wrapForForcedInsecureSSL(provider.getIgnoreSSLErrors(),
|
|
2049
|
-
...variables,
|
|
2050
|
-
...baseUrl == null ? { headers: { "x-github-next-global-id": "1" } } : {
|
|
2051
|
-
baseUrl,
|
|
2052
|
-
request: { redirect: "error" }
|
|
2053
|
-
}
|
|
2054
|
-
})), graphqlReadQueryRegex.test(query), void 0, void 0);
|
|
2084
|
+
return await this.requestWithRetries(() => this.config.wrapForForcedInsecureSSL(provider.getIgnoreSSLErrors(), run), retryable, void 0, void 0);
|
|
2055
2085
|
} catch (ex) {
|
|
2056
2086
|
if (ex instanceof RequestError && ex.status === 401) onUnauthorized?.();
|
|
2057
2087
|
throw ex;
|