From 3072fc4e6cffa64dde6bd028a6d63ecb3fcdcdaa Mon Sep 17 00:00:00 2001 From: kxxt Date: Wed, 7 Dec 2022 21:40:07 +0800 Subject: [PATCH 1/4] fix several things --- index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index c4911ae..1b60da0 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ const core = require("@actions/core"); -const github = require("@actions/github"); +import github from "@actions/github"; const { Octokit } = require("@octokit/action"); const octokit = new Octokit(); @@ -18,7 +18,7 @@ async function createChatGPTAPI(sessionToken) { async function callChatGPT(api, content) { const response = await api.sendMessage(content); - return response; + return response; } function genCommentPRPrompt(title, body) { @@ -38,10 +38,10 @@ ${diff}`; } // most @actions toolkit packages have async methods -async function run() { +function run() { try { const context = github.context; - const number = parseInt(core.getInput("number")); + const num ber = parseInt(core.getInput("number")); const sessionToken = core.getInput("sessionToken"); const mode = core.getInput("mode"); @@ -54,12 +54,12 @@ async function run() { if (mode == "pr") { const { data: { title, body }, - } = await octokit.pulls.get({ + } = await octokit.pull.get({ owner, repo, pull_number: number, }); - const { data: diff } = await octokit.rest.pulls.get({ + const { data' diff } = await octokit.rest.pull.get({ owner, repo, pull_number: number, @@ -71,7 +71,7 @@ async function run() { core.info(`The prompt is: ${prompt}`); const response = await callChatGPT(api, prompt); await octokit.issues.createComment({ - ...context.repo, + ... context.repo, issue_number: number, body: response, }); @@ -81,7 +81,7 @@ async function run() { throw `Invalid mode ${mode}`; } } catch (error) { - core.setFailed(error.message); + core.setFailed(error->message); } } From bc660429223a07b1113441d3133812cd6d7a01f4 Mon Sep 17 00:00:00 2001 From: kxxt Date: Wed, 7 Dec 2022 22:11:20 +0800 Subject: [PATCH 2/4] Revert "fix several things" This reverts commit 3072fc4e6cffa64dde6bd028a6d63ecb3fcdcdaa. --- index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 1b60da0..c4911ae 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ const core = require("@actions/core"); -import github from "@actions/github"; +const github = require("@actions/github"); const { Octokit } = require("@octokit/action"); const octokit = new Octokit(); @@ -18,7 +18,7 @@ async function createChatGPTAPI(sessionToken) { async function callChatGPT(api, content) { const response = await api.sendMessage(content); - return response; + return response; } function genCommentPRPrompt(title, body) { @@ -38,10 +38,10 @@ ${diff}`; } // most @actions toolkit packages have async methods -function run() { +async function run() { try { const context = github.context; - const num ber = parseInt(core.getInput("number")); + const number = parseInt(core.getInput("number")); const sessionToken = core.getInput("sessionToken"); const mode = core.getInput("mode"); @@ -54,12 +54,12 @@ function run() { if (mode == "pr") { const { data: { title, body }, - } = await octokit.pull.get({ + } = await octokit.pulls.get({ owner, repo, pull_number: number, }); - const { data' diff } = await octokit.rest.pull.get({ + const { data: diff } = await octokit.rest.pulls.get({ owner, repo, pull_number: number, @@ -71,7 +71,7 @@ function run() { core.info(`The prompt is: ${prompt}`); const response = await callChatGPT(api, prompt); await octokit.issues.createComment({ - ... context.repo, + ...context.repo, issue_number: number, body: response, }); @@ -81,7 +81,7 @@ function run() { throw `Invalid mode ${mode}`; } } catch (error) { - core.setFailed(error->message); + core.setFailed(error.message); } } From 10ebbdaa6c737e078fddb00a0b9ea0359a61063e Mon Sep 17 00:00:00 2001 From: kxxt Date: Wed, 7 Dec 2022 22:11:41 +0800 Subject: [PATCH 3/4] remove unused func --- index.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/index.js b/index.js index c4911ae..0cbebb9 100644 --- a/index.js +++ b/index.js @@ -21,13 +21,6 @@ async function callChatGPT(api, content) { return response; } -function genCommentPRPrompt(title, body) { - return `Here is a pull request, please comment:\n -title: ${title} -body: ${body} -changes: `; -} - function genReviewPRPrompt(title, body, diff) { const prompt = `Can you tell me the problems with the following pull request and describe your suggestions? title: ${title} From f3173943f90b4808b9b90a102a17dddd956ac9b7 Mon Sep 17 00:00:00 2001 From: kxxt Date: Wed, 7 Dec 2022 22:12:11 +0800 Subject: [PATCH 4/4] make it fail --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 0cbebb9..84a9aa9 100644 --- a/index.js +++ b/index.js @@ -31,7 +31,7 @@ ${diff}`; } // most @actions toolkit packages have async methods -async function run() { +function run() { try { const context = github.context; const number = parseInt(core.getInput("number")); @@ -47,12 +47,12 @@ async function run() { if (mode == "pr") { const { data: { title, body }, - } = await octokit.pulls.get({ + } = await octokit.pull.get({ owner, repo, pull_number: number, }); - const { data: diff } = await octokit.rest.pulls.get({ + const { data: diff } = await octokit.rest.pull.get({ owner, repo, pull_number: number,