diff --git a/src/update/index.ts b/src/update/index.ts index c11a2ce..7106840 100644 --- a/src/update/index.ts +++ b/src/update/index.ts @@ -7,12 +7,23 @@ export const update = async ( folder: CodeFolder, data: WebhookEventData, ) => { - const description = data.task.items + const descriptions = data.task.items .filter(({ type }) => type === 'message') - .map(({ data }) => `${(data as any).content}`) - .join('\n'); + .map(({ data }) => `${(data as any).content}`); - const message = `${data.task.title}${description}`; + const originData = + data.task.items.find(({ type }) => type === 'origin')?.data ?? {}; + + const comments = ((originData as any).issueComments ?? []).map( + ({ body, userName }: { body: string; userName: string }) => + `${body}`, + ); + + const message = [ + `${data.task.title}`, + ...descriptions, + ...comments, + ].join('\n'); const run = query({ prompt: message, diff --git a/test/events/processTask.test.ts b/test/events/processTask.test.ts index 37e9640..5fd0b55 100644 --- a/test/events/processTask.test.ts +++ b/test/events/processTask.test.ts @@ -48,6 +48,33 @@ const dataWithDescription = { }, } as WebhookEventData; +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; + const codeFixture = join(__dirname, '..', 'fixtures', 'code'); const anthropicRequestData = { @@ -218,7 +245,7 @@ suite('events/processTask', () => { assert.deepEqual(queryStub.firstCall.args, [ { prompt: - 'Fix a minor bugIt does not work', + 'Fix a minor bug\nIt does not work', options: { cwd: codeFixture, permissionMode: 'bypassPermissions', @@ -254,6 +281,65 @@ suite('events/processTask', () => { }); }); + 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: + 'Fix a minor bug\nThis is a comment\nThis is another 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;