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 e19d0b0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
45 changes: 39 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,53 @@ 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')
const watermark = `\n\nWatermark: puLL-Merge - ${process.env.GITHUB_REPOSITORY}@${process.env.PRNUM}`
const watermark = `[puLL-Merge] - ${process.env.GITHUB_REPOSITORY}@${context.issue.number}`
var patchExplained = await explainPatch({
const patchExplained = watermark+"\n\n"+(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 }));
var query = `query($owner:String!, $name:String!, $prnumber:Int!) {
repository(owner:$owner, name:$name) {
pullRequest(number:$prnumber) {
comments(last: 100) {
nodes {
author { login }
body
bodyHTML
bodyText
}
}
}
}
}`;
const variables = {
owner: context.repo.owner,
name: context.repo.repo,
prnumber: context.issue.number
}
const messages = (await github.graphql(query, variables)).repository.pullRequest.comments.nodes;
patchExplained += watermark;
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,
Expand Down
8 changes: 3 additions & 5 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 All @@ -35,7 +33,7 @@ export default async function explainPatch({openaiKey, repo, prnum,
},
})

return patchBody;
return "ANTANI";

const aiResponse = await openai.chat.completions.create({
model: model,
Expand Down

0 comments on commit e19d0b0

Please sign in to comment.