Skip to content

Commit

Permalink
Merge pull request #55 from ca-dp/fix-error-handle
Browse files Browse the repository at this point in the history
Fix error handle
  • Loading branch information
ouchi2501 authored Oct 19, 2023
2 parents 676e304 + 1b90ff3 commit 78e0967
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
8 changes: 6 additions & 2 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ describe('run', () => {
await main.run()

// Ensure the error message was set correctly
expect(setFailedMock).toHaveBeenCalledWith('Response content is missing')
expect(setFailedMock).toHaveBeenCalledWith(
'[review]Response content is missing'
)

// Clear environment variables
delete process.env.OPENAI_API_KEY
Expand Down Expand Up @@ -180,7 +182,9 @@ describe('run', () => {
await main.run()

// Ensure the error message was set correctly
expect(setFailedMock).toHaveBeenCalledWith('Response content is missing')
expect(setFailedMock).toHaveBeenCalledWith(
'[chat]Response content is missing'
)

// Clear environment variables
delete process.env.OPENAI_API_KEY
Expand Down
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export async function run(): Promise<void> {
switch (cmd) {
case 'review': {
const diff = await github.getPullRequestDiff()
if (diff === '') {
core.setFailed('Pull request diff is missing')
}
const sysPrompt = prompt.getCodeReviewSystemPrompt()
const messagePromise = ai.completionRequest(
core.getInput('OPENAI_API_KEY', { required: true }),
Expand All @@ -22,7 +25,7 @@ export async function run(): Promise<void> {
const message = await messagePromise

if (message === '') {
core.setFailed('Response content is missing')
core.setFailed('[review]Response content is missing')
}

await github.createGitHubComment(message)
Expand All @@ -44,7 +47,7 @@ export async function run(): Promise<void> {
)
const response = await responseMessage
if (response === '') {
core.setFailed('Response content is missing')
core.setFailed('[chat]Response content is missing')
}

await github.createGitHubComment(response)
Expand Down

0 comments on commit 78e0967

Please sign in to comment.