Skip to content

Commit 3b19c4f

Browse files
Copilotjoshspicer
andcommitted
Add optional head_ref property to RemoteAgentJobPayload for async branching
Co-authored-by: joshspicer <23246594+joshspicer@users.noreply.github.com>
1 parent a22902a commit 3b19c4f

3 files changed

Lines changed: 82 additions & 1 deletion

File tree

src/github/copilotApi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface RemoteAgentJobPayload {
1919
body_placeholder?: string;
2020
body_suffix?: string;
2121
base_ref?: string;
22+
head_ref?: string;
2223
};
2324
run_name?: string;
2425
}

src/github/copilotRemoteAgent.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ export class CopilotRemoteAgentManager extends Disposable {
255255
pull_request: {
256256
title,
257257
body_placeholder: problemContext,
258-
base_ref: ref,
258+
base_ref: hasChanges && autoPushAndCommit ? baseRef : ref,
259+
...(hasChanges && autoPushAndCommit && { head_ref: ref })
259260
}
260261
};
261262
const { pull_request } = await capiClient.postRemoteAgentJob(owner, repo, payload);

src/test/github/copilotApi.test.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { default as assert } from 'assert';
2+
import { RemoteAgentJobPayload } from '../../github/copilotApi';
3+
4+
describe('CopilotApi Tests', function () {
5+
describe('RemoteAgentJobPayload', () => {
6+
it('should have optional head_ref property', () => {
7+
// Test payload without head_ref (when not pushing)
8+
const payloadWithoutHeadRef: RemoteAgentJobPayload = {
9+
problem_statement: 'Test problem',
10+
pull_request: {
11+
title: 'Test title',
12+
body_placeholder: 'Test body',
13+
base_ref: 'main'
14+
}
15+
};
16+
17+
assert.strictEqual(payloadWithoutHeadRef.pull_request?.head_ref, undefined);
18+
assert.strictEqual(payloadWithoutHeadRef.pull_request?.base_ref, 'main');
19+
});
20+
21+
it('should include head_ref when pushing async branch', () => {
22+
// Test payload with head_ref (when pushing to async branch)
23+
const payloadWithHeadRef: RemoteAgentJobPayload = {
24+
problem_statement: 'Test problem',
25+
pull_request: {
26+
title: 'Test title',
27+
body_placeholder: 'Test body',
28+
base_ref: 'main',
29+
head_ref: 'continue-from-1234567890'
30+
}
31+
};
32+
33+
assert.strictEqual(payloadWithHeadRef.pull_request?.head_ref, 'continue-from-1234567890');
34+
assert.strictEqual(payloadWithHeadRef.pull_request?.base_ref, 'main');
35+
});
36+
37+
it('should support conditional head_ref property using spread operator', () => {
38+
const hasChanges = true;
39+
const autoPushAndCommit = true;
40+
const baseRef = 'main';
41+
const ref = 'continue-from-1234567890';
42+
43+
// Simulate the logic from copilotRemoteAgent.ts
44+
const payload: RemoteAgentJobPayload = {
45+
problem_statement: 'Test problem',
46+
pull_request: {
47+
title: 'Test title',
48+
body_placeholder: 'Test body',
49+
base_ref: hasChanges && autoPushAndCommit ? baseRef : ref,
50+
...(hasChanges && autoPushAndCommit && { head_ref: ref })
51+
}
52+
};
53+
54+
assert.strictEqual(payload.pull_request?.base_ref, 'main');
55+
assert.strictEqual(payload.pull_request?.head_ref, 'continue-from-1234567890');
56+
});
57+
58+
it('should not include head_ref when not pushing', () => {
59+
const hasChanges = false;
60+
const autoPushAndCommit = true;
61+
const baseRef = 'main';
62+
const ref = 'main';
63+
64+
// Simulate the logic from copilotRemoteAgent.ts
65+
const payload: RemoteAgentJobPayload = {
66+
problem_statement: 'Test problem',
67+
pull_request: {
68+
title: 'Test title',
69+
body_placeholder: 'Test body',
70+
base_ref: hasChanges && autoPushAndCommit ? baseRef : ref,
71+
...(hasChanges && autoPushAndCommit && { head_ref: ref })
72+
}
73+
};
74+
75+
assert.strictEqual(payload.pull_request?.base_ref, 'main');
76+
assert.strictEqual(payload.pull_request?.head_ref, undefined);
77+
});
78+
});
79+
});

0 commit comments

Comments
 (0)