Skip to content

Commit ad4c2cb

Browse files
committed
add tests for utils
1 parent 1c94aa7 commit ad4c2cb

18 files changed

+498
-199
lines changed

.eslintrc.json

+12-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"parserOptions": {
1111
"ecmaVersion": 9,
1212
"sourceType": "module",
13-
"project": "./tsconfig.json"
13+
"project": "./tsconfig.eslint.json"
1414
},
1515
"rules": {
1616
"no-console": "off",
@@ -64,6 +64,17 @@
6464
"@typescript-eslint/type-annotation-spacing": "error",
6565
"@typescript-eslint/unbound-method": "error"
6666
},
67+
"overrides": [
68+
{
69+
"files": [
70+
"**/*.test.ts"
71+
],
72+
"rules": {
73+
"@typescript-eslint/no-explicit-any": "off",
74+
"@typescript-eslint/no-non-null-assertion": "off"
75+
}
76+
}
77+
],
6778
"env": {
6879
"node": true,
6980
"es6": true,

.github/workflows/build-test.yml renamed to .github/workflows/build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'build-test'
1+
name: 'Build'
22
on: # rebuild any PRs and main branch changes
33
pull_request:
44
push:
@@ -7,7 +7,7 @@ on: # rebuild any PRs and main branch changes
77
- 'releases/*'
88

99
jobs:
10-
build: # make sure build/ci work properly
10+
build:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v3

.github/workflows/main.yml

+28-25
Original file line numberDiff line numberDiff line change
@@ -17,56 +17,59 @@ permissions:
1717
pull-requests: write
1818

1919
jobs:
20-
# This job only runs for pull requests
21-
pr_opened:
22-
name: PR opened
23-
# Only run the job if the pull request contains @AdaGPT
24-
if: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.body, '@AdaGPT') }}
20+
# This job only runs for issues
21+
issue:
22+
name: Issue opened
23+
# Only run the job if the issue contains @AdaGPT
24+
if: ${{ github.event_name == 'issues' && contains(github.event.issue.body, '@AdaGPT') }}
2525
runs-on: ubuntu-latest
2626
steps:
2727
- uses: actions/checkout@v3
2828
- uses: ./
2929
name: AdaGPT
3030
with:
3131
github_token: ${{ secrets.GITHUB_TOKEN }}
32-
openai_key: ${{ secrets.OPENAI_KEY }}
33-
# This job only runs for issues
34-
issue_opened:
35-
name: Issue opened
36-
# Only run the job if the pull request contains @AdaGPT
37-
if: ${{ github.event_name == 'issues' && contains(github.event.issue.body, '@AdaGPT') }}
32+
openai_key: ${{ secrets.OPENAI_KEY }}
33+
34+
# This job only runs for issue comments
35+
issue_comment:
36+
name: Issue comment
37+
# Only run the job if the comment contains @AdaGPT
38+
if: ${{ github.event_name == 'issue_comment' && !github.event.issue.pull_request && contains(github.event.comment.body, '@AdaGPT') }}
3839
runs-on: ubuntu-latest
3940
steps:
4041
- uses: actions/checkout@v3
4142
- uses: ./
42-
name: AdaGPT
43+
name: AdaGPT
4344
with:
4445
github_token: ${{ secrets.GITHUB_TOKEN }}
45-
openai_key: ${{ secrets.OPENAI_KEY }}
46-
# This job only runs for pull request comments
47-
pr_commented:
48-
name: PR comment
49-
# Only run the job if the comment contains @AdaGPT
50-
if: ${{ github.event_name == 'issue_comment' && github.event.issue.pull_request && contains(github.event.comment.body, '@AdaGPT') }}
46+
openai_key: ${{ secrets.OPENAI_KEY }}
47+
48+
# This job only runs for pull requests
49+
pull_request:
50+
name: PR opened
51+
# Only run the job if the pull request contains @AdaGPT
52+
if: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.body, '@AdaGPT') }}
5153
runs-on: ubuntu-latest
5254
steps:
5355
- uses: actions/checkout@v3
5456
- uses: ./
5557
name: AdaGPT
5658
with:
5759
github_token: ${{ secrets.GITHUB_TOKEN }}
58-
openai_key: ${{ secrets.OPENAI_KEY }}
59-
60-
# This job only runs for issue comments
61-
issue_commented:
62-
name: Issue comment
60+
openai_key: ${{ secrets.OPENAI_KEY }}
61+
62+
# This job only runs for pull request comments
63+
pull_request_comment:
64+
name: PR comment
6365
# Only run the job if the comment contains @AdaGPT
64-
if: ${{ github.event_name == 'issue_comment' && !github.event.issue.pull_request && contains(github.event.comment.body, '@AdaGPT') }}
66+
if: ${{ github.event_name == 'issue_comment' && github.event.issue.pull_request && contains(github.event.comment.body, '@AdaGPT') }}
6567
runs-on: ubuntu-latest
6668
steps:
6769
- uses: actions/checkout@v3
6870
- uses: ./
69-
name: AdaGPT
71+
name: AdaGPT
7072
with:
7173
github_token: ${{ secrets.GITHUB_TOKEN }}
7274
openai_key: ${{ secrets.OPENAI_KEY }}
75+

README.md

+30-7
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ To use AdaGPT, you'll need to create an OpenAI API key and add AdaGPT to your wo
1111

1212
1. Create an [OpenAI API key](https://platform.openai.com/account/api-keys) if you don't already have one. Keep in mind that you'll occur charges for using the API.
1313
2. Save your OpenAI API key as a [Secret](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) in your repository.
14-
3. Create a new workflow in folder `.github/workflows` that will be executed for [new comments](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#issue_comment) on issues and pull requests.
14+
3. Create a new workflow in folder `.github/workflows` that will be triggered on [issues](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#issues), [pull requests](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request) and [comments](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#issue_comment).
1515

1616
### Workflow
1717
```yaml
1818
# File: .github/workflows/adagpt.yml
1919
name: 'AdaGPT'
2020

21-
# Run the workflow on new issue comments
21+
# Run the workflow on new issues, pull requests and comments
2222
on:
23+
issues:
24+
types: [opened]
25+
pull_request:
26+
types: [opened]
2327
issue_comment:
2428
types: [created]
2529

@@ -29,21 +33,40 @@ permissions:
2933
pull-requests: write
3034

3135
jobs:
32-
issue_comment:
33-
# Only run the job if the comment contains @AdaGPT (this will also be checked implicitly by the action again)
34-
if: ${{ github.event.comment && contains(github.event.comment.body, '@AdaGPT') }}
35-
name: Issue and PR comments
36+
# Runs for issues, pull requests and comments
37+
adagpt:
38+
name: AdaGPT comment
3639
runs-on: ubuntu-latest
3740
steps:
3841
- uses: actions/checkout@v3
42+
# The action will only run if the description or comments mentions @AdaGPT
3943
- uses: zirkelc/adagpt@v1
4044
name: AdaGPT
4145
with:
4246
github_token: ${{ secrets.GITHUB_TOKEN }}
4347
openai_key: ${{ secrets.OPENAI_KEY }}
4448
```
4549
46-
Check out [`main.yml`](./.github/workflows/main.yml) for a working demo.
50+
The action will only run if the issue, pull requests or comments mentions `@AdaGPT`. Otherwise, the action will return immediately without doing anything. If you want to skip the whole workflow run, you can use the [`if` conditional](https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idif) to check if the issue, pull request or comment mentions `@AdaGPT`.
51+
52+
```yml
53+
jobs:
54+
# Runs only for issues
55+
issue:
56+
name: Issue opened
57+
# Check if the issue contains @AdaGPT, otherwise skip the workflow run
58+
if: ${{ github.event_name == 'issues' && contains(github.event.issue.body, '@AdaGPT') }}
59+
runs-on: ubuntu-latest
60+
steps:
61+
- uses: actions/checkout@v3
62+
- uses: zirkelc/adagpt@v1
63+
name: AdaGPT
64+
with:
65+
github_token: ${{ secrets.GITHUB_TOKEN }}
66+
openai_key: ${{ secrets.OPENAI_KEY }}
67+
```
68+
69+
Check out [`main.yml`](./.github/workflows/main.yml) for more examples.
4770

4871
### Permissions
4972
The `GITHUB_TOKEN` requires the following permissions to create comments on issues and pull requests:

dist/index.js

+25-78
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)