Skip to content

Commit

Permalink
action.yml: delete scaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
thypon committed Nov 29, 2023
1 parent 253de5b commit 83c1774
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
36 changes: 33 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ runs:
env:
OPENAI_API_KEY: ${{ inputs.openai_api_key }}
GITHUB_TOKEN: ${{ inputs.github_token }}
PRNUM: ${{ github.event.number }}
with:
script: |
const { default: explainPatch } = await import('${{ github.action_path }}/src/openaiExplainPatch.js')
Expand All @@ -39,11 +38,42 @@ runs:
var patchExplained = await explainPatch({
openaiKey: process.env.OPENAI_API_KEY,
github: github,
repo: process.env.GITHUB_REPOSITORY,
prnum: process.env.PRNUM});
owner: context.repo.owner,
repo: context.repo.repo,
prnum: context.issue.number });
patchExplained += watermark;
var query = `query($owner:String!, $name:String!, $prnumber:Int!) {
repository(owner:$owner, name:$name) {
pullRequest(number:$prnumber) {
comments(first: 100) {
nodes {
author { login }
body
bodyHTML
bodyText
}
}
}
}
}`;
const messages = (await github.graphql(query, variables)).repository.pullRequest.comments.nodes;
for (var i = 0; i < messages.length; i++) {
if (messages[i].body.includes(watermark)) {
console.log(messages[i])
/*await github.request('DELETE /repos/{owner}/{repo}/issues/comments/{comment_id}', {
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: 'COMMENT_ID',
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
})*/
}
}
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
Expand Down
6 changes: 2 additions & 4 deletions src/openaiExplainPatch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import OpenAI from "openai";

export default async function explainPatch({openaiKey, repo, prnum,
export default async function explainPatch({openaiKey, owner, repo, prnum,
githubToken=null,
github=null,
model="gpt-3.5-turbo-16k",
Expand All @@ -21,11 +21,9 @@ export default async function explainPatch({openaiKey, repo, prnum,
github = new Octokit({auth: githubToken})
}

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

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

0 comments on commit 83c1774

Please sign in to comment.