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 051ff53
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 5 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')
119 changes: 119 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"email": "[email protected]"
},
"dependencies": {
"@octokit/core": "^5.0.2",
"openai": "^4.20.1"
}
}
32 changes: 29 additions & 3 deletions src/openaiExplainPatch.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
import OpenAI from "openai";

export default async function explainPatch({openaiKey, repo, prnum,
export default async function explainPatch({openaiKey, repo, prnum,
githubToken=null,
github=null,
model="gpt-3.5-turbo-16k",
system_prompt="Explain the patch:\n\n",
max_tokens=256,
temperature=1,
top_p=1,
frequency_penalty=0,
presence_penalty=0}) {

if (!github && !githubToken) throw RangeError("github and githubToken arguments cannot be both null");

const openai = new OpenAI({apiKey: openaiKey});

const patchResponse = await fetch(`https://github.com/${repo}/pull/${prnum}.patch`);
const patchBody = await patchResponse.text();
if (!github) {
const { Octokit } = await import("@octokit/core");

github = {
rest: new Octokit({auth: githubToken})
}
}

const [owner, reponame] = repo.split('/');

console.log(github.rest)

const {data: patchBody} = await github.rest.request('GET /repos/{owner}/{repo}/pulls/{pull_number}', {
owner: owner,
repo: reponame,
pull_number: prnum,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
},
mediaType: {
format: "patch",
},
})

return patchBody;

Expand Down

0 comments on commit 051ff53

Please sign in to comment.