Skip to content

Commit

Permalink
Bot - Fix Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
homieggbot committed Oct 6, 2024
1 parent 6a257a2 commit 3cd886c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
12 changes: 7 additions & 5 deletions src/lib/ai/chat/get-answer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ export async function getAnswer(params: GetAnswerParams): Promise<string> {
channelID: channelID,
answerID,
}),
isGitHubContext ? getGitHubPullRequestContextTool({
organization,
answerID,
channelID,
}) : null,
isGitHubContext
? getGitHubPullRequestContextTool({

Check failure on line 100 in src/lib/ai/chat/get-answer.ts

View workflow job for this annotation

GitHub Actions / 🎯 Typecheck

Cannot find name 'getGitHubPullRequestContextTool'.
organization,
answerID,
channelID,
})
: null,
getTodaysDateTool({ answerId: answerID, organization }),
getFindCompletedTasksTool({
organization,
Expand Down
10 changes: 7 additions & 3 deletions src/lib/ai/chat/tools/get-github-pull-request-context-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ interface GetGitHubPullRequestContextToolParams {
channelID: string
}

export function getGitHubPullRequestContextTool(params: GetGitHubPullRequestContextToolParams) {
export function getGitHubPullRequestContextTool(
params: GetGitHubPullRequestContextToolParams,
) {
const { organization, answerID, channelID } = params
return new DynamicTool({
name: 'get_github_pull_request_context',
Expand All @@ -34,15 +36,17 @@ export function getGitHubPullRequestContextTool(params: GetGitHubPullRequestCont
})

const [, repoId] = channelID.split('-')
const repo = await github.rest.repos.getById({ repo_id: parseInt(repoId) })
const repo = await github.rest.repos.getById({

Check failure on line 39 in src/lib/ai/chat/tools/get-github-pull-request-context-tool.ts

View workflow job for this annotation

GitHub Actions / 🎯 Typecheck

Property 'getById' does not exist on type '{ acceptInvitation: { (params?: (RequestParameters & { invitation_id: number; }) | undefined): Promise<OctokitResponse<never, 204>>; defaults: <O extends RequestParameters = RequestParameters>(newDefaults: O) => RequestInterface<...>; endpoint: EndpointInterface<...>; }; ... 199 more ...; uploadReleaseAsset: { ...; ...'.
repo_id: parseInt(repoId),
})

const pulls = await github.rest.pulls.list({
owner: repo.data.owner.login,
repo: repo.data.name,
state: 'open',
})

const prContext = pulls.data.map(pr => ({
const prContext = pulls.data.map((pr) => ({
number: pr.number,
title: pr.title,
user: pr.user.login,

Check failure on line 52 in src/lib/ai/chat/tools/get-github-pull-request-context-tool.ts

View workflow job for this annotation

GitHub Actions / 🎯 Typecheck

'pr.user' is possibly 'null'.
Expand Down
22 changes: 18 additions & 4 deletions src/pages/api/github/review-comment-webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,35 @@ import { logger } from '@/lib/log/logger'

export default async function handler(
req: NextApiRequest,
res: NextApiResponse
res: NextApiResponse,
) {
if (req.method !== 'POST') {
return res.status(405).json({ message: 'Method not allowed' })
}

const { body } = req

if (body.action !== 'created' || !body.comment || !body.comment.body.includes('@homie')) {
if (
body.action !== 'created' ||
!body.comment ||
!body.comment.body.includes('@homie')
) {
return res.status(200).json({ message: 'No action needed' })
}

try {
const organization = await dbClient
.selectFrom('homie.organization')
.where('ext_gh_install_id', '=', body.installation.id)

Check failure on line 28 in src/pages/api/github/review-comment-webhook.ts

View workflow job for this annotation

GitHub Actions / 🎯 Typecheck

Argument of type '"ext_gh_install_id"' is not assignable to parameter of type 'ReferenceExpression<KyselySchema, "homie.organization">'.
.select(['id', 'ext_gh_install_id', 'is_persona_enabled', 'persona_positivity_level', 'persona_g_level', 'persona_affection_level', 'persona_emoji_level'])
.select([

Check failure on line 29 in src/pages/api/github/review-comment-webhook.ts

View workflow job for this annotation

GitHub Actions / 🎯 Typecheck

No overload matches this call.
'id',
'ext_gh_install_id',
'is_persona_enabled',
'persona_positivity_level',
'persona_g_level',
'persona_affection_level',
'persona_emoji_level',
])
.executeTakeFirst()

if (!organization) {
Expand All @@ -35,7 +47,9 @@ export default async function handler(
const message = body.comment.body.replace('@homie', '').trim()
const answer = await getAnswer({
organization,
messages: [{ type: 'human', text: message, ts: new Date().toISOString() }],
messages: [
{ type: 'human', text: message, ts: new Date().toISOString() },
],
channelID: `github-${body.repository.id}`,
})

Expand Down

0 comments on commit 3cd886c

Please sign in to comment.