Skip to content

Commit 3a752b1

Browse files
feat(api): add branch reset functionality
1 parent 13aabb5 commit 3a752b1

File tree

10 files changed

+115
-4
lines changed

10 files changed

+115
-4
lines changed

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 20
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/stainless%2Fstainless-v0-030e47a1bfd79a657974f5beddd685940ec04b1aa1786c3b2cb0f4610ad2b42c.yml
3-
openapi_spec_hash: 33b337af28bcc1c9aa1a5218acf2a7fe
4-
config_hash: 6b235571b537b4814a33a1008b443e36
1+
configured_endpoints: 21
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/stainless%2Fstainless-v0-ec93b81b2d599edd19449bae3cb40bdb17890908d97cc867e36425a45e491c16.yml
3+
openapi_spec_hash: fe8b8fd7782670698fecfe2fcc05f693
4+
config_hash: 626376bcac885a796930ef32094b8387

api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Methods:
3434
- <code title="get /v0/projects/{project}/branches">client.projects.branches.<a href="./src/resources/projects/branches.ts">list</a>({ ...params }) -> BranchListResponsesPage</code>
3535
- <code title="delete /v0/projects/{project}/branches/{branch}">client.projects.branches.<a href="./src/resources/projects/branches.ts">delete</a>(branch, { ...params }) -> unknown</code>
3636
- <code title="put /v0/projects/{project}/branches/{branch}/rebase">client.projects.branches.<a href="./src/resources/projects/branches.ts">rebase</a>(branch, { ...params }) -> ProjectBranch</code>
37+
- <code title="put /v0/projects/{project}/branches/{branch}/reset">client.projects.branches.<a href="./src/resources/projects/branches.ts">reset</a>(branch, { ...params }) -> ProjectBranch</code>
3738

3839
## Configs
3940

packages/mcp-server/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@ The following tools are available in this MCP server.
278278
The branch is rebased onto the `base` branch or commit SHA, inheriting
279279
any config and custom code changes.
280280

281+
- `reset_projects_branches` (`write`): Reset a project branch.
282+
283+
If `branch` === `main`, the branch is reset to `target_config_sha`. Otherwise, the
284+
branch is reset to `main`.
285+
281286
### Resource `projects.configs`:
282287

283288
- `retrieve_projects_configs` (`read`):

packages/mcp-server/src/code-tool-worker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const fuse = new Fuse(
5050
'client.projects.branches.delete',
5151
'client.projects.branches.list',
5252
'client.projects.branches.rebase',
53+
'client.projects.branches.reset',
5354
'client.projects.branches.retrieve',
5455
'client.projects.configs.guess',
5556
'client.projects.configs.retrieve',

packages/mcp-server/src/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import retrieve_projects_branches from './projects/branches/retrieve-projects-br
1313
import list_projects_branches from './projects/branches/list-projects-branches';
1414
import delete_projects_branches from './projects/branches/delete-projects-branches';
1515
import rebase_projects_branches from './projects/branches/rebase-projects-branches';
16+
import reset_projects_branches from './projects/branches/reset-projects-branches';
1617
import retrieve_projects_configs from './projects/configs/retrieve-projects-configs';
1718
import guess_projects_configs from './projects/configs/guess-projects-configs';
1819
import create_builds from './builds/create-builds';
@@ -39,6 +40,7 @@ addEndpoint(retrieve_projects_branches);
3940
addEndpoint(list_projects_branches);
4041
addEndpoint(delete_projects_branches);
4142
addEndpoint(rebase_projects_branches);
43+
addEndpoint(reset_projects_branches);
4244
addEndpoint(retrieve_projects_configs);
4345
addEndpoint(guess_projects_configs);
4446
addEndpoint(create_builds);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import { Metadata, asTextContentResult } from '@stainless-api/sdk-mcp/tools/types';
4+
5+
import { Tool } from '@modelcontextprotocol/sdk/types.js';
6+
import Stainless from '@stainless-api/sdk';
7+
8+
export const metadata: Metadata = {
9+
resource: 'projects.branches',
10+
operation: 'write',
11+
tags: [],
12+
httpMethod: 'put',
13+
httpPath: '/v0/projects/{project}/branches/{branch}/reset',
14+
};
15+
16+
export const tool: Tool = {
17+
name: 'reset_projects_branches',
18+
description:
19+
'Reset a project branch.\n\nIf `branch` === `main`, the branch is reset to `target_config_sha`. Otherwise, the\nbranch is reset to `main`.',
20+
inputSchema: {
21+
type: 'object',
22+
properties: {
23+
project: {
24+
type: 'string',
25+
},
26+
branch: {
27+
type: 'string',
28+
},
29+
target_config_sha: {
30+
type: 'string',
31+
description:
32+
'The commit SHA to reset the main branch to. Required if resetting the main branch; disallowed otherwise.',
33+
},
34+
},
35+
required: ['project', 'branch'],
36+
},
37+
annotations: {
38+
idempotentHint: true,
39+
},
40+
};
41+
42+
export const handler = async (client: Stainless, args: Record<string, unknown> | undefined) => {
43+
const { branch, ...body } = args as any;
44+
return asTextContentResult(await client.projects.branches.reset(branch, body));
45+
};
46+
47+
export default { metadata, tool, handler };

src/resources/projects/branches.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,24 @@ export class Branches extends APIResource {
7575
...options,
7676
});
7777
}
78+
79+
/**
80+
* Reset a project branch.
81+
*
82+
* If `branch` === `main`, the branch is reset to `target_config_sha`. Otherwise,
83+
* the branch is reset to `main`.
84+
*/
85+
reset(
86+
branch: string,
87+
params: BranchResetParams | null | undefined = {},
88+
options?: RequestOptions,
89+
): APIPromise<ProjectBranch> {
90+
const { project = this._client.project, target_config_sha } = params ?? {};
91+
return this._client.put(path`/v0/projects/${project}/branches/${branch}/reset`, {
92+
query: { target_config_sha },
93+
...options,
94+
});
95+
}
7896
}
7997

8098
export type BranchListResponsesPage = Page<BranchListResponse>;
@@ -236,6 +254,19 @@ export interface BranchRebaseParams {
236254
base?: string;
237255
}
238256

257+
export interface BranchResetParams {
258+
/**
259+
* Path param:
260+
*/
261+
project?: string;
262+
263+
/**
264+
* Query param: The commit SHA to reset the main branch to. Required if resetting
265+
* the main branch; disallowed otherwise.
266+
*/
267+
target_config_sha?: string;
268+
}
269+
239270
export declare namespace Branches {
240271
export {
241272
type ProjectBranch as ProjectBranch,
@@ -247,5 +278,6 @@ export declare namespace Branches {
247278
type BranchListParams as BranchListParams,
248279
type BranchDeleteParams as BranchDeleteParams,
249280
type BranchRebaseParams as BranchRebaseParams,
281+
type BranchResetParams as BranchResetParams,
250282
};
251283
}

src/resources/projects/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export {
1010
type BranchListParams,
1111
type BranchDeleteParams,
1212
type BranchRebaseParams,
13+
type BranchResetParams,
1314
type BranchListResponsesPage,
1415
} from './branches';
1516
export {

src/resources/projects/projects.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
BranchListResponse,
1212
BranchListResponsesPage,
1313
BranchRebaseParams,
14+
BranchResetParams,
1415
BranchRetrieveParams,
1516
Branches,
1617
ProjectBranch,
@@ -164,6 +165,7 @@ export declare namespace Projects {
164165
type BranchListParams as BranchListParams,
165166
type BranchDeleteParams as BranchDeleteParams,
166167
type BranchRebaseParams as BranchRebaseParams,
168+
type BranchResetParams as BranchResetParams,
167169
};
168170

169171
export {

tests/api-resources/projects/branches.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,24 @@ describe('resource branches', () => {
101101
test.skip('rebase: required and optional params', async () => {
102102
const response = await client.projects.branches.rebase('branch', { project: 'project', base: 'base' });
103103
});
104+
105+
// Prism tests are disabled
106+
test.skip('reset: only required params', async () => {
107+
const responsePromise = client.projects.branches.reset('branch', { project: 'project' });
108+
const rawResponse = await responsePromise.asResponse();
109+
expect(rawResponse).toBeInstanceOf(Response);
110+
const response = await responsePromise;
111+
expect(response).not.toBeInstanceOf(Response);
112+
const dataAndResponse = await responsePromise.withResponse();
113+
expect(dataAndResponse.data).toBe(response);
114+
expect(dataAndResponse.response).toBe(rawResponse);
115+
});
116+
117+
// Prism tests are disabled
118+
test.skip('reset: required and optional params', async () => {
119+
const response = await client.projects.branches.reset('branch', {
120+
project: 'project',
121+
target_config_sha: 'target_config_sha',
122+
});
123+
});
104124
});

0 commit comments

Comments
 (0)