From 9105227d558f86c1791826ce54d2353023200eee Mon Sep 17 00:00:00 2001 From: Steve White Date: Wed, 29 Jan 2025 16:53:49 +0000 Subject: [PATCH] Add clean patch for update_file feature --- update_file.patch | 107 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 update_file.patch diff --git a/update_file.patch b/update_file.patch new file mode 100644 index 0000000..02f721a --- /dev/null +++ b/update_file.patch @@ -0,0 +1,107 @@ +diff --git a/src/index.ts b/src/index.ts +--- a/src/index.ts 2024-01-29 17:00:00.000000000 +0000 ++++ b/src/index.ts 2024-01-29 17:00:00.000000000 +0000 +@@ -25,6 +25,14 @@ + branch?: string; + } + ++interface UpdateFileArgs extends RepoArgs { ++ path: string; ++ content: string; ++ message: string; ++ branch?: string; ++ sha: string; ++} ++ + interface GetContentsArgs extends RepoArgs { + path: string; + ref?: string; +@@ -214,6 +222,41 @@ + required: ['owner', 'repo', 'path', 'message'], + }, + }, ++ { ++ name: 'update_file', ++ description: 'Update an existing file in a repository', ++ inputSchema: { ++ type: 'object', ++ properties: { ++ owner: { ++ type: 'string', ++ description: 'Repository owner', ++ }, ++ repo: { ++ type: 'string', ++ description: 'Repository name', ++ }, ++ path: { ++ type: 'string', ++ description: 'Path to file', ++ }, ++ content: { ++ type: 'string', ++ description: 'New file content (will be base64 encoded)', ++ }, ++ message: { ++ type: 'string', ++ description: 'Commit message', ++ }, ++ branch: { ++ type: 'string', ++ description: 'Branch name', ++ }, ++ sha: { ++ type: 'string', ++ description: 'SHA of the file being replaced', ++ }, ++ }, ++ required: ['owner', 'repo', 'path', 'content', 'message', 'sha'], ++ }, ++ }, + { + name: 'create_branch', + description: 'Create a new branch in a repository', +@@ -432,6 +475,41 @@ + }; + } + ++ case 'update_file': { ++ const args = request.params.arguments as unknown as UpdateFileArgs; ++ const response = await this.api.put( ++ `/repos/${args.owner}/${args.repo}/contents/${args.path}`, ++ { ++ content: Buffer.from(args.content).toString('base64'), ++ message: args.message, ++ sha: args.sha, ++ branch: args.branch, ++ } ++ ); ++ ++ // Verify the file after update ++ const verifyResponse = await this.api.get( ++ `/repos/${args.owner}/${args.repo}/contents/${args.path}`, ++ { ++ params: { ref: args.branch }, ++ } ++ ); ++ ++ return { ++ content: [ ++ { ++ type: 'text', ++ text: JSON.stringify({ ++ success: true, ++ message: 'File updated successfully', ++ file: { ++ path: args.path, ++ commit: response.data.commit, ++ }, ++ content: verifyResponse.data, ++ }, null, 2), ++ }, ++ ], ++ }; ++ } ++ + case 'create_branch': { + const { owner, repo, branch, from } = request.params.arguments as unknown as CreateBranchArgs; \ No newline at end of file