110 lines
3.3 KiB
Diff
110 lines
3.3 KiB
Diff
|
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;
|
||
|
@@ -214,6 +222,41 @@ class GiteaServer {
|
||
|
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',
|
||
|
inputSchema: {
|
||
|
@@ -432,6 +475,41 @@ 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;
|