feat: add mark-duplicate (#23)

* feat: add mark-duplicate

* add

* add

* add

* add

* add

* add

* add

* change

* update
This commit is contained in:
xrkffgg
2020-12-30 13:48:38 +08:00
committed by GitHub
parent a2273a4c3b
commit c81901f651
12 changed files with 223 additions and 9 deletions

View File

@@ -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,

View File

@@ -10,6 +10,7 @@ const {
doCreateIssue,
doCreateIssueContent,
doDeleteComment,
doMarkDuplicate,
doLockIssue,
doOpenIssue,
doRemoveAssignees,
@@ -38,6 +39,7 @@ const ALLACTIONS = [
'create-issue',
'delete-comment',
'lock-issue',
'mark-duplicate',
'open-issue',
'remove-assignees',
'remove-labels',
@@ -79,7 +81,9 @@ async function main() {
updateMode = 'replace';
}
// actions
const actions = core.getInput("actions", { required: true });
const actionsArr = actions.split(',');
actionsArr.forEach(item => {
testActions(item.trim());
@@ -117,6 +121,9 @@ async function main() {
case 'lock-issue':
await doLockIssue(owner, repo, issueNumber);
break;
case 'mark-duplicate':
await doMarkDuplicate(owner, repo, labels);
break;
case 'open-issue':
await doOpenIssue(owner, repo, issueNumber);
break;