Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/update/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,23 @@
folder: CodeFolder,
data: WebhookEventData<WebhookEventType.TaskCreated>,
) => {
const description = data.task.items
const descriptions = data.task.items
.filter(({ type }) => type === 'message')
.map(({ data }) => `<description>${(data as any).content}</description>`)
.join('\n');
.map(({ data }) => `<description>${(data as any).content}</description>`);

Check warning on line 12 in src/update/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 12 in src/update/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

const message = `<title>${data.task.title}</title>${description}`;
const originData =
data.task.items.find(({ type }) => type === 'origin')?.data ?? {};

const comments = ((originData as any).issueComments ?? []).map(

Check warning on line 17 in src/update/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 17 in src/update/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
({ body, userName }: { body: string; userName: string }) =>
`<comment author="${userName}">${body}</comment>`,
);

const message = [
`<title>${data.task.title}</title>`,
...descriptions,
...comments,
].join('\n');

const run = query({
prompt: message,
Expand Down
88 changes: 87 additions & 1 deletion test/events/processTask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,33 @@
},
} as WebhookEventData<WebhookEventType.TaskCreated>;

const dataWithOriginComments = {
...data,
task: {
...data.task,
items: [
{
id: 1,
type: 'origin',
data: {
issueComments: [
{
body: 'This is a comment',
userName: 'user1',
},
{
body: 'This is another comment',
userName: 'user2',
},
],
},
bot_id: null,
repo_id: null,
},
],
},
} as WebhookEventData<WebhookEventType.TaskCreated>;

const codeFixture = join(__dirname, '..', 'fixtures', 'code');

const anthropicRequestData = {
Expand Down Expand Up @@ -218,7 +245,7 @@
assert.deepEqual(queryStub.firstCall.args, [
{
prompt:
'<title>Fix a minor bug</title><description>It does not work</description>',
'<title>Fix a minor bug</title>\n<description>It does not work</description>',
options: {
cwd: codeFixture,
permissionMode: 'bypassPermissions',
Expand Down Expand Up @@ -254,8 +281,67 @@
});
});

suite('with task origin comments', () => {
setup(async () => {
await processTask.handler?.(app, {
baseURL: 'https://api.automa.app',
data: dataWithOriginComments,
});
});

test('should download code', async () => {
assert.equal(downloadStub.callCount, 1);
assert.deepEqual(downloadStub.firstCall.args, [
dataWithOriginComments,
{
baseURL: 'https://api.automa.app',
},
]);
});

test('should run claude code', async () => {
assert.equal(queryStub.callCount, 1);
assert.deepEqual(queryStub.firstCall.args, [
{
prompt:
'<title>Fix a minor bug</title>\n<comment author="user1">This is a comment</comment>\n<comment author="user2">This is another comment</comment>',
options: {
cwd: codeFixture,
permissionMode: 'bypassPermissions',
},
},
]);
});

test('should generate PR fields', async () => {
assert.equal(parseStub.callCount, 1);
assert.deepEqual(parseStub.firstCall.args, [anthropicRequestData]);
});

test('should propose code', async () => {
assert.equal(proposeStub.callCount, 1);
assert.deepEqual(proposeStub.firstCall.args, [
{
...dataWithOriginComments,
proposal: {
title: 'Fix a minor bug',
body: 'This PR fixes a minor bug.',
},
},
{
baseURL: 'https://api.automa.app',
},
]);
});

test('should cleanup code', async () => {
assert.equal(cleanupStub.callCount, 1);
assert.deepEqual(cleanupStub.firstCall.args, [dataWithOriginComments]);
});
});

suite('with download error', () => {
let error: any;

Check warning on line 344 in test/events/processTask.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 344 in test/events/processTask.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

setup(async () => {
downloadStub.rejects(new Error('Download error'));
Expand Down Expand Up @@ -303,7 +389,7 @@
});

suite('with claude code error', () => {
let error: any;

Check warning on line 392 in test/events/processTask.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 392 in test/events/processTask.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

setup(async () => {
queryStub.returns({
Expand Down Expand Up @@ -365,7 +451,7 @@
});

suite('with claude code non-completed output', () => {
let error: any;

Check warning on line 454 in test/events/processTask.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 454 in test/events/processTask.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

setup(async () => {
queryStub.returns({
Expand Down Expand Up @@ -432,7 +518,7 @@
});

suite('with propose error', () => {
let error: any;

Check warning on line 521 in test/events/processTask.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 521 in test/events/processTask.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

setup(async () => {
proposeStub.rejects(new Error('Propose error'));
Expand Down
Loading