Skip to content

Commit

Permalink
add new triggers for issues and pull requests
Browse files Browse the repository at this point in the history
  • Loading branch information
zirkelc committed May 5, 2023
1 parent 6969fd3 commit 1c94aa7
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 23 deletions.
1 change: 1 addition & 0 deletions .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
push:
branches:
- main
- next
paths-ignore:
- '**.md'
pull_request:
Expand Down
46 changes: 37 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
name: AdaGPT

# Trigger the workflow on issue comments
on:
# Trigger the workflow on new issues
issues:
types: [opened]
# Trigger the workflow on new pull requests
pull_request:
types: [opened]
# Trigger the workflow on new issue comments
issue_comment:
types: [created]

Expand All @@ -11,34 +17,56 @@ permissions:
pull-requests: write

jobs:
# This job only runs for pull requests
pr_opened:
name: PR opened
# Only run the job if the pull request contains @AdaGPT
if: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.body, '@AdaGPT') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./
name: AdaGPT
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
openai_key: ${{ secrets.OPENAI_KEY }}
# This job only runs for issues
issue_opened:
name: Issue opened
# Only run the job if the pull request contains @AdaGPT
if: ${{ github.event_name == 'issues' && contains(github.event.issue.body, '@AdaGPT') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./
name: AdaGPT
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
openai_key: ${{ secrets.OPENAI_KEY }}
# This job only runs for pull request comments
pr_commented:
name: PR comment
# Only run the job if the comment contains @AdaGPT
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '@AdaGPT') }}
if: ${{ github.event_name == 'issue_comment' && github.event.issue.pull_request && contains(github.event.comment.body, '@AdaGPT') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# Replace ./ with zirkelc/adagpt@v1 to use the action
- uses: ./
- uses: ./
name: AdaGPT
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# Reference secrets from the repository settings/secrets/actions
openai_key: ${{ secrets.OPENAI_KEY }}

# This job only runs for issue comments
issue_commented:
name: Issue comment
# Only run the job if the comment contains @AdaGPT
if: ${{ !github.event.issue.pull_request && contains(github.event.comment.body, '@AdaGPT') }}
if: ${{ github.event_name == 'issue_comment' && !github.event.issue.pull_request && contains(github.event.comment.body, '@AdaGPT') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# Replace ./ with zirkelc/adagpt@v1 to use the action
- uses: ./
- uses: ./
name: AdaGPT
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# Reference secrets from the repository settings/secrets/actions
openai_key: ${{ secrets.OPENAI_KEY }}
10 changes: 4 additions & 6 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function run(): Promise<void> {
debug('Trigger', { trigger });

// check if the event body contains the assistant handle, otherwise skip
if (!trigger?.body || ASSISTANT_REGEX.test(trigger.body)) {
if (!trigger?.body || !ASSISTANT_REGEX.test(trigger.body)) {
debug(`Event doesn't contain ${ASSISTANT_HANDLE}. Skipping...`);
return;
}
Expand Down
10 changes: 4 additions & 6 deletions src/openai/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ export async function generateCompletion(
} catch (error) {
if (isAxiosError(error)) {
const response = error.response;
if (response?.status === 429) {
core.error(
'Request to OpenAI failed with status 429. This is due to incorrect billing setup or excessive quota usage. Please follow this guide to fix it: https://help.openai.com/en/articles/6891831-error-code-429-you-exceeded-your-current-quota-please-check-your-plan-and-billing-details',
);
} else {
core.error(`Request to OpenAI failed with status ${response?.status}: ${response?.data?.error?.message}`);
core.error(`Request to OpenAI failed with status ${response?.status}: ${response?.data?.error?.message}`);

if (response?.status) {
core.error('API Error Codes: https://help.openai.com/en/collections/3808446-api-error-codes-explained');
}
} else {
const message = error instanceof Error ? error.message : error;
Expand Down

0 comments on commit 1c94aa7

Please sign in to comment.