Skip to content

Commit 3e54409

Browse files
author
pompurin404
committed
support label and rename issue
1 parent f038edd commit 3e54409

4 files changed

Lines changed: 267 additions & 147 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
- [x] Close issue(closeIssue)
88
- [x] Lock issue(lockIssue)
9-
- [x] Comment issues(commentIssue)
9+
- [x] Comment issue(commentIssue)
10+
- [x] Label issue(labelIssue)
11+
- [x] Rename issue(renameIssue)
1012
- [ ] and more...
1113

1214
## Inputs

dist/index.js

Lines changed: 126 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -40017,69 +40017,133 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4001740017
return (mod && mod.__esModule) ? mod : { "default": mod };
4001840018
};
4001940019
Object.defineProperty(exports, "__esModule", ({ value: true }));
40020-
exports.commentIssue = exports.lockIssue = exports.closeIssue = void 0;
40020+
exports.init_tools = init_tools;
4002140021
const zod_1 = __nccwpck_require__(931);
4002240022
const zod_to_json_schema_1 = __importDefault(__nccwpck_require__(3109));
4002340023
const github = __importStar(__nccwpck_require__(3802));
4002440024
const _1 = __nccwpck_require__(3300);
40025-
// close issue
40026-
const CloseParams = zod_1.z.object({
40027-
reason: zod_1.z.enum(["not_planned", "completed"]),
40028-
});
40029-
exports.closeIssue = zodFunction({
40030-
name: "closeIssue",
40031-
description: "Close Issue",
40032-
function: async ({ reason }) => {
40033-
const octokit = github.getOctokit(_1.github_token);
40034-
octokit.rest.issues.update({
40035-
owner: github.context.issue.owner,
40036-
repo: github.context.issue.repo,
40037-
issue_number: github.context.issue.number,
40038-
state: "closed",
40039-
state_reason: reason,
40040-
});
40041-
console.log(`#${github.context.issue.number} closed as ${reason}`);
40042-
},
40043-
schema: CloseParams,
40044-
});
40045-
// lock issue
40046-
const LockParams = zod_1.z.object({
40047-
reason: zod_1.z.enum(["off-topic", "spam", "too heated", "resolved"]),
40048-
});
40049-
exports.lockIssue = zodFunction({
40050-
name: "lockIssue",
40051-
description: "Lock Issue",
40052-
function: async ({ reason }) => {
40053-
const octokit = github.getOctokit(_1.github_token);
40054-
octokit.rest.issues.lock({
40055-
owner: github.context.issue.owner,
40056-
repo: github.context.issue.repo,
40057-
issue_number: github.context.issue.number,
40058-
lock_reason: reason,
40059-
});
40060-
console.log(`#${github.context.issue.number} locked as ${reason}`);
40061-
},
40062-
schema: LockParams,
40063-
});
40064-
// comment issue
40065-
const CommentParams = zod_1.z.object({
40066-
content: zod_1.z.string(),
40067-
});
40068-
exports.commentIssue = zodFunction({
40069-
name: "commentIssue",
40070-
description: "Comment Issue",
40071-
function: async ({ content }) => {
40072-
const octokit = github.getOctokit(_1.github_token);
40073-
octokit.rest.issues.createComment({
40025+
const octokit = github.getOctokit(_1.github_token);
40026+
async function init_tools() {
40027+
let repo_labels = [
40028+
"bug",
40029+
"enhancement",
40030+
"question",
40031+
"invalid",
40032+
"wontfix",
40033+
"duplicate",
40034+
];
40035+
try {
40036+
const labels = await octokit.rest.issues.listLabelsForRepo({
4007440037
owner: github.context.issue.owner,
4007540038
repo: github.context.issue.repo,
40076-
issue_number: github.context.issue.number,
40077-
body: content,
4007840039
});
40079-
console.log(`#${github.context.issue.number} commented: ${content}`);
40080-
},
40081-
schema: CommentParams,
40082-
});
40040+
const labelNames = labels.data.map((label) => label.name);
40041+
if (labelNames.length > 0) {
40042+
repo_labels = [labelNames[0], ...labelNames.slice(1)];
40043+
}
40044+
}
40045+
catch (e) {
40046+
console.log(e);
40047+
}
40048+
// close issue
40049+
const CloseParams = zod_1.z.object({
40050+
reason: zod_1.z.enum(["not_planned", "completed"]),
40051+
});
40052+
const closeIssue = zodFunction({
40053+
name: "closeIssue",
40054+
description: "Close Issue",
40055+
function: async ({ reason }) => {
40056+
octokit.rest.issues.update({
40057+
owner: github.context.issue.owner,
40058+
repo: github.context.issue.repo,
40059+
issue_number: github.context.issue.number,
40060+
state: "closed",
40061+
state_reason: reason,
40062+
});
40063+
console.log(`#${github.context.issue.number} closed as ${reason}`);
40064+
},
40065+
schema: CloseParams,
40066+
});
40067+
// lock issue
40068+
const LockParams = zod_1.z.object({
40069+
reason: zod_1.z.enum(["off-topic", "spam", "too heated", "resolved"]),
40070+
});
40071+
const lockIssue = zodFunction({
40072+
name: "lockIssue",
40073+
description: "Lock Issue",
40074+
function: async ({ reason }) => {
40075+
octokit.rest.issues.lock({
40076+
owner: github.context.issue.owner,
40077+
repo: github.context.issue.repo,
40078+
issue_number: github.context.issue.number,
40079+
lock_reason: reason,
40080+
});
40081+
console.log(`#${github.context.issue.number} locked as ${reason}`);
40082+
},
40083+
schema: LockParams,
40084+
});
40085+
// comment issue
40086+
const CommentParams = zod_1.z.object({
40087+
content: zod_1.z.string(),
40088+
});
40089+
const commentIssue = zodFunction({
40090+
name: "commentIssue",
40091+
description: "Comment Issue",
40092+
function: async ({ content }) => {
40093+
octokit.rest.issues.createComment({
40094+
owner: github.context.issue.owner,
40095+
repo: github.context.issue.repo,
40096+
issue_number: github.context.issue.number,
40097+
body: content,
40098+
});
40099+
console.log(`#${github.context.issue.number} commented: ${content}`);
40100+
},
40101+
schema: CommentParams,
40102+
});
40103+
// label issue
40104+
const LabelParams = zod_1.z.object({
40105+
label: zod_1.z.array(zod_1.z.enum(repo_labels)),
40106+
});
40107+
const labelIssue = zodFunction({
40108+
name: "labelIssue",
40109+
description: "Label Issue",
40110+
function: async ({ label }) => {
40111+
octokit.rest.issues.addLabels({
40112+
owner: github.context.issue.owner,
40113+
repo: github.context.issue.repo,
40114+
issue_number: github.context.issue.number,
40115+
labels: label,
40116+
});
40117+
console.log(`#${github.context.issue.number} labeled: ${label}`);
40118+
},
40119+
schema: LabelParams,
40120+
});
40121+
// rename issue
40122+
const RenameParams = zod_1.z.object({
40123+
title: zod_1.z.string(),
40124+
});
40125+
const renameIssue = zodFunction({
40126+
name: "renameIssue",
40127+
description: "Rename Issue",
40128+
function: async ({ title }) => {
40129+
octokit.rest.issues.update({
40130+
owner: github.context.issue.owner,
40131+
repo: github.context.issue.repo,
40132+
issue_number: github.context.issue.number,
40133+
title: title,
40134+
});
40135+
console.log(`#${github.context.issue.number} renamed: ${title}`);
40136+
},
40137+
schema: RenameParams,
40138+
});
40139+
return {
40140+
closeIssue,
40141+
lockIssue,
40142+
commentIssue,
40143+
labelIssue,
40144+
renameIssue,
40145+
};
40146+
}
4008340147
// utils function
4008440148
function zodFunction({ function: fn, schema, description = "", name, }) {
4008540149
return {
@@ -40138,7 +40202,7 @@ const github = __importStar(__nccwpck_require__(3802));
4013840202
const core = __importStar(__nccwpck_require__(4708));
4013940203
const openai_1 = __importDefault(__nccwpck_require__(9448));
4014040204
let tools = [];
40141-
function checkInput() {
40205+
async function checkInput() {
4014240206
if (!exports.openai_base_url) {
4014340207
exports.openai_base_url = "https://api.openai.com/v1";
4014440208
}
@@ -40160,21 +40224,12 @@ function checkInput() {
4016040224
if (!exports.available_tools) {
4016140225
exports.available_tools = "closeIssue,lockIssue,commentIssue";
4016240226
}
40227+
const all_tools = await (0, github_calls_1.init_tools)();
4016340228
exports.available_tools.split(",").forEach((tool) => {
40164-
switch (tool) {
40165-
case "closeIssue":
40166-
tools.push(github_calls_1.closeIssue);
40167-
break;
40168-
case "lockIssue":
40169-
tools.push(github_calls_1.lockIssue);
40170-
break;
40171-
case "commentIssue":
40172-
tools.push(github_calls_1.commentIssue);
40173-
break;
40174-
default:
40175-
throw new Error(`Tool "${tool}" is not available`);
40176-
// todo: support more tools
40229+
if (!all_tools[tool]) {
40230+
throw new Error(`Tool "${tool}" is not available`);
4017740231
}
40232+
tools.push(all_tools[tool]);
4017840233
});
4017940234
}
4018040235
async function main() {
@@ -40186,7 +40241,7 @@ async function main() {
4018640241
exports.github_token = core.getInput("github_token");
4018740242
exports.available_tools = core.getInput("available_tools");
4018840243
exports.action_event = github.context.eventName;
40189-
checkInput();
40244+
await checkInput();
4019040245
const openai = new openai_1.default({
4019140246
baseURL: exports.openai_base_url,
4019240247
apiKey: exports.openai_api_key,

0 commit comments

Comments
 (0)