Skip to content

Commit

Permalink
add tests for utils
Browse files Browse the repository at this point in the history
  • Loading branch information
zirkelc committed May 8, 2023
1 parent 1c94aa7 commit ad4c2cb
Show file tree
Hide file tree
Showing 18 changed files with 498 additions and 199 deletions.
13 changes: 12 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
"project": "./tsconfig.eslint.json"
},
"rules": {
"no-console": "off",
Expand Down Expand Up @@ -64,6 +64,17 @@
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error"
},
"overrides": [
{
"files": [
"**/*.test.ts"
],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off"
}
}
],
"env": {
"node": true,
"es6": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'build-test'
name: 'Build'
on: # rebuild any PRs and main branch changes
pull_request:
push:
Expand All @@ -7,7 +7,7 @@ on: # rebuild any PRs and main branch changes
- 'releases/*'

jobs:
build: # make sure build/ci work properly
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
53 changes: 28 additions & 25 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,59 @@ 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') }}
# This job only runs for issues
issue:
name: Issue opened
# Only run the job if the issue 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 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') }}
openai_key: ${{ secrets.OPENAI_KEY }}

# This job only runs for issue comments
issue_comment:
name: Issue comment
# Only run the job if the comment contains @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
- uses: ./
name: AdaGPT
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_name == 'issue_comment' && github.event.issue.pull_request && contains(github.event.comment.body, '@AdaGPT') }}
openai_key: ${{ secrets.OPENAI_KEY }}

# This job only runs for pull requests
pull_request:
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 issue comments
issue_commented:
name: Issue comment
openai_key: ${{ secrets.OPENAI_KEY }}
# This job only runs for pull request comments
pull_request_comment:
name: PR comment
# Only run the job if the comment contains @AdaGPT
if: ${{ github.event_name == 'issue_comment' && !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
- uses: ./
name: AdaGPT
name: AdaGPT
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
openai_key: ${{ secrets.OPENAI_KEY }}

37 changes: 30 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ To use AdaGPT, you'll need to create an OpenAI API key and add AdaGPT to your wo

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.
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.
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.
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).

### Workflow
```yaml
# File: .github/workflows/adagpt.yml
name: 'AdaGPT'

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

Expand All @@ -29,21 +33,40 @@ permissions:
pull-requests: write

jobs:
issue_comment:
# Only run the job if the comment contains @AdaGPT (this will also be checked implicitly by the action again)
if: ${{ github.event.comment && contains(github.event.comment.body, '@AdaGPT') }}
name: Issue and PR comments
# Runs for issues, pull requests and comments
adagpt:
name: AdaGPT comment
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# The action will only run if the description or comments mentions @AdaGPT
- uses: zirkelc/adagpt@v1
name: AdaGPT
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
openai_key: ${{ secrets.OPENAI_KEY }}
```
Check out [`main.yml`](./.github/workflows/main.yml) for a working demo.
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`.

```yml
jobs:
# Runs only for issues
issue:
name: Issue opened
# Check if the issue contains @AdaGPT, otherwise skip the workflow run
if: ${{ github.event_name == 'issues' && contains(github.event.issue.body, '@AdaGPT') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: zirkelc/adagpt@v1
name: AdaGPT
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
openai_key: ${{ secrets.OPENAI_KEY }}
```

Check out [`main.yml`](./.github/workflows/main.yml) for more examples.

### Permissions
The `GITHUB_TOKEN` requires the following permissions to create comments on issues and pull requests:
Expand Down
103 changes: 25 additions & 78 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.

Loading

0 comments on commit ad4c2cb

Please sign in to comment.