Add the PR description reviewer workflow #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Pull Request Reviewer | |
on: | |
pull_request: | |
types: [opened, reopened, edited] | |
jobs: | |
pr_reviewer_job: | |
runs-on: ubuntu-latest | |
name: A job to review pull request descriptions | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
repository: firefliesai/.github | |
path: firefliesai | |
sparse-checkout-cone-mode: false | |
sparse-checkout: | | |
.github/scripts/PR_reviewer.js | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
registry-url: https://npm.pkg.github.com | |
scope: '@firefliesai' | |
- name: Install packages | |
env: | |
GTP_TOKEN: ${{ secrets.CROSS_REPO_TOKEN }} | |
run: | | |
[ -f package.json ] && mv package.json package.json.xx | |
npm install openai @octokit/rest @slack/web-api slackify-markdown | |
- name: Run PR Reviewer | |
uses: actions/github-script@v6 | |
id: reviewer | |
env: | |
GTP_TOKEN: ${{ secrets.CROSS_REPO_TOKEN }} | |
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }} | |
with: | |
script: | | |
const { Octokit } = require('@octokit/rest'); | |
const OpenAI = require('openai'); | |
const { WebClient } = require('@slack/web-api'); | |
const format = require('slackify-markdown'); | |
const { reviewPR } = require('${{ github.workspace }}/firefliesai/.github/scripts/PR_reviewer.js'); | |
console.log('import reviewPR', reviewPR); | |
if (!process.env.GTP_TOKEN) { | |
throw new Error('GTP_TOKEN is not set'); | |
} | |
if (!process.env.OPENAI_API_KEY) { | |
throw new Error('OPENAI_API_KEY is not set'); | |
} | |
if (!process.env.SLACK_TOKEN) { | |
throw new Error('SLACK_TOKEN is not set'); | |
} | |
// OCTOKIT REFERENCE: https://octokit.github.io/rest.js/v20 | |
const octokit = new Octokit({ | |
auth: process.env.GTP_TOKEN, | |
request: { | |
fetch, | |
}, | |
}); | |
const openai = new OpenAI({ | |
apiKey: process.env.OPENAI_API_KEY, | |
}); | |
const slack = new WebClient(process.env.SLACK_TOKEN); | |
await reviewPR({ openai, octokit, slack, format, context }); |