Skip to content

Commit

Permalink
action.yml: add support for private patches
Browse files Browse the repository at this point in the history
  • Loading branch information
thypon committed Nov 29, 2023
1 parent 3ef47f9 commit 613f008
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
7 changes: 5 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ runs:
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
if: ${{ inputs.openai_api_key != '' }}
env:
OPENAI_API_KEY: ${{ inputs.openai_api_key }}
OPENAI_API_KEY: ${{ inputs.openai_api_key }}
GITHUB_TOKEN: ${{ inputs.github_token }}
PRNUM: ${{ github.event.issue.number }}
with:
script: |
const { default: explainPatch } = await import('${{ github.action_path }}/src/openaiExplainPatch.js')
console.log(process.env)
console.log(await explainPatch({
openaiKey: process.env.OPENAI_API_KEY,
githubToken: process.env.GITHUB_TOKEN,
repo: process.env.GITHUB_ACTION_REPOSITORY,
prnum: process.env.GITHUB_REF_NAME.split('/')[0]}))
prnum: process.env.PRNUM}))
console.log('rerun')
console.log('implement me')
15 changes: 13 additions & 2 deletions src/openaiExplainPatch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import OpenAI from "openai";

export default async function explainPatch({openaiKey, repo, prnum,
export default async function explainPatch({openaiKey, repo, prnum,
githubToken=null,
model="gpt-3.5-turbo-16k",
system_prompt="Explain the patch:\n\n",
max_tokens=256,
Expand All @@ -10,7 +11,17 @@ export default async function explainPatch({openaiKey, repo, prnum,
presence_penalty=0}) {
const openai = new OpenAI({apiKey: openaiKey});

const patchResponse = await fetch(`https://github.com/${repo}/pull/${prnum}.patch`);
const githubHeaders = {
Accept: 'application/vnd.github.3.patch',
'X-GitHub-Api-Version': '2022-11-28'
};

if (githubToken)
githubHeaders['Authorization'] = `Bearer ${githubToken}`;

const patchResponse = await fetch(`https://api.github.com/repos/${repo}/pulls/${prnum}.patch`, {
method: 'GET',
headers: githubHeaders});
const patchBody = await patchResponse.text();

return patchBody;
Expand Down

0 comments on commit 613f008

Please sign in to comment.