From 99368da9f50df028ad644b0fb7852bbd7b6cb1cd Mon Sep 17 00:00:00 2001 From: Steve White Date: Wed, 29 Jan 2025 16:19:17 +0000 Subject: [PATCH] Add patch file for update_file functionality --- add-update-file.patch | 109 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 add-update-file.patch diff --git a/add-update-file.patch b/add-update-file.patch new file mode 100644 index 0000000..c3b3585 --- /dev/null +++ b/add-update-file.patch @@ -0,0 +1,109 @@ +diff --git a/src/index.ts b/src/index.ts +index 671f7f1..e892a7c 100644 +--- a/src/index.ts ++++ b/src/index.ts +@@ -25,6 +25,14 @@ interface CreateFileArgs extends RepoArgs { + branch?: string; + } + ++interface UpdateFileArgs extends RepoArgs { ++ path: string; ++ content: string; ++ message: string; ++ branch?: string; ++ sha: string; ++} ++ + interface GetContentsArgs extends RepoArgs { + path: string; + ref?: string; +@@ -213,6 +221,32 @@ class GiteaServer { + }, + }, + { ++ 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', + inputSchema: { +@@ -431,6 +465,42 @@ class GiteaServer { + }; + } + ++ 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; +