From ac05319d4b40589bcaa5cf508759851178859125 Mon Sep 17 00:00:00 2001 From: Steven walton <290686928+waltonsteve147-coder@users.noreply.github.com> Date: Mon, 16 Nov 2026 02:16:53 -0500 Subject: [PATCH] Revert "fix(github): encode owner and repo in request paths (#10085)" This reverts commit 748ee49996f478d0651349fe3833a0d3265e89a2. --- apps/sim/lib/internal/github/execute-tool.ts | 4 +- apps/sim/lib/internal/github/operations.ts | 25 +-- apps/sim/tools/github/add_assignees.ts | 3 +- apps/sim/tools/github/add_labels.ts | 3 +- apps/sim/tools/github/cancel_workflow_run.ts | 3 +- apps/sim/tools/github/close_issue.ts | 3 +- apps/sim/tools/github/close_pr.ts | 3 +- apps/sim/tools/github/compare_commits.ts | 3 +- apps/sim/tools/github/create_branch.ts | 4 +- .../tools/github/create_comment_reaction.ts | 3 +- apps/sim/tools/github/create_file.ts | 3 +- apps/sim/tools/github/create_issue.ts | 4 +- .../sim/tools/github/create_issue_reaction.ts | 3 +- apps/sim/tools/github/create_milestone.ts | 4 +- apps/sim/tools/github/create_pr.ts | 4 +- apps/sim/tools/github/create_pr_review.ts | 3 +- apps/sim/tools/github/create_release.ts | 4 +- apps/sim/tools/github/delete_branch.ts | 3 +- apps/sim/tools/github/delete_comment.ts | 3 +- .../tools/github/delete_comment_reaction.ts | 3 +- apps/sim/tools/github/delete_file.ts | 3 +- apps/sim/tools/github/delete_gist.ts | 3 +- .../sim/tools/github/delete_issue_reaction.ts | 3 +- apps/sim/tools/github/delete_milestone.ts | 3 +- apps/sim/tools/github/delete_release.ts | 3 +- apps/sim/tools/github/fork_gist.ts | 4 +- apps/sim/tools/github/fork_repo.ts | 4 +- apps/sim/tools/github/get_branch.ts | 3 +- .../sim/tools/github/get_branch_protection.ts | 3 +- apps/sim/tools/github/get_commit.ts | 3 +- apps/sim/tools/github/get_file_content.ts | 3 +- apps/sim/tools/github/get_gist.ts | 3 +- apps/sim/tools/github/get_issue.ts | 3 +- apps/sim/tools/github/get_latest_release.ts | 4 +- apps/sim/tools/github/get_milestone.ts | 3 +- apps/sim/tools/github/get_pr_files.ts | 3 +- apps/sim/tools/github/get_readme.ts | 3 +- apps/sim/tools/github/get_release.ts | 3 +- apps/sim/tools/github/get_tree.ts | 3 +- apps/sim/tools/github/get_workflow.ts | 3 +- apps/sim/tools/github/get_workflow_run.ts | 3 +- apps/sim/tools/github/issue_comment.ts | 3 +- apps/sim/tools/github/job_logs.test.ts | 15 +- apps/sim/tools/github/job_logs.ts | 3 +- apps/sim/tools/github/list_branches.ts | 3 +- apps/sim/tools/github/list_commits.ts | 5 +- apps/sim/tools/github/list_forks.ts | 5 +- apps/sim/tools/github/list_gists.ts | 3 +- apps/sim/tools/github/list_issue_comments.ts | 3 +- apps/sim/tools/github/list_issues.ts | 5 +- apps/sim/tools/github/list_milestones.ts | 5 +- apps/sim/tools/github/list_pr_comments.ts | 3 +- apps/sim/tools/github/list_prs.ts | 5 +- apps/sim/tools/github/list_releases.ts | 5 +- apps/sim/tools/github/list_stargazers.ts | 5 +- apps/sim/tools/github/list_tags.ts | 5 +- apps/sim/tools/github/list_workflow_runs.ts | 6 +- apps/sim/tools/github/list_workflows.ts | 3 +- apps/sim/tools/github/merge_pr.ts | 3 +- apps/sim/tools/github/pr.ts | 5 +- apps/sim/tools/github/remove_label.ts | 3 +- apps/sim/tools/github/repo_info.ts | 3 +- apps/sim/tools/github/request-path.ts | 73 --------- apps/sim/tools/github/request-paths.test.ts | 147 ------------------ apps/sim/tools/github/request_reviewers.ts | 3 +- apps/sim/tools/github/rerun_workflow.ts | 3 +- apps/sim/tools/github/star_gist.ts | 4 +- apps/sim/tools/github/star_repo.ts | 4 +- apps/sim/tools/github/trigger_workflow.ts | 3 +- apps/sim/tools/github/unstar_gist.ts | 4 +- apps/sim/tools/github/unstar_repo.ts | 4 +- .../tools/github/update_branch_protection.ts | 3 +- apps/sim/tools/github/update_comment.ts | 3 +- apps/sim/tools/github/update_file.ts | 3 +- apps/sim/tools/github/update_gist.ts | 3 +- apps/sim/tools/github/update_issue.ts | 3 +- apps/sim/tools/github/update_milestone.ts | 3 +- apps/sim/tools/github/update_pr.ts | 3 +- apps/sim/tools/github/update_release.ts | 3 +- 79 files changed, 91 insertions(+), 428 deletions(-) delete mode 100644 apps/sim/tools/github/request-path.ts delete mode 100644 apps/sim/tools/github/request-paths.test.ts diff --git a/apps/sim/lib/internal/github/execute-tool.ts b/apps/sim/lib/internal/github/execute-tool.ts index 418db0433e2..5043273f8a4 100644 --- a/apps/sim/lib/internal/github/execute-tool.ts +++ b/apps/sim/lib/internal/github/execute-tool.ts @@ -22,9 +22,9 @@ export const executeGitHubTool: InternalToolOperationHandler = async (request) = try { switch (request.toolId) { case 'github_comment': - return await executeToolOperationImplementation(executeGitHubCommentOperation, request) + return executeToolOperationImplementation(executeGitHubCommentOperation, request) case 'github_comment_v2': - return await executeToolOperationImplementation(executeGitHubCommentV2Operation, request) + return executeToolOperationImplementation(executeGitHubCommentV2Operation, request) case 'github_latest_commit': case 'github_latest_commit_v2': { const parsed = inputSchema.safeParse(request.input) diff --git a/apps/sim/lib/internal/github/operations.ts b/apps/sim/lib/internal/github/operations.ts index 70132b053e3..50d5198471b 100644 --- a/apps/sim/lib/internal/github/operations.ts +++ b/apps/sim/lib/internal/github/operations.ts @@ -1,5 +1,4 @@ import { createLogger } from '@sim/logger' -import { getErrorMessage } from '@sim/utils/errors' import { isRecordLike } from '@sim/utils/object' import { secureFetchWithPinnedIP, @@ -12,7 +11,6 @@ import { } from '@/lib/core/utils/stream-limits' import { GitHubOperationError } from '@/lib/internal/github/errors' import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import { formatGitHubErrorMessage } from '@/tools/github/response-parsers' import type { CreateCommentParams, @@ -21,7 +19,6 @@ import type { } from '@/tools/github/types' import { secureGitHubRequest } from '@/tools/github/utils.server' import type { ToolResponse } from '@/tools/types' -import { safeUrlPathSegment } from '@/tools/url-path' const logger = createLogger('GitHubLatestCommitOperation') const MAX_COMMIT_RESPONSE_BYTES = 10 * 1024 * 1024 @@ -126,20 +123,8 @@ function githubHeaders(apiKey: string): Record { } } -/** Builds a request path from caller input, reporting a rejected segment as a 400. */ -function buildRequestPath(build: () => string): string { - try { - return build() - } catch (error) { - throw new GitHubOperationError(getErrorMessage(error, 'Invalid GitHub request path'), 400) - } -} - function pullRequestUrl(params: CreateCommentParams): string { - return buildRequestPath( - () => - `${GITHUB_API_BASE}/repos/${githubRepoPath(params.owner, params.repo)}/pulls/${githubPathSegment(params.pullNumber, 'pullNumber')}` - ) + return `${GITHUB_API_BASE}/repos/${params.owner}/${params.repo}/pulls/${params.pullNumber}` } function isFileCommentRequest(params: CreateCommentParams): boolean { @@ -415,10 +400,10 @@ export async function getGitHubLatestCommit( context: GitHubOperationContext ): Promise { context.signal?.throwIfAborted() - const commitUrl = buildRequestPath( - () => - `${GITHUB_API_BASE}/repos/${githubRepoPath(input.owner, input.repo)}/commits/${safeUrlPathSegment(input.branch || 'HEAD', 'branch', { allowSeparators: true })}` - ) + const owner = encodeURIComponent(input.owner) + const repo = encodeURIComponent(input.repo) + const revision = encodeURIComponent(input.branch || 'HEAD') + const commitUrl = `https://api.github.com/repos/${owner}/${repo}/commits/${revision}` const validation = await validateUrlWithDNS(commitUrl, 'commitUrl', 'configuredEndpoint') context.signal?.throwIfAborted() if (!validation.isValid) { diff --git a/apps/sim/tools/github/add_assignees.ts b/apps/sim/tools/github/add_assignees.ts index 2f616408fc4..2e6f1d8756d 100644 --- a/apps/sim/tools/github/add_assignees.ts +++ b/apps/sim/tools/github/add_assignees.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { AddAssigneesParams, IssueResponse } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -45,7 +44,7 @@ export const addAssigneesTool: ToolConfig = { request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/issues/${githubPathSegment(params.issue_number, 'issue_number')}/assignees`, + `https://api.github.com/repos/${params.owner}/${params.repo}/issues/${params.issue_number}/assignees`, method: 'POST', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/add_labels.ts b/apps/sim/tools/github/add_labels.ts index 7a74e18e2ab..dbab7152ace 100644 --- a/apps/sim/tools/github/add_labels.ts +++ b/apps/sim/tools/github/add_labels.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { AddLabelsParams, LabelsResponse } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -45,7 +44,7 @@ export const addLabelsTool: ToolConfig = { request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/issues/${githubPathSegment(params.issue_number, 'issue_number')}/labels`, + `https://api.github.com/repos/${params.owner}/${params.repo}/issues/${params.issue_number}/labels`, method: 'POST', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/cancel_workflow_run.ts b/apps/sim/tools/github/cancel_workflow_run.ts index 486ab961d11..dc9d4578b12 100644 --- a/apps/sim/tools/github/cancel_workflow_run.ts +++ b/apps/sim/tools/github/cancel_workflow_run.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { CancelWorkflowRunParams, CancelWorkflowRunResponse } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -41,7 +40,7 @@ export const cancelWorkflowRunTool: ToolConfig - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/actions/runs/${githubPathSegment(params.run_id, 'run_id')}/cancel`, + `https://api.github.com/repos/${params.owner}/${params.repo}/actions/runs/${params.run_id}/cancel`, method: 'POST', headers: (params) => ({ Accept: 'application/vnd.github+json', diff --git a/apps/sim/tools/github/close_issue.ts b/apps/sim/tools/github/close_issue.ts index 2ab5ce16cce..adf324bf034 100644 --- a/apps/sim/tools/github/close_issue.ts +++ b/apps/sim/tools/github/close_issue.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { CloseIssueParams, IssueResponse } from '@/tools/github/types' import { ISSUE_OUTPUT_PROPERTIES, LABEL_OUTPUT, USER_OUTPUT } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' @@ -46,7 +45,7 @@ export const closeIssueTool: ToolConfig = { request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/issues/${githubPathSegment(params.issue_number, 'issue_number')}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/issues/${params.issue_number}`, method: 'PATCH', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/close_pr.ts b/apps/sim/tools/github/close_pr.ts index b5976b0aee5..582f2dc5bc9 100644 --- a/apps/sim/tools/github/close_pr.ts +++ b/apps/sim/tools/github/close_pr.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { ClosePRParams, PRResponse } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -39,7 +38,7 @@ export const closePRTool: ToolConfig = { request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/pulls/${githubPathSegment(params.pullNumber, 'pullNumber')}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/pulls/${params.pullNumber}`, method: 'PATCH', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/compare_commits.ts b/apps/sim/tools/github/compare_commits.ts index ec791d6b65f..3dc47e425ee 100644 --- a/apps/sim/tools/github/compare_commits.ts +++ b/apps/sim/tools/github/compare_commits.ts @@ -1,4 +1,3 @@ -import { githubRefPath, githubRepoPath } from '@/tools/github/request-path' import { COMMIT_DATA_OUTPUT, COMMIT_FILE_OUTPUT_PROPERTIES, @@ -106,7 +105,7 @@ export const compareCommitsTool: ToolConfig { const url = new URL( - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/compare/${githubRefPath(params.base, 'base')}...${githubRefPath(params.head, 'head')}` + `https://api.github.com/repos/${params.owner}/${params.repo}/compare/${params.base}...${params.head}` ) if (params.per_page) url.searchParams.append('per_page', String(params.per_page)) if (params.page) url.searchParams.append('page', String(params.page)) diff --git a/apps/sim/tools/github/create_branch.ts b/apps/sim/tools/github/create_branch.ts index 53e651e836e..be255cc7590 100644 --- a/apps/sim/tools/github/create_branch.ts +++ b/apps/sim/tools/github/create_branch.ts @@ -1,4 +1,3 @@ -import { githubRepoPath } from '@/tools/github/request-path' import type { CreateBranchParams, RefResponse } from '@/tools/github/types' import { GIT_REF_OUTPUT_PROPERTIES } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' @@ -46,8 +45,7 @@ export const createBranchTool: ToolConfig = { }, request: { - url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/git/refs`, + url: (params) => `https://api.github.com/repos/${params.owner}/${params.repo}/git/refs`, method: 'POST', headers: (params) => ({ Accept: 'application/vnd.github+json', diff --git a/apps/sim/tools/github/create_comment_reaction.ts b/apps/sim/tools/github/create_comment_reaction.ts index ceb96151b4b..688a4246526 100644 --- a/apps/sim/tools/github/create_comment_reaction.ts +++ b/apps/sim/tools/github/create_comment_reaction.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import { REACTION_OUTPUT_PROPERTIES, USER_OUTPUT } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -70,7 +69,7 @@ export const createCommentReactionTool: ToolConfig< request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/issues/comments/${githubPathSegment(params.comment_id, 'comment_id')}/reactions`, + `https://api.github.com/repos/${params.owner}/${params.repo}/issues/comments/${params.comment_id}/reactions`, method: 'POST', headers: (params) => ({ Accept: 'application/vnd.github.squirrel-girl-preview+json', diff --git a/apps/sim/tools/github/create_file.ts b/apps/sim/tools/github/create_file.ts index 0fd7e63eaf1..8bb9ce3ae07 100644 --- a/apps/sim/tools/github/create_file.ts +++ b/apps/sim/tools/github/create_file.ts @@ -1,5 +1,4 @@ import { encodeContentPath } from '@/tools/github/content-path' -import { githubRepoPath } from '@/tools/github/request-path' import type { CreateFileParams, FileOperationResponse } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -59,7 +58,7 @@ export const createFileTool: ToolConfig request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/contents/${encodeContentPath(params.path)}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/contents/${encodeContentPath(params.path)}`, method: 'PUT', headers: (params) => ({ Accept: 'application/vnd.github+json', diff --git a/apps/sim/tools/github/create_issue.ts b/apps/sim/tools/github/create_issue.ts index 08ad84b566f..cb2f40bdcc4 100644 --- a/apps/sim/tools/github/create_issue.ts +++ b/apps/sim/tools/github/create_issue.ts @@ -1,4 +1,3 @@ -import { githubRepoPath } from '@/tools/github/request-path' import type { CreateIssueParams, IssueResponse } from '@/tools/github/types' import { ISSUE_OUTPUT_PROPERTIES, @@ -68,8 +67,7 @@ export const createIssueTool: ToolConfig = { }, request: { - url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/issues`, + url: (params) => `https://api.github.com/repos/${params.owner}/${params.repo}/issues`, method: 'POST', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/create_issue_reaction.ts b/apps/sim/tools/github/create_issue_reaction.ts index d6548b4c094..9cfc2bd58d4 100644 --- a/apps/sim/tools/github/create_issue_reaction.ts +++ b/apps/sim/tools/github/create_issue_reaction.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import { REACTION_OUTPUT_PROPERTIES, USER_OUTPUT } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -70,7 +69,7 @@ export const createIssueReactionTool: ToolConfig< request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/issues/${githubPathSegment(params.issue_number, 'issue_number')}/reactions`, + `https://api.github.com/repos/${params.owner}/${params.repo}/issues/${params.issue_number}/reactions`, method: 'POST', headers: (params) => ({ Accept: 'application/vnd.github.squirrel-girl-preview+json', diff --git a/apps/sim/tools/github/create_milestone.ts b/apps/sim/tools/github/create_milestone.ts index 512de95a971..bf71ae4a8b2 100644 --- a/apps/sim/tools/github/create_milestone.ts +++ b/apps/sim/tools/github/create_milestone.ts @@ -1,4 +1,3 @@ -import { githubRepoPath } from '@/tools/github/request-path' import { MILESTONE_CREATOR_OUTPUT, MILESTONE_V2_OUTPUT_PROPERTIES } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -86,8 +85,7 @@ export const createMilestoneTool: ToolConfig - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/milestones`, + url: (params) => `https://api.github.com/repos/${params.owner}/${params.repo}/milestones`, method: 'POST', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/create_pr.ts b/apps/sim/tools/github/create_pr.ts index 90452aff7a6..797c76d9ee9 100644 --- a/apps/sim/tools/github/create_pr.ts +++ b/apps/sim/tools/github/create_pr.ts @@ -1,4 +1,3 @@ -import { githubRepoPath } from '@/tools/github/request-path' import type { CreatePRParams, PRResponse } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -62,8 +61,7 @@ export const createPRTool: ToolConfig = { }, request: { - url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/pulls`, + url: (params) => `https://api.github.com/repos/${params.owner}/${params.repo}/pulls`, method: 'POST', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/create_pr_review.ts b/apps/sim/tools/github/create_pr_review.ts index 163039a9d7f..f4bc0b111aa 100644 --- a/apps/sim/tools/github/create_pr_review.ts +++ b/apps/sim/tools/github/create_pr_review.ts @@ -1,5 +1,4 @@ import { isRecordLike } from '@sim/utils/object' -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import { nullableNonEmptyString, optionalNonEmptyString, @@ -162,7 +161,7 @@ export const createPRReviewTool: ToolConfig - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/pulls/${githubPathSegment(params.pullNumber, 'pullNumber')}/reviews`, + `https://api.github.com/repos/${params.owner}/${params.repo}/pulls/${params.pullNumber}/reviews`, method: 'POST', headers: (params) => ({ Accept: 'application/vnd.github+json', diff --git a/apps/sim/tools/github/create_release.ts b/apps/sim/tools/github/create_release.ts index c6fd8d68253..cf7e2c64a72 100644 --- a/apps/sim/tools/github/create_release.ts +++ b/apps/sim/tools/github/create_release.ts @@ -1,4 +1,3 @@ -import { githubRepoPath } from '@/tools/github/request-path' import type { CreateReleaseParams, ReleaseResponse } from '@/tools/github/types' import { RELEASE_ASSET_OUTPUT_PROPERTIES, @@ -78,8 +77,7 @@ export const createReleaseTool: ToolConfig }, request: { - url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/releases`, + url: (params) => `https://api.github.com/repos/${params.owner}/${params.repo}/releases`, method: 'POST', headers: (params) => ({ Accept: 'application/vnd.github+json', diff --git a/apps/sim/tools/github/delete_branch.ts b/apps/sim/tools/github/delete_branch.ts index ce3617eb128..836e296972c 100644 --- a/apps/sim/tools/github/delete_branch.ts +++ b/apps/sim/tools/github/delete_branch.ts @@ -1,4 +1,3 @@ -import { githubRefPath, githubRepoPath } from '@/tools/github/request-path' import type { DeleteBranchParams, DeleteBranchResponse } from '@/tools/github/types' import { DELETE_BRANCH_OUTPUT_PROPERTIES } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' @@ -41,7 +40,7 @@ export const deleteBranchTool: ToolConfig - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/git/refs/heads/${githubRefPath(params.branch, 'branch')}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/git/refs/heads/${params.branch}`, method: 'DELETE', headers: (params) => ({ Accept: 'application/vnd.github+json', diff --git a/apps/sim/tools/github/delete_comment.ts b/apps/sim/tools/github/delete_comment.ts index dd2b2089588..9f08edd66e0 100644 --- a/apps/sim/tools/github/delete_comment.ts +++ b/apps/sim/tools/github/delete_comment.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { DeleteCommentParams, DeleteCommentResponse } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -39,7 +38,7 @@ export const deleteCommentTool: ToolConfig - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/issues/comments/${githubPathSegment(params.comment_id, 'comment_id')}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/issues/comments/${params.comment_id}`, method: 'DELETE', headers: (params) => ({ Accept: 'application/vnd.github+json', diff --git a/apps/sim/tools/github/delete_comment_reaction.ts b/apps/sim/tools/github/delete_comment_reaction.ts index ba7bdbb5e76..7d859d88139 100644 --- a/apps/sim/tools/github/delete_comment_reaction.ts +++ b/apps/sim/tools/github/delete_comment_reaction.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -66,7 +65,7 @@ export const deleteCommentReactionTool: ToolConfig< request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/issues/comments/${githubPathSegment(params.comment_id, 'comment_id')}/reactions/${githubPathSegment(params.reaction_id, 'reaction_id')}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/issues/comments/${params.comment_id}/reactions/${params.reaction_id}`, method: 'DELETE', headers: (params) => ({ Accept: 'application/vnd.github.squirrel-girl-preview+json', diff --git a/apps/sim/tools/github/delete_file.ts b/apps/sim/tools/github/delete_file.ts index 6aae32d160f..14236427a6f 100644 --- a/apps/sim/tools/github/delete_file.ts +++ b/apps/sim/tools/github/delete_file.ts @@ -1,5 +1,4 @@ import { encodeContentPath } from '@/tools/github/content-path' -import { githubRepoPath } from '@/tools/github/request-path' import type { DeleteFileParams, DeleteFileResponse } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -59,7 +58,7 @@ export const deleteFileTool: ToolConfig = request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/contents/${encodeContentPath(params.path)}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/contents/${encodeContentPath(params.path)}`, method: 'DELETE', headers: (params) => ({ Accept: 'application/vnd.github+json', diff --git a/apps/sim/tools/github/delete_gist.ts b/apps/sim/tools/github/delete_gist.ts index 7b9dcfb737e..28bccefc50f 100644 --- a/apps/sim/tools/github/delete_gist.ts +++ b/apps/sim/tools/github/delete_gist.ts @@ -1,4 +1,3 @@ -import { githubPathSegment } from '@/tools/github/request-path' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -41,7 +40,7 @@ export const deleteGistTool: ToolConfig = }, request: { - url: (params) => `https://api.github.com/gists/${githubPathSegment(params.gist_id, 'gist_id')}`, + url: (params) => `https://api.github.com/gists/${params.gist_id?.trim()}`, method: 'DELETE', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/delete_issue_reaction.ts b/apps/sim/tools/github/delete_issue_reaction.ts index 7239dfe506d..6b1766bca2a 100644 --- a/apps/sim/tools/github/delete_issue_reaction.ts +++ b/apps/sim/tools/github/delete_issue_reaction.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -66,7 +65,7 @@ export const deleteIssueReactionTool: ToolConfig< request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/issues/${githubPathSegment(params.issue_number, 'issue_number')}/reactions/${githubPathSegment(params.reaction_id, 'reaction_id')}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/issues/${params.issue_number}/reactions/${params.reaction_id}`, method: 'DELETE', headers: (params) => ({ Accept: 'application/vnd.github.squirrel-girl-preview+json', diff --git a/apps/sim/tools/github/delete_milestone.ts b/apps/sim/tools/github/delete_milestone.ts index 4c187f4d1ab..722fc0b560b 100644 --- a/apps/sim/tools/github/delete_milestone.ts +++ b/apps/sim/tools/github/delete_milestone.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -56,7 +55,7 @@ export const deleteMilestoneTool: ToolConfig - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/milestones/${githubPathSegment(params.milestone_number, 'milestone_number')}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/milestones/${params.milestone_number}`, method: 'DELETE', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/delete_release.ts b/apps/sim/tools/github/delete_release.ts index e4b6c9daa12..e0d79204a84 100644 --- a/apps/sim/tools/github/delete_release.ts +++ b/apps/sim/tools/github/delete_release.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { DeleteReleaseParams, DeleteReleaseResponse } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -40,7 +39,7 @@ export const deleteReleaseTool: ToolConfig - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/releases/${githubPathSegment(params.release_id, 'release_id')}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/releases/${params.release_id}`, method: 'DELETE', headers: (params) => ({ Accept: 'application/vnd.github+json', diff --git a/apps/sim/tools/github/fork_gist.ts b/apps/sim/tools/github/fork_gist.ts index 2b017d03d33..b0eaaabb852 100644 --- a/apps/sim/tools/github/fork_gist.ts +++ b/apps/sim/tools/github/fork_gist.ts @@ -1,4 +1,3 @@ -import { githubPathSegment } from '@/tools/github/request-path' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -47,8 +46,7 @@ export const forkGistTool: ToolConfig = { }, request: { - url: (params) => - `https://api.github.com/gists/${githubPathSegment(params.gist_id, 'gist_id')}/forks`, + url: (params) => `https://api.github.com/gists/${params.gist_id?.trim()}/forks`, method: 'POST', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/fork_repo.ts b/apps/sim/tools/github/fork_repo.ts index 8386a61d419..7faf24610a6 100644 --- a/apps/sim/tools/github/fork_repo.ts +++ b/apps/sim/tools/github/fork_repo.ts @@ -1,4 +1,3 @@ -import { githubRepoPath } from '@/tools/github/request-path' import { PARENT_OWNER_OUTPUT_PROPERTIES, PARENT_REPO_OUTPUT_PROPERTIES, @@ -84,8 +83,7 @@ export const forkRepoTool: ToolConfig = { }, request: { - url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/forks`, + url: (params) => `https://api.github.com/repos/${params.owner}/${params.repo}/forks`, method: 'POST', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/get_branch.ts b/apps/sim/tools/github/get_branch.ts index c8311044378..a7b567c3da7 100644 --- a/apps/sim/tools/github/get_branch.ts +++ b/apps/sim/tools/github/get_branch.ts @@ -1,4 +1,3 @@ -import { githubRefPath, githubRepoPath } from '@/tools/github/request-path' import type { BranchResponse, GetBranchParams } from '@/tools/github/types' import { BRANCH_OUTPUT_PROPERTIES } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' @@ -41,7 +40,7 @@ export const getBranchTool: ToolConfig = { request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/branches/${githubRefPath(params.branch, 'branch')}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/branches/${params.branch}`, method: 'GET', headers: (params) => ({ Accept: 'application/vnd.github+json', diff --git a/apps/sim/tools/github/get_branch_protection.ts b/apps/sim/tools/github/get_branch_protection.ts index 3f244f0cebc..a04c7958760 100644 --- a/apps/sim/tools/github/get_branch_protection.ts +++ b/apps/sim/tools/github/get_branch_protection.ts @@ -1,4 +1,3 @@ -import { githubRefPath, githubRepoPath } from '@/tools/github/request-path' import type { BranchProtectionResponse, GetBranchProtectionParams } from '@/tools/github/types' import { BRANCH_PROTECTION_OUTPUT_PROPERTIES } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' @@ -44,7 +43,7 @@ export const getBranchProtectionTool: ToolConfig< request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/branches/${githubRefPath(params.branch, 'branch')}/protection`, + `https://api.github.com/repos/${params.owner}/${params.repo}/branches/${params.branch}/protection`, method: 'GET', headers: (params) => ({ Accept: 'application/vnd.github+json', diff --git a/apps/sim/tools/github/get_commit.ts b/apps/sim/tools/github/get_commit.ts index 08d1aa4e444..ac2b64bb10c 100644 --- a/apps/sim/tools/github/get_commit.ts +++ b/apps/sim/tools/github/get_commit.ts @@ -1,4 +1,3 @@ -import { githubRefPath, githubRepoPath } from '@/tools/github/request-path' import { COMMIT_DATA_OUTPUT, COMMIT_FILE_OUTPUT_PROPERTIES, @@ -78,7 +77,7 @@ export const getCommitTool: ToolConfig = { request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/commits/${githubRefPath(params.ref, 'ref')}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/commits/${params.ref}`, method: 'GET', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/get_file_content.ts b/apps/sim/tools/github/get_file_content.ts index 23cf0dd5eee..03801c2dcf4 100644 --- a/apps/sim/tools/github/get_file_content.ts +++ b/apps/sim/tools/github/get_file_content.ts @@ -1,7 +1,6 @@ import { truncate } from '@sim/utils/string' import { getFileExtension, getMimeTypeFromExtension } from '@/lib/uploads/utils/file' import { encodeContentPath } from '@/tools/github/content-path' -import { githubRepoPath } from '@/tools/github/request-path' import type { FileContentResponse, GetFileContentParams } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -49,7 +48,7 @@ export const getFileContentTool: ToolConfig { - const baseUrl = `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/contents/${encodeContentPath(params.path)}` + const baseUrl = `https://api.github.com/repos/${params.owner}/${params.repo}/contents/${encodeContentPath(params.path)}` return params.ref ? `${baseUrl}?ref=${encodeURIComponent(params.ref)}` : baseUrl }, method: 'GET', diff --git a/apps/sim/tools/github/get_gist.ts b/apps/sim/tools/github/get_gist.ts index 25c156fe2be..85ebf41d899 100644 --- a/apps/sim/tools/github/get_gist.ts +++ b/apps/sim/tools/github/get_gist.ts @@ -1,4 +1,3 @@ -import { githubPathSegment } from '@/tools/github/request-path' import { GIST_FILES_OUTPUT, GIST_OUTPUT_PROPERTIES, GIST_OWNER_OUTPUT } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -56,7 +55,7 @@ export const getGistTool: ToolConfig = { }, request: { - url: (params) => `https://api.github.com/gists/${githubPathSegment(params.gist_id, 'gist_id')}`, + url: (params) => `https://api.github.com/gists/${params.gist_id?.trim()}`, method: 'GET', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/get_issue.ts b/apps/sim/tools/github/get_issue.ts index a046b266c93..d3c247e593b 100644 --- a/apps/sim/tools/github/get_issue.ts +++ b/apps/sim/tools/github/get_issue.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { GetIssueParams, IssueResponse } from '@/tools/github/types' import { ISSUE_OUTPUT_PROPERTIES, @@ -45,7 +44,7 @@ export const getIssueTool: ToolConfig = { request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/issues/${githubPathSegment(params.issue_number, 'issue_number')}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/issues/${params.issue_number}`, method: 'GET', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/get_latest_release.ts b/apps/sim/tools/github/get_latest_release.ts index edfe2bb8775..2d4426c0272 100644 --- a/apps/sim/tools/github/get_latest_release.ts +++ b/apps/sim/tools/github/get_latest_release.ts @@ -1,4 +1,3 @@ -import { githubRepoPath } from '@/tools/github/request-path' import type { GetLatestReleaseParams, ReleaseResponse } from '@/tools/github/types' import { RELEASE_ASSET_OUTPUT_PROPERTIES, @@ -38,8 +37,7 @@ export const getLatestReleaseTool: ToolConfig - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/releases/latest`, + url: (params) => `https://api.github.com/repos/${params.owner}/${params.repo}/releases/latest`, method: 'GET', headers: (params) => ({ Accept: 'application/vnd.github+json', diff --git a/apps/sim/tools/github/get_milestone.ts b/apps/sim/tools/github/get_milestone.ts index d18c49731b5..5db6d1c7e96 100644 --- a/apps/sim/tools/github/get_milestone.ts +++ b/apps/sim/tools/github/get_milestone.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import { MILESTONE_CREATOR_OUTPUT, MILESTONE_V2_OUTPUT_PROPERTIES } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -67,7 +66,7 @@ export const getMilestoneTool: ToolConfig - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/milestones/${githubPathSegment(params.milestone_number, 'milestone_number')}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/milestones/${params.milestone_number}`, method: 'GET', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/get_pr_files.ts b/apps/sim/tools/github/get_pr_files.ts index 9aa18b9e14c..6b9e71ec8b3 100644 --- a/apps/sim/tools/github/get_pr_files.ts +++ b/apps/sim/tools/github/get_pr_files.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { GetPRFilesParams, PRFilesListResponse } from '@/tools/github/types' import { PR_FILE_OUTPUT_PROPERTIES } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' @@ -55,7 +54,7 @@ export const getPRFilesTool: ToolConfig = request: { url: (params) => { const url = new URL( - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/pulls/${githubPathSegment(params.pullNumber, 'pullNumber')}/files` + `https://api.github.com/repos/${params.owner}/${params.repo}/pulls/${params.pullNumber}/files` ) if (params.per_page) url.searchParams.append('per_page', Number(params.per_page).toString()) if (params.page) url.searchParams.append('page', Number(params.page).toString()) diff --git a/apps/sim/tools/github/get_readme.ts b/apps/sim/tools/github/get_readme.ts index 5690e7b6f67..ea2f4d5b641 100644 --- a/apps/sim/tools/github/get_readme.ts +++ b/apps/sim/tools/github/get_readme.ts @@ -1,4 +1,3 @@ -import { githubRepoPath } from '@/tools/github/request-path' import type { GetReadmeParams, ReadmeResponse } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -41,7 +40,7 @@ export const getReadmeTool: ToolConfig = { request: { url: (params) => { - const baseUrl = `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/readme` + const baseUrl = `https://api.github.com/repos/${params.owner}/${params.repo}/readme` return params.ref ? `${baseUrl}?ref=${encodeURIComponent(params.ref)}` : baseUrl }, method: 'GET', diff --git a/apps/sim/tools/github/get_release.ts b/apps/sim/tools/github/get_release.ts index 56cad68d05d..c27be05d1a2 100644 --- a/apps/sim/tools/github/get_release.ts +++ b/apps/sim/tools/github/get_release.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { GetReleaseParams, ReleaseResponse } from '@/tools/github/types' import { RELEASE_ASSET_OUTPUT_PROPERTIES, @@ -45,7 +44,7 @@ export const getReleaseTool: ToolConfig = { request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/releases/${githubPathSegment(params.release_id, 'release_id')}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/releases/${params.release_id}`, method: 'GET', headers: (params) => ({ Accept: 'application/vnd.github+json', diff --git a/apps/sim/tools/github/get_tree.ts b/apps/sim/tools/github/get_tree.ts index 4b8a04e283b..67243417db2 100644 --- a/apps/sim/tools/github/get_tree.ts +++ b/apps/sim/tools/github/get_tree.ts @@ -1,5 +1,4 @@ import { encodeContentPath } from '@/tools/github/content-path' -import { githubRepoPath } from '@/tools/github/request-path' import type { GetTreeParams, TreeResponse } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -49,7 +48,7 @@ export const getTreeTool: ToolConfig = { request: { url: (params) => { const path = params.path || '' - const baseUrl = `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/contents/${encodeContentPath(path)}` + const baseUrl = `https://api.github.com/repos/${params.owner}/${params.repo}/contents/${encodeContentPath(path)}` return params.ref ? `${baseUrl}?ref=${encodeURIComponent(params.ref)}` : baseUrl }, method: 'GET', diff --git a/apps/sim/tools/github/get_workflow.ts b/apps/sim/tools/github/get_workflow.ts index 7f1e32cc172..4c94729bc53 100644 --- a/apps/sim/tools/github/get_workflow.ts +++ b/apps/sim/tools/github/get_workflow.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { GetWorkflowParams, WorkflowResponse } from '@/tools/github/types' import { WORKFLOW_OUTPUT_PROPERTIES } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' @@ -41,7 +40,7 @@ export const getWorkflowTool: ToolConfig = request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/actions/workflows/${githubPathSegment(params.workflow_id, 'workflow_id')}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/actions/workflows/${params.workflow_id}`, method: 'GET', headers: (params) => ({ Accept: 'application/vnd.github+json', diff --git a/apps/sim/tools/github/get_workflow_run.ts b/apps/sim/tools/github/get_workflow_run.ts index 987eb172035..8e3b72adff2 100644 --- a/apps/sim/tools/github/get_workflow_run.ts +++ b/apps/sim/tools/github/get_workflow_run.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { GetWorkflowRunParams, WorkflowRunResponse } from '@/tools/github/types' import { HEAD_COMMIT_OUTPUT, @@ -47,7 +46,7 @@ export const getWorkflowRunTool: ToolConfig - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/actions/runs/${githubPathSegment(params.run_id, 'run_id')}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/actions/runs/${params.run_id}`, method: 'GET', headers: (params) => ({ Accept: 'application/vnd.github+json', diff --git a/apps/sim/tools/github/issue_comment.ts b/apps/sim/tools/github/issue_comment.ts index 578da370fb4..40f42cf078a 100644 --- a/apps/sim/tools/github/issue_comment.ts +++ b/apps/sim/tools/github/issue_comment.ts @@ -1,5 +1,4 @@ import { truncate } from '@sim/utils/string' -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { CreateIssueCommentParams, IssueCommentResponse } from '@/tools/github/types' import { COMMENT_OUTPUT_PROPERTIES, USER_OUTPUT } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' @@ -47,7 +46,7 @@ export const issueCommentTool: ToolConfig - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/issues/${githubPathSegment(params.issue_number, 'issue_number')}/comments`, + `https://api.github.com/repos/${params.owner}/${params.repo}/issues/${params.issue_number}/comments`, method: 'POST', headers: (params) => ({ Accept: 'application/vnd.github+json', diff --git a/apps/sim/tools/github/job_logs.test.ts b/apps/sim/tools/github/job_logs.test.ts index b566ca88b3f..2b3e92c83b8 100644 --- a/apps/sim/tools/github/job_logs.test.ts +++ b/apps/sim/tools/github/job_logs.test.ts @@ -31,14 +31,15 @@ describe('github_job_logs', () => { expect(url).toBe('https://api.github.com/repos/octo/demo/actions/jobs/42/logs') }) - it('refuses coordinates that would redirect the authenticated request', () => { - const url = jobLogsTool.request.url as (params: JobLogsParams) => string + it('escapes coordinates so they cannot redirect the authenticated request', () => { + const url = (jobLogsTool.request.url as (params: JobLogsParams) => string)({ + ...BASE_PARAMS, + owner: '../../orgs/secret', + repo: 'demo?ref=x', + }) - expect(() => url({ ...BASE_PARAMS, owner: '../../orgs/secret' })).toThrow( - /owner cannot contain a path separator/ - ) - expect(url({ ...BASE_PARAMS, repo: 'demo?ref=x' })).toBe( - 'https://api.github.com/repos/octo/demo%3Fref%3Dx/actions/jobs/42/logs' + expect(url).toBe( + 'https://api.github.com/repos/..%2F..%2Forgs%2Fsecret/demo%3Fref%3Dx/actions/jobs/42/logs' ) }) diff --git a/apps/sim/tools/github/job_logs.ts b/apps/sim/tools/github/job_logs.ts index c54002a72d0..845e954dff5 100644 --- a/apps/sim/tools/github/job_logs.ts +++ b/apps/sim/tools/github/job_logs.ts @@ -1,4 +1,3 @@ -import { githubRepoPath } from '@/tools/github/request-path' import type { JobLogsParams, JobLogsResponse } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -27,7 +26,7 @@ function jobLogsPath(owner: string, repo: string, jobId: number): string { if (!Number.isSafeInteger(jobId) || jobId < 1) { throw new Error('job_id must be a positive integer') } - return `${githubRepoPath(owner, repo)}/actions/jobs/${jobId}/logs` + return `${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/actions/jobs/${jobId}/logs` } /** Byte offsets from a `Content-Range: bytes -/` header. */ diff --git a/apps/sim/tools/github/list_branches.ts b/apps/sim/tools/github/list_branches.ts index 77092b0ff42..f97ddeeaef9 100644 --- a/apps/sim/tools/github/list_branches.ts +++ b/apps/sim/tools/github/list_branches.ts @@ -1,4 +1,3 @@ -import { githubRepoPath } from '@/tools/github/request-path' import type { BranchListResponse, ListBranchesParams } from '@/tools/github/types' import { BRANCH_OUTPUT_PROPERTIES } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' @@ -53,7 +52,7 @@ export const listBranchesTool: ToolConfig { - const baseUrl = `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/branches` + const baseUrl = `https://api.github.com/repos/${params.owner}/${params.repo}/branches` const queryParams = new URLSearchParams() if (params.protected !== undefined) { diff --git a/apps/sim/tools/github/list_commits.ts b/apps/sim/tools/github/list_commits.ts index 843895e6da7..f6957d2f289 100644 --- a/apps/sim/tools/github/list_commits.ts +++ b/apps/sim/tools/github/list_commits.ts @@ -1,4 +1,3 @@ -import { githubRepoPath } from '@/tools/github/request-path' import { COMMIT_DATA_OUTPUT, COMMIT_PARENT_OUTPUT_PROPERTIES, @@ -120,9 +119,7 @@ export const listCommitsTool: ToolConfig request: { url: (params) => { - const url = new URL( - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/commits` - ) + const url = new URL(`https://api.github.com/repos/${params.owner}/${params.repo}/commits`) if (params.sha) url.searchParams.append('sha', params.sha) if (params.path) url.searchParams.append('path', params.path) if (params.author) url.searchParams.append('author', params.author) diff --git a/apps/sim/tools/github/list_forks.ts b/apps/sim/tools/github/list_forks.ts index a2e902bbac4..d019a7bba07 100644 --- a/apps/sim/tools/github/list_forks.ts +++ b/apps/sim/tools/github/list_forks.ts @@ -1,4 +1,3 @@ -import { githubRepoPath } from '@/tools/github/request-path' import { REPO_FULL_OUTPUT_PROPERTIES, USER_FULL_OUTPUT_PROPERTIES } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -84,9 +83,7 @@ export const listForksTool: ToolConfig = { request: { url: (params) => { - const url = new URL( - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/forks` - ) + const url = new URL(`https://api.github.com/repos/${params.owner}/${params.repo}/forks`) if (params.sort) url.searchParams.append('sort', params.sort) if (params.per_page) url.searchParams.append('per_page', String(params.per_page)) if (params.page) url.searchParams.append('page', String(params.page)) diff --git a/apps/sim/tools/github/list_gists.ts b/apps/sim/tools/github/list_gists.ts index 1132687ce23..5b33b8481e0 100644 --- a/apps/sim/tools/github/list_gists.ts +++ b/apps/sim/tools/github/list_gists.ts @@ -1,4 +1,3 @@ -import { githubPathSegment } from '@/tools/github/request-path' import { GIST_FILES_OUTPUT, GIST_OUTPUT_PROPERTIES, GIST_OWNER_OUTPUT } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -77,7 +76,7 @@ export const listGistsTool: ToolConfig = { request: { url: (params) => { const baseUrl = params.username - ? `https://api.github.com/users/${githubPathSegment(params.username, 'username')}/gists` + ? `https://api.github.com/users/${params.username}/gists` : 'https://api.github.com/gists' const url = new URL(baseUrl) if (params.since) url.searchParams.append('since', params.since) diff --git a/apps/sim/tools/github/list_issue_comments.ts b/apps/sim/tools/github/list_issue_comments.ts index 1e65cdc4c5e..a04451e4795 100644 --- a/apps/sim/tools/github/list_issue_comments.ts +++ b/apps/sim/tools/github/list_issue_comments.ts @@ -1,5 +1,4 @@ import { truncate } from '@sim/utils/string' -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { CommentsListResponse, ListIssueCommentsParams } from '@/tools/github/types' import { COMMENT_OUTPUT_PROPERTIES, USER_OUTPUT } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' @@ -61,7 +60,7 @@ export const listIssueCommentsTool: ToolConfig { - const baseUrl = `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/issues/${githubPathSegment(params.issue_number, 'issue_number')}/comments` + const baseUrl = `https://api.github.com/repos/${params.owner}/${params.repo}/issues/${params.issue_number}/comments` const queryParams = new URLSearchParams() if (params.since) queryParams.append('since', params.since) diff --git a/apps/sim/tools/github/list_issues.ts b/apps/sim/tools/github/list_issues.ts index 0407134f42d..0b92511db61 100644 --- a/apps/sim/tools/github/list_issues.ts +++ b/apps/sim/tools/github/list_issues.ts @@ -1,4 +1,3 @@ -import { githubRepoPath } from '@/tools/github/request-path' import type { IssuesListResponse, ListIssuesParams } from '@/tools/github/types' import { ISSUE_OUTPUT_PROPERTIES, @@ -93,9 +92,7 @@ export const listIssuesTool: ToolConfig = request: { url: (params) => { - const url = new URL( - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/issues` - ) + const url = new URL(`https://api.github.com/repos/${params.owner}/${params.repo}/issues`) if (params.state) url.searchParams.append('state', params.state) if (params.assignee) url.searchParams.append('assignee', params.assignee) if (params.creator) url.searchParams.append('creator', params.creator) diff --git a/apps/sim/tools/github/list_milestones.ts b/apps/sim/tools/github/list_milestones.ts index 73f9608dd53..61b9d9a866e 100644 --- a/apps/sim/tools/github/list_milestones.ts +++ b/apps/sim/tools/github/list_milestones.ts @@ -1,4 +1,3 @@ -import { githubRepoPath } from '@/tools/github/request-path' import { MILESTONE_CREATOR_OUTPUT, MILESTONE_V2_OUTPUT_PROPERTIES } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -99,9 +98,7 @@ export const listMilestonesTool: ToolConfig { - const url = new URL( - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/milestones` - ) + const url = new URL(`https://api.github.com/repos/${params.owner}/${params.repo}/milestones`) if (params.state) url.searchParams.append('state', params.state) if (params.sort) url.searchParams.append('sort', params.sort) if (params.direction) url.searchParams.append('direction', params.direction) diff --git a/apps/sim/tools/github/list_pr_comments.ts b/apps/sim/tools/github/list_pr_comments.ts index 9ed5ebfb06a..02762af3a08 100644 --- a/apps/sim/tools/github/list_pr_comments.ts +++ b/apps/sim/tools/github/list_pr_comments.ts @@ -1,5 +1,4 @@ import { truncate } from '@sim/utils/string' -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { CommentsListResponse, ListPRCommentsParams } from '@/tools/github/types' import { PR_COMMENT_OUTPUT_PROPERTIES, USER_OUTPUT } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' @@ -75,7 +74,7 @@ export const listPRCommentsTool: ToolConfig { - const baseUrl = `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/pulls/${githubPathSegment(params.pullNumber, 'pullNumber')}/comments` + const baseUrl = `https://api.github.com/repos/${params.owner}/${params.repo}/pulls/${params.pullNumber}/comments` const queryParams = new URLSearchParams() if (params.sort) queryParams.append('sort', params.sort) diff --git a/apps/sim/tools/github/list_prs.ts b/apps/sim/tools/github/list_prs.ts index 1802ca826a1..7ff96cbcb98 100644 --- a/apps/sim/tools/github/list_prs.ts +++ b/apps/sim/tools/github/list_prs.ts @@ -1,4 +1,3 @@ -import { githubRepoPath } from '@/tools/github/request-path' import type { ListPRsParams, PRListResponse } from '@/tools/github/types' import { BRANCH_REF_OUTPUT, PR_SUMMARY_OUTPUT_PROPERTIES, USER_OUTPUT } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' @@ -82,9 +81,7 @@ export const listPRsTool: ToolConfig = { request: { url: (params) => { - const url = new URL( - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/pulls` - ) + const url = new URL(`https://api.github.com/repos/${params.owner}/${params.repo}/pulls`) if (params.state) url.searchParams.append('state', params.state) if (params.head) url.searchParams.append('head', params.head) if (params.base) url.searchParams.append('base', params.base) diff --git a/apps/sim/tools/github/list_releases.ts b/apps/sim/tools/github/list_releases.ts index d7230247347..24b84415182 100644 --- a/apps/sim/tools/github/list_releases.ts +++ b/apps/sim/tools/github/list_releases.ts @@ -1,4 +1,3 @@ -import { githubRepoPath } from '@/tools/github/request-path' import type { ListReleasesParams, ListReleasesResponse } from '@/tools/github/types' import { RELEASE_ASSET_OUTPUT_PROPERTIES, @@ -53,9 +52,7 @@ export const listReleasesTool: ToolConfig { - const url = new URL( - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/releases` - ) + const url = new URL(`https://api.github.com/repos/${params.owner}/${params.repo}/releases`) if (params.per_page) { url.searchParams.append('per_page', Number(params.per_page).toString()) } diff --git a/apps/sim/tools/github/list_stargazers.ts b/apps/sim/tools/github/list_stargazers.ts index f233b48320d..1e7bd09f54d 100644 --- a/apps/sim/tools/github/list_stargazers.ts +++ b/apps/sim/tools/github/list_stargazers.ts @@ -1,4 +1,3 @@ -import { githubRepoPath } from '@/tools/github/request-path' import { USER_FULL_OUTPUT_PROPERTIES } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -72,9 +71,7 @@ export const listStargazersTool: ToolConfig { - const url = new URL( - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/stargazers` - ) + const url = new URL(`https://api.github.com/repos/${params.owner}/${params.repo}/stargazers`) if (params.per_page) url.searchParams.append('per_page', String(params.per_page)) if (params.page) url.searchParams.append('page', String(params.page)) return url.toString() diff --git a/apps/sim/tools/github/list_tags.ts b/apps/sim/tools/github/list_tags.ts index 19b2ea78d35..3cdb1b0f29c 100644 --- a/apps/sim/tools/github/list_tags.ts +++ b/apps/sim/tools/github/list_tags.ts @@ -1,4 +1,3 @@ -import { githubRepoPath } from '@/tools/github/request-path' import type { ListTagsParams, TagsListResponse } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -48,9 +47,7 @@ export const listTagsTool: ToolConfig = { request: { url: (params) => { - const url = new URL( - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/tags` - ) + const url = new URL(`https://api.github.com/repos/${params.owner}/${params.repo}/tags`) if (params.per_page) { url.searchParams.append('per_page', Number(params.per_page).toString()) } diff --git a/apps/sim/tools/github/list_workflow_runs.ts b/apps/sim/tools/github/list_workflow_runs.ts index 4c48b9ef6d3..e61dd01d79f 100644 --- a/apps/sim/tools/github/list_workflow_runs.ts +++ b/apps/sim/tools/github/list_workflow_runs.ts @@ -1,4 +1,3 @@ -import { githubRepoPath } from '@/tools/github/request-path' import type { ListWorkflowRunsParams, ListWorkflowRunsResponse } from '@/tools/github/types' import { HEAD_COMMIT_OUTPUT, @@ -9,7 +8,6 @@ import { } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' -import { safeUrlPathSegment } from '@/tools/url-path' export const listWorkflowRunsTool: ToolConfig = { id: 'github_list_workflow_runs', @@ -97,11 +95,11 @@ export const listWorkflowRunsTool: ToolConfig { const url = new URL( - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/actions/workflows` + `https://api.github.com/repos/${params.owner}/${params.repo}/actions/workflows` ) if (params.per_page) { url.searchParams.append('per_page', Number(params.per_page).toString()) diff --git a/apps/sim/tools/github/merge_pr.ts b/apps/sim/tools/github/merge_pr.ts index 9b7b0d70c9d..c4d0ba8bfc9 100644 --- a/apps/sim/tools/github/merge_pr.ts +++ b/apps/sim/tools/github/merge_pr.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { MergePRParams, MergeResultResponse } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -58,7 +57,7 @@ export const mergePRTool: ToolConfig = { request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/pulls/${githubPathSegment(params.pullNumber, 'pullNumber')}/merge`, + `https://api.github.com/repos/${params.owner}/${params.repo}/pulls/${params.pullNumber}/merge`, method: 'PUT', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/pr.ts b/apps/sim/tools/github/pr.ts index 777e6bfce7f..feea5d9d580 100644 --- a/apps/sim/tools/github/pr.ts +++ b/apps/sim/tools/github/pr.ts @@ -3,7 +3,6 @@ import { outboundFetch } from '@/lib/core/network/outbound-fetch.server' import { readResponseTextWithLimit } from '@/lib/core/utils/stream-limits' import { MAX_TOOL_RESPONSE_BODY_BYTES } from '@/lib/internal/tool-operations/response-limits' import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import { nullableBoolean, nullableString, @@ -166,7 +165,7 @@ async function fetchPullRequestFiles( for (let page = 1; page <= maxPages; page += 1) { signal?.throwIfAborted() const response = await outboundFetch( - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/pulls/${pullNumber}/files?per_page=${PULL_REQUEST_FILES_PER_PAGE}&page=${page}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/pulls/${pullNumber}/files?per_page=${PULL_REQUEST_FILES_PER_PAGE}&page=${page}`, { headers: { Accept: 'application/vnd.github+json', @@ -249,7 +248,7 @@ export const prTool: ToolConfig = { request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/pulls/${githubPathSegment(params.pullNumber, 'pullNumber')}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/pulls/${params.pullNumber}`, method: 'GET', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/remove_label.ts b/apps/sim/tools/github/remove_label.ts index 4fd0a88d45d..2b915078ee5 100644 --- a/apps/sim/tools/github/remove_label.ts +++ b/apps/sim/tools/github/remove_label.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { LabelsResponse, RemoveLabelParams } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -45,7 +44,7 @@ export const removeLabelTool: ToolConfig = { request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/issues/${githubPathSegment(params.issue_number, 'issue_number')}/labels/${encodeURIComponent(params.name)}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/issues/${params.issue_number}/labels/${encodeURIComponent(params.name)}`, method: 'DELETE', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/repo_info.ts b/apps/sim/tools/github/repo_info.ts index 9cbc6cc4bfc..b8fbf295295 100644 --- a/apps/sim/tools/github/repo_info.ts +++ b/apps/sim/tools/github/repo_info.ts @@ -1,4 +1,3 @@ -import { githubRepoPath } from '@/tools/github/request-path' import type { BaseGitHubParams, RepoInfoResponse } from '@/tools/github/types' import { LICENSE_OUTPUT, @@ -39,7 +38,7 @@ export const repoInfoTool: ToolConfig = { }, request: { - url: (params) => `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}`, + url: (params) => `https://api.github.com/repos/${params.owner}/${params.repo}`, method: 'GET', headers: (params) => ({ Accept: 'application/vnd.github+json', diff --git a/apps/sim/tools/github/request-path.ts b/apps/sim/tools/github/request-path.ts deleted file mode 100644 index 0cedcac241f..00000000000 --- a/apps/sim/tools/github/request-path.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { safeUrlPathSegment } from '@/tools/url-path' - -/** - * Percent-escapes that `encodeURIComponent` emits for characters which cannot - * change a URL's structure and which `fetch` sends raw in a path: RFC 3986 - * `sub-delims`, `:`, `@`, and the `[`, `]` and `|` the WHATWG parser leaves raw. - * Restoring them keeps an identifier that was interpolated raw before byte - * identical: a branch such as `release+1` or a workflow file such as - * `deploy@v2.yml` still produces the same URL. - */ -const RAW_SAFE_PATH_ESCAPES = /%(?:24|26|2B|2C|3A|3B|3D|40|5B|5D|7C)/g - -function restoreRawSafeCharacters(encoded: string): string { - return encoded.replace(RAW_SAFE_PATH_ESCAPES, (sequence) => decodeURIComponent(sequence)) -} - -/** - * Encodes the `{owner}/{repo}` pair of a GitHub REST path. GitHub names only - * use `[A-Za-z0-9-_.]`, so every real name passes through unchanged; a value - * carrying `/`, `?`, `#`, or a dot segment, which would steer the - * authenticated request to a different endpoint, is rejected or escaped. - * - * @throws When either value is empty, a dot segment, or contains a separator. - */ -export function githubRepoPath(owner: string, repo: string): string { - return `${safeUrlPathSegment(owner, 'owner')}/${safeUrlPathSegment(repo, 'repo')}` -} - -/** - * Encodes an identifier that fills exactly one GitHub REST path segment: a - * number (issue, pull, run, milestone, release, comment, reaction), a gist id, - * a username, or a workflow id or file name. - * - * @throws When the value is empty, a dot segment, or contains a separator. - */ -export function githubPathSegment(value: string | number, paramName: string): string { - return restoreRawSafeCharacters(safeUrlPathSegment(value, paramName)) -} - -/** - * Encodes a git ref (a branch name, `heads/`, a tag, or a SHA) for a - * path position that GitHub matches greedily, so its `/` separators are kept. - * Each segment is escaped so a `?` or `#` cannot end the path, and a `.` or - * `..` segment, which the URL parser would resolve away, is rejected. Git - * forbids both in ref names, so no real ref changes. - * - * A numeric ref (an all-digit short SHA or branch sent as a JSON number) is - * stringified like any other numeric segment. - * - * @throws When the ref is empty or contains a dot segment. - */ -export function githubRefPath(ref: string | number, paramName: string): string { - if (typeof ref !== 'string') { - return safeUrlPathSegment(ref, paramName) - } - if (ref.trim() === '') { - throw new Error(`${paramName} is required`) - } - return ref - .trim() - .split('/') - .map((segment) => { - if (segment === '.' || segment === '..') { - throw new Error(`${paramName} cannot contain "." or ".." path segments`) - } - try { - return restoreRawSafeCharacters(encodeURIComponent(segment)) - } catch { - throw new Error(`${paramName} contains an unpaired UTF-16 surrogate and cannot be encoded`) - } - }) - .join('/') -} diff --git a/apps/sim/tools/github/request-paths.test.ts b/apps/sim/tools/github/request-paths.test.ts deleted file mode 100644 index 8e9352a837b..00000000000 --- a/apps/sim/tools/github/request-paths.test.ts +++ /dev/null @@ -1,147 +0,0 @@ -import { describe, expect, it } from 'vitest' -import { executeGitHubTool } from '@/lib/internal/github/execute-tool' -import { getGitHubLatestCommit } from '@/lib/internal/github/operations' -import { compareCommitsTool } from '@/tools/github/compare_commits' -import { deleteBranchTool } from '@/tools/github/delete_branch' -import { getBranchTool } from '@/tools/github/get_branch' -import { getGistTool } from '@/tools/github/get_gist' -import { getIssueTool } from '@/tools/github/get_issue' -import { getWorkflowTool } from '@/tools/github/get_workflow' -import { listGistsTool } from '@/tools/github/list_gists' -import { repoInfoTool } from '@/tools/github/repo_info' -import { starRepoTool } from '@/tools/github/star_repo' -import type { ToolConfig } from '@/tools/types' - -function url(tool: ToolConfig, params: Record): string { - const { url: builder } = tool.request - return typeof builder === 'function' ? builder({ apiKey: 'ghp_test', ...params }) : builder -} - -describe('GitHub request paths', () => { - it.each([ - ['octocat', 'Hello-World'], - ['my-org', 'repo.name_2'], - ['a1', '.github'], - ['user-123', 'x..y'], - ])('leaves real owner %s and repo %s byte identical', (owner, repo) => { - expect(url(repoInfoTool, { owner, repo })).toBe(`https://api.github.com/repos/${owner}/${repo}`) - expect(url(starRepoTool, { owner, repo })).toBe( - `https://api.github.com/user/starred/${owner}/${repo}` - ) - }) - - it.each([ - [{ owner: '..', repo: 'demo' }, /owner cannot be "\.\."/], - [{ owner: 'octo', repo: '.' }, /repo cannot be "\."/], - [{ owner: 'orgs/acme', repo: 'demo' }, /owner cannot contain a path separator/], - [{ owner: 'octo', repo: 'demo\\..' }, /repo cannot contain a path separator/], - ])('rejects an owner or repo that would leave the repository path', (params, error) => { - expect(() => url(repoInfoTool, params)).toThrow(error) - expect(() => url(starRepoTool, params)).toThrow(error) - }) - - it('escapes a query or fragment delimiter instead of letting it end the path', () => { - expect(url(repoInfoTool, { owner: 'octo', repo: 'x?y' })).toBe( - 'https://api.github.com/repos/octo/x%3Fy' - ) - expect(url(repoInfoTool, { owner: 'octo#z', repo: 'demo' })).toBe( - 'https://api.github.com/repos/octo%23z/demo' - ) - }) - - it('rejects a numeric id that smuggles extra segments', () => { - const params = { owner: 'octo', repo: 'demo' } - - expect(url(getIssueTool, { ...params, issue_number: 42 })).toBe( - 'https://api.github.com/repos/octo/demo/issues/42' - ) - expect(() => url(getIssueTool, { ...params, issue_number: '1/../../../user' })).toThrow( - /issue_number cannot contain a path separator/ - ) - }) - - it('keeps workflow file names and gist ids as one segment', () => { - const params = { owner: 'octo', repo: 'demo' } - - expect(url(getWorkflowTool, { ...params, workflow_id: 'deploy@v2+prod.yml' })).toBe( - 'https://api.github.com/repos/octo/demo/actions/workflows/deploy@v2+prod.yml' - ) - expect(() => url(getWorkflowTool, { ...params, workflow_id: '../../hooks' })).toThrow( - /workflow_id cannot contain a path separator/ - ) - expect(url(getGistTool, { gist_id: ' aa5a315d61ae9438b18d ' })).toBe( - 'https://api.github.com/gists/aa5a315d61ae9438b18d' - ) - expect(() => url(getGistTool, { gist_id: '..' })).toThrow(/gist_id cannot be "\.\."/) - expect(() => url(listGistsTool, { username: 'octo/repos' })).toThrow( - /username cannot contain a path separator/ - ) - }) - - it('keeps the slashes and raw-safe characters of a branch byte identical', () => { - const params = { owner: 'octo', repo: 'demo' } - - expect(url(getBranchTool, { ...params, branch: 'feature/login+v2@team' })).toBe( - 'https://api.github.com/repos/octo/demo/branches/feature/login+v2@team' - ) - expect(url(deleteBranchTool, { ...params, branch: 'users/jane/fix' })).toBe( - 'https://api.github.com/repos/octo/demo/git/refs/heads/users/jane/fix' - ) - expect(url(compareCommitsTool, { ...params, base: 'main', head: 'release/1.2' })).toBe( - 'https://api.github.com/repos/octo/demo/compare/main...release/1.2' - ) - }) - - it('accepts a numeric ref or branch sent as a JSON number', () => { - const params = { owner: 'octo', repo: 'demo' } - - expect(url(getBranchTool, { ...params, branch: 2024 })).toBe( - 'https://api.github.com/repos/octo/demo/branches/2024' - ) - expect(url(compareCommitsTool, { ...params, base: 1234567, head: 'main' })).toBe( - 'https://api.github.com/repos/octo/demo/compare/1234567...main' - ) - }) - - it('escapes delimiters in a branch and rejects its dot segments', () => { - const params = { owner: 'octo', repo: 'demo' } - - expect(url(getBranchTool, { ...params, branch: 'a?b#c' })).toBe( - 'https://api.github.com/repos/octo/demo/branches/a%3Fb%23c' - ) - expect(() => url(deleteBranchTool, { ...params, branch: 'x/../../../../hooks' })).toThrow( - /branch cannot contain "\." or "\.\." path segments/ - ) - expect(() => url(compareCommitsTool, { ...params, base: 'main', head: '..' })).toThrow( - /head cannot contain "\." or "\.\." path segments/ - ) - }) - - it('rejects a traversal owner in the latest-commit operation as a 400 before any request', async () => { - await expect( - getGitHubLatestCommit( - { owner: '..', repo: 'demo', apiKey: 'ghp_test' }, - { requestId: 'test-request' } - ) - ).rejects.toMatchObject({ - status: 400, - message: 'owner cannot be ".." (path traversal is not allowed)', - }) - }) - - it('answers a traversal owner in the PR comment operation with a 400', async () => { - const response = await executeGitHubTool({ - toolId: 'github_comment', - input: { owner: 'octo', repo: '..', body: 'hi', pullNumber: 1, apiKey: 'ghp_test' }, - headers: new Headers(), - context: { workflowId: 'workflow-1' }, - requestId: 'test-request', - }) - - expect(response.status).toBe(400) - expect(await response.json()).toEqual({ - success: false, - error: 'repo cannot be ".." (path traversal is not allowed)', - }) - }) -}) diff --git a/apps/sim/tools/github/request_reviewers.ts b/apps/sim/tools/github/request_reviewers.ts index cebbbc7cd59..4e71791393b 100644 --- a/apps/sim/tools/github/request_reviewers.ts +++ b/apps/sim/tools/github/request_reviewers.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { RequestReviewersParams, ReviewersResponse } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -52,7 +51,7 @@ export const requestReviewersTool: ToolConfig - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/pulls/${githubPathSegment(params.pullNumber, 'pullNumber')}/requested_reviewers`, + `https://api.github.com/repos/${params.owner}/${params.repo}/pulls/${params.pullNumber}/requested_reviewers`, method: 'POST', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/rerun_workflow.ts b/apps/sim/tools/github/rerun_workflow.ts index 6a1c9bf27c2..5de1dc38e8d 100644 --- a/apps/sim/tools/github/rerun_workflow.ts +++ b/apps/sim/tools/github/rerun_workflow.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { RerunWorkflowParams, RerunWorkflowResponse } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -47,7 +46,7 @@ export const rerunWorkflowTool: ToolConfig - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/actions/runs/${githubPathSegment(params.run_id, 'run_id')}/rerun`, + `https://api.github.com/repos/${params.owner}/${params.repo}/actions/runs/${params.run_id}/rerun`, method: 'POST', headers: (params) => ({ Accept: 'application/vnd.github+json', diff --git a/apps/sim/tools/github/star_gist.ts b/apps/sim/tools/github/star_gist.ts index 5bef447a944..cb0ccf1a4c2 100644 --- a/apps/sim/tools/github/star_gist.ts +++ b/apps/sim/tools/github/star_gist.ts @@ -1,4 +1,3 @@ -import { githubPathSegment } from '@/tools/github/request-path' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -41,8 +40,7 @@ export const starGistTool: ToolConfig = { }, request: { - url: (params) => - `https://api.github.com/gists/${githubPathSegment(params.gist_id, 'gist_id')}/star`, + url: (params) => `https://api.github.com/gists/${params.gist_id?.trim()}/star`, method: 'PUT', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/star_repo.ts b/apps/sim/tools/github/star_repo.ts index 2eb914ad48d..0455c49b198 100644 --- a/apps/sim/tools/github/star_repo.ts +++ b/apps/sim/tools/github/star_repo.ts @@ -1,4 +1,3 @@ -import { githubRepoPath } from '@/tools/github/request-path' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -49,8 +48,7 @@ export const starRepoTool: ToolConfig = { }, request: { - url: (params) => - `https://api.github.com/user/starred/${githubRepoPath(params.owner, params.repo)}`, + url: (params) => `https://api.github.com/user/starred/${params.owner}/${params.repo}`, method: 'PUT', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/trigger_workflow.ts b/apps/sim/tools/github/trigger_workflow.ts index d10e1d60a1b..a40392104aa 100644 --- a/apps/sim/tools/github/trigger_workflow.ts +++ b/apps/sim/tools/github/trigger_workflow.ts @@ -1,5 +1,4 @@ import { isRecordLike } from '@sim/utils/object' -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { TriggerWorkflowParams, TriggerWorkflowResponse } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -76,7 +75,7 @@ export const triggerWorkflowTool: ToolConfig - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/actions/workflows/${githubPathSegment(params.workflow_id, 'workflow_id')}/dispatches`, + `https://api.github.com/repos/${params.owner}/${params.repo}/actions/workflows/${params.workflow_id}/dispatches`, method: 'POST', headers: (params) => ({ Accept: 'application/vnd.github+json', diff --git a/apps/sim/tools/github/unstar_gist.ts b/apps/sim/tools/github/unstar_gist.ts index 7c2f682bdae..d2b5116bb4e 100644 --- a/apps/sim/tools/github/unstar_gist.ts +++ b/apps/sim/tools/github/unstar_gist.ts @@ -1,4 +1,3 @@ -import { githubPathSegment } from '@/tools/github/request-path' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -41,8 +40,7 @@ export const unstarGistTool: ToolConfig = }, request: { - url: (params) => - `https://api.github.com/gists/${githubPathSegment(params.gist_id, 'gist_id')}/star`, + url: (params) => `https://api.github.com/gists/${params.gist_id?.trim()}/star`, method: 'DELETE', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/unstar_repo.ts b/apps/sim/tools/github/unstar_repo.ts index 896cb7282a2..ff3d772d307 100644 --- a/apps/sim/tools/github/unstar_repo.ts +++ b/apps/sim/tools/github/unstar_repo.ts @@ -1,4 +1,3 @@ -import { githubRepoPath } from '@/tools/github/request-path' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -49,8 +48,7 @@ export const unstarRepoTool: ToolConfig = }, request: { - url: (params) => - `https://api.github.com/user/starred/${githubRepoPath(params.owner, params.repo)}`, + url: (params) => `https://api.github.com/user/starred/${params.owner}/${params.repo}`, method: 'DELETE', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/update_branch_protection.ts b/apps/sim/tools/github/update_branch_protection.ts index 394c294271a..aa75d1036c7 100644 --- a/apps/sim/tools/github/update_branch_protection.ts +++ b/apps/sim/tools/github/update_branch_protection.ts @@ -1,4 +1,3 @@ -import { githubRefPath, githubRepoPath } from '@/tools/github/request-path' import type { BranchProtectionResponse, UpdateBranchProtectionParams } from '@/tools/github/types' import { BRANCH_PROTECTION_OUTPUT_PROPERTIES } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' @@ -136,7 +135,7 @@ export const updateBranchProtectionTool: ToolConfig< request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/branches/${githubRefPath(params.branch, 'branch')}/protection`, + `https://api.github.com/repos/${params.owner}/${params.repo}/branches/${params.branch}/protection`, method: 'PUT', headers: (params) => ({ Accept: 'application/vnd.github+json', diff --git a/apps/sim/tools/github/update_comment.ts b/apps/sim/tools/github/update_comment.ts index e1cdc51c7b4..b3c6e6644dc 100644 --- a/apps/sim/tools/github/update_comment.ts +++ b/apps/sim/tools/github/update_comment.ts @@ -1,5 +1,4 @@ import { truncate } from '@sim/utils/string' -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { IssueCommentResponse, UpdateCommentParams } from '@/tools/github/types' import { COMMENT_OUTPUT_PROPERTIES, USER_OUTPUT } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' @@ -47,7 +46,7 @@ export const updateCommentTool: ToolConfig - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/issues/comments/${githubPathSegment(params.comment_id, 'comment_id')}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/issues/comments/${params.comment_id}`, method: 'PATCH', headers: (params) => ({ Accept: 'application/vnd.github+json', diff --git a/apps/sim/tools/github/update_file.ts b/apps/sim/tools/github/update_file.ts index d393cd64eab..e26785a1e0a 100644 --- a/apps/sim/tools/github/update_file.ts +++ b/apps/sim/tools/github/update_file.ts @@ -1,5 +1,4 @@ import { encodeContentPath } from '@/tools/github/content-path' -import { githubRepoPath } from '@/tools/github/request-path' import type { FileOperationResponse, UpdateFileParams } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -65,7 +64,7 @@ export const updateFileTool: ToolConfig request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/contents/${encodeContentPath(params.path)}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/contents/${encodeContentPath(params.path)}`, method: 'PUT', headers: (params) => ({ Accept: 'application/vnd.github+json', diff --git a/apps/sim/tools/github/update_gist.ts b/apps/sim/tools/github/update_gist.ts index fb249be4b30..10cbd2f9aac 100644 --- a/apps/sim/tools/github/update_gist.ts +++ b/apps/sim/tools/github/update_gist.ts @@ -1,4 +1,3 @@ -import { githubPathSegment } from '@/tools/github/request-path' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -64,7 +63,7 @@ export const updateGistTool: ToolConfig = }, request: { - url: (params) => `https://api.github.com/gists/${githubPathSegment(params.gist_id, 'gist_id')}`, + url: (params) => `https://api.github.com/gists/${params.gist_id?.trim()}`, method: 'PATCH', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/update_issue.ts b/apps/sim/tools/github/update_issue.ts index 10d9865806d..b3d3571194e 100644 --- a/apps/sim/tools/github/update_issue.ts +++ b/apps/sim/tools/github/update_issue.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { IssueResponse, UpdateIssueParams } from '@/tools/github/types' import { ISSUE_OUTPUT_PROPERTIES, @@ -75,7 +74,7 @@ export const updateIssueTool: ToolConfig = { request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/issues/${githubPathSegment(params.issue_number, 'issue_number')}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/issues/${params.issue_number}`, method: 'PATCH', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/update_milestone.ts b/apps/sim/tools/github/update_milestone.ts index 7da7b772dfc..9a5ffe3823c 100644 --- a/apps/sim/tools/github/update_milestone.ts +++ b/apps/sim/tools/github/update_milestone.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -91,7 +90,7 @@ export const updateMilestoneTool: ToolConfig - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/milestones/${githubPathSegment(params.milestone_number, 'milestone_number')}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/milestones/${params.milestone_number}`, method: 'PATCH', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/update_pr.ts b/apps/sim/tools/github/update_pr.ts index adc7adb0afc..38e12e346b0 100644 --- a/apps/sim/tools/github/update_pr.ts +++ b/apps/sim/tools/github/update_pr.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { PRResponse, UpdatePRParams } from '@/tools/github/types' import { GITHUB_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials' import type { ToolConfig } from '@/tools/types' @@ -63,7 +62,7 @@ export const updatePRTool: ToolConfig = { request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/pulls/${githubPathSegment(params.pullNumber, 'pullNumber')}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/pulls/${params.pullNumber}`, method: 'PATCH', headers: (params) => ({ Accept: 'application/vnd.github.v3+json', diff --git a/apps/sim/tools/github/update_release.ts b/apps/sim/tools/github/update_release.ts index 8d8d2d016de..798b5b138d3 100644 --- a/apps/sim/tools/github/update_release.ts +++ b/apps/sim/tools/github/update_release.ts @@ -1,4 +1,3 @@ -import { githubPathSegment, githubRepoPath } from '@/tools/github/request-path' import type { ReleaseResponse, UpdateReleaseParams } from '@/tools/github/types' import { RELEASE_ASSET_OUTPUT_PROPERTIES, @@ -81,7 +80,7 @@ export const updateReleaseTool: ToolConfig request: { url: (params) => - `https://api.github.com/repos/${githubRepoPath(params.owner, params.repo)}/releases/${githubPathSegment(params.release_id, 'release_id')}`, + `https://api.github.com/repos/${params.owner}/${params.repo}/releases/${params.release_id}`, method: 'PATCH', headers: (params) => ({ Accept: 'application/vnd.github+json',