forked from kxxt/chatgpt-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (26 loc) · 856 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const core = require("@actions/core");
const { createChatGPTAPI } = require("./chatgpt");
const { runPRReview } = require("./run");
// most @actions toolkit packages have async methods
async function run() {
try {
const number = parseInt(core.getInput("number"));
const sessionToken = core.getInput("sessionToken");
const mode = core.getInput("mode");
const split = core.getInput("split");
// Get current repo.
const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/");
// Create ChatGPT API
const api = await createChatGPTAPI(sessionToken);
if (mode == "pr") {
runPRReview({ api, owner, repo, number, split });
} else if (mode == "issue") {
throw "Not implemented!";
} else {
throw `Invalid mode ${mode}`;
}
} catch (error) {
core.setFailed(error.message);
}
}
run();