Skip to content

Update mergeable/auto-changelog@RedEyeMods/.github #109

Update mergeable/auto-changelog@RedEyeMods/.github

Update mergeable/auto-changelog@RedEyeMods/.github #109

Workflow file for this run

name: Auto PR Description
on:
pull_request:
types: [opened, edited, synchronize]
branches:
- '**'
jobs:
username-whitelist:
runs-on: ubuntu-latest
env:
CURRENT_USER: ${{ github.event.pull_request.user.login }}
USERNAME_WHITELIST: "['wwwDayDream']"
outputs:
USER_ALLOWED: ${{ steps.user-check.outputs.ENV_CONTAINS }}
steps:
- name: User Check
id: user-check
run: |
echo "Checking if '$CURRENT_USER' is in '$USERNAME_WHITELIST'"
echo "ENV_CONTAINS=${{ contains(fromJson(env.USERNAME_WHITELIST), env.CURRENT_USER) }}" >> $GITHUB_OUTPUT
- run: echo "${{ steps.user-check.outputs.ENV_CONTAINS }}"
explain-diff:
needs: username-whitelist
if: github.event.pull_request.body == '$GPT' && needs.username-whitelist.outputs.USER_ALLOWED == 'true'
runs-on: ubuntu-latest
env:
DIFF_URL: ${{ github.event.pull_request.diff_url }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: GrantBirki/[email protected]
id: git-diff-action
- name: Print Diff
env:
GIT_DIFF: ${{ steps.git-diff-action.outputs.raw-diff }}
run: echo "$GIT_DIFF"
- uses: actions/setup-node@v4
with:
node-version: '20.x'
- run: npm install openai
- name: Call OpenAI API
id: api-ai
uses: actions/github-script@v7
env:
OPENAI_API_TOKEN: ${{ secrets.OPENAI_API_TOKEN }}
GIT_DIFF: ${{ steps.git-diff-action.outputs.raw-diff }}
with:
script: |
const OpenAI = require("openai");
const ai = new OpenAI({
apiKey: process.env.OPENAI_API_TOKEN
});
const userContent = `Pull Request: ${{ github.event.pull_request.title }}
Merges: ${{ github.head_ref }} -> ${{ github.base_ref }}
${process.env.GIT_DIFF}`;
core.setOutput('DIFF_TEXT', userContent);
const repoInfo = ('${{ github.repository }}').split('/');
const owner = repoInfo[0];
const repo = repoInfo[1];
const prNumber = ${{ github.event.pull_request.number }};
core.warning("Running AI!!");
const completion = await ai.chat.completions.create({
messages: [
{
role: "system",
content: `You will receive the output from a 'git diff' command that is executed on a Pull Request, which you will also receive some information about prior to the diff output, and you will be writing the description for it utilizing GitHub's available markdown. Your response should mostly adhere to the following template where you fill in any text within the '<>':
## Description
ℹ️ <Brief overview>
### Changes Made
<Insert List of Changes>`
},
{
role: "user",
content: userContent
}
],
model: "gpt-3.5-turbo"
});
github.rest.pulls.update({
owner: owner,
repo: repo,
pull_number: prNumber,
body: completion.choices[0].message.content
});