mirror of
https://gitea.com/Lydanne/issues-helper.git
synced 2025-08-20 18:55:47 +08:00
feat: add mark-duplicate (#23)
* feat: add mark-duplicate * add * add * add * add * add * add * add * change * update
This commit is contained in:
34
src/base.js
34
src/base.js
@@ -24,6 +24,8 @@ const octokit = new Octokit({ auth: `token ${token}` });
|
||||
const contents = core.getInput("contents");
|
||||
const issueContents = core.getInput("issue-contents");
|
||||
|
||||
const context = github.context;
|
||||
|
||||
async function doAddAssignees (owner, repo, issueNumber, assignees) {
|
||||
await octokit.issues.addAssignees({
|
||||
owner,
|
||||
@@ -138,6 +140,32 @@ async function doLockIssue (owner, repo, issueNumber) {
|
||||
core.info(`Actions: [lock-issue][${issueNumber}] success!`);
|
||||
};
|
||||
|
||||
async function doMarkDuplicate (owner, repo, labels) {
|
||||
if (context.eventName != 'issue_comment') {
|
||||
core.info(`This actions only support on 'issue_comment'!`);
|
||||
return false;
|
||||
}
|
||||
const duplicateCommand = core.getInput("duplicate-command") || '/d';
|
||||
const duplicateLabels = core.getInput("duplicate-labels");
|
||||
|
||||
const commentId = context.payload.comment.id;
|
||||
const commentBody = context.payload.comment.body;
|
||||
const issueNumber = context.payload.issue.number;
|
||||
|
||||
if (commentBody.startsWith(duplicateCommand) && commentBody.split(' ')[0] == duplicateCommand) {
|
||||
const nextBody = commentBody.replace(duplicateCommand, 'Duplicate of');
|
||||
await doUpdateComment(owner, repo, commentId, nextBody, 'replace', true);
|
||||
if (duplicateLabels) {
|
||||
await doAddLabels(owner, repo, issueNumber, duplicateLabels);
|
||||
}
|
||||
if (labels) {
|
||||
await doSetLabels(owner, repo, issueNumber, labels);
|
||||
}
|
||||
} else {
|
||||
core.info(`This comment body should start whith 'duplicate-command'`);
|
||||
}
|
||||
};
|
||||
|
||||
async function doOpenIssue (owner, repo, issueNumber) {
|
||||
await octokit.issues.update({
|
||||
owner,
|
||||
@@ -204,7 +232,8 @@ async function doUpdateComment (
|
||||
repo,
|
||||
commentId,
|
||||
body,
|
||||
updateMode
|
||||
updateMode,
|
||||
ifUpdateBody,
|
||||
) {
|
||||
const comment = await octokit.issues.getComment({
|
||||
owner,
|
||||
@@ -219,7 +248,7 @@ async function doUpdateComment (
|
||||
comment_id: commentId
|
||||
};
|
||||
|
||||
if (core.getInput("body")) {
|
||||
if (core.getInput("body") || ifUpdateBody) {
|
||||
if (updateMode === 'append') {
|
||||
params.body = `${comment_body}\n${body}`;
|
||||
} else {
|
||||
@@ -355,6 +384,7 @@ module.exports = {
|
||||
doCreateIssue,
|
||||
doCreateIssueContent,
|
||||
doDeleteComment,
|
||||
doMarkDuplicate,
|
||||
doLockIssue,
|
||||
doOpenIssue,
|
||||
doRemoveAssignees,
|
||||
|
Reference in New Issue
Block a user