mirror of
https://gitea.com/Lydanne/issues-helper.git
synced 2025-08-20 18:55:47 +08:00
Merge pull request #42 from actions-cool/main
chore: merge main into 1.x
This commit is contained in:
@@ -360,14 +360,14 @@ jobs:
|
|||||||
|
|
||||||
#### `mark-duplicate`
|
#### `mark-duplicate`
|
||||||
|
|
||||||
Quickly mark duplicate questions, only for issue new comments.
|
Quickly mark duplicate questions, only for issue new comments or edit comments.
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
name: Issue Mark Duplicate
|
name: Issue Mark Duplicate
|
||||||
|
|
||||||
on:
|
on:
|
||||||
issue_comment:
|
issue_comment:
|
||||||
types: [created]
|
types: [created, edited]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
mark-duplicate:
|
mark-duplicate:
|
||||||
|
@@ -360,14 +360,14 @@ jobs:
|
|||||||
|
|
||||||
#### `mark-duplicate`
|
#### `mark-duplicate`
|
||||||
|
|
||||||
快捷标记重复问题,仅作用于 issue 新增评论。
|
快捷标记重复问题,仅作用于 issue 新增编辑评论。
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
name: Issue Mark Duplicate
|
name: Issue Mark Duplicate
|
||||||
|
|
||||||
on:
|
on:
|
||||||
issue_comment:
|
issue_comment:
|
||||||
types: [created]
|
types: [created, edited]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
mark-duplicate:
|
mark-duplicate:
|
||||||
|
82
dist/index.js
vendored
82
dist/index.js
vendored
@@ -8026,55 +8026,55 @@ async function doMarkDuplicate (owner, repo, labels) {
|
|||||||
core.info(`This actions only support on 'issue_comment'!`);
|
core.info(`This actions only support on 'issue_comment'!`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (context.payload.action != 'created') {
|
|
||||||
core.info(`This actions only support on 'issue_comment' created!`);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const duplicateCommand = core.getInput("duplicate-command");
|
if (context.payload.action == 'created' || context.payload.action == 'edited') {
|
||||||
const duplicateLabels = core.getInput("duplicate-labels");
|
const duplicateCommand = core.getInput("duplicate-command");
|
||||||
const removeLables = core.getInput("remove-labels");
|
const duplicateLabels = core.getInput("duplicate-labels");
|
||||||
const closeIssue = core.getInput("close-issue");
|
const removeLables = core.getInput("remove-labels");
|
||||||
|
const closeIssue = core.getInput("close-issue");
|
||||||
|
|
||||||
const commentId = context.payload.comment.id;
|
const commentId = context.payload.comment.id;
|
||||||
const commentBody = context.payload.comment.body;
|
const commentBody = context.payload.comment.body;
|
||||||
const issueNumber = context.payload.issue.number;
|
const issueNumber = context.payload.issue.number;
|
||||||
|
|
||||||
const ifCommandInput = !!duplicateCommand;
|
const ifCommandInput = !!duplicateCommand;
|
||||||
|
|
||||||
if (!commentBody.includes('?') && ((ifCommandInput && commentBody.startsWith(duplicateCommand) && commentBody.split(' ')[0] == duplicateCommand) || testDuplicate(commentBody))) {
|
if (!commentBody.includes('?') && ((ifCommandInput && commentBody.startsWith(duplicateCommand) && commentBody.split(' ')[0] == duplicateCommand) || testDuplicate(commentBody))) {
|
||||||
if (ifCommandInput) {
|
if (ifCommandInput) {
|
||||||
const nextBody = commentBody.replace(duplicateCommand, 'Duplicate of');
|
const nextBody = commentBody.replace(duplicateCommand, 'Duplicate of');
|
||||||
await doUpdateComment(owner, repo, commentId, nextBody, 'replace', true);
|
await doUpdateComment(owner, repo, commentId, nextBody, 'replace', true);
|
||||||
} else if (contents) {
|
} else if (contents) {
|
||||||
await doCreateCommentContent(owner, repo, commentId, dealStringToArr(contents));
|
await doCreateCommentContent(owner, repo, commentId, dealStringToArr(contents));
|
||||||
}
|
}
|
||||||
|
|
||||||
const issue = await octokit.issues.get({
|
const issue = await octokit.issues.get({
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
issue_number: issueNumber
|
issue_number: issueNumber
|
||||||
});
|
});
|
||||||
let newLabels = [];
|
let newLabels = [];
|
||||||
if (issue.data.labels.length > 0) {
|
if (issue.data.labels.length > 0) {
|
||||||
newLabels = issue.data.labels.map(({ name }) => name).filter(name => !dealStringToArr(removeLables).includes(name));
|
newLabels = issue.data.labels.map(({ name }) => name).filter(name => !dealStringToArr(removeLables).includes(name));
|
||||||
}
|
}
|
||||||
if (duplicateLabels) {
|
if (duplicateLabels) {
|
||||||
newLabels = [...newLabels, ...dealStringToArr(duplicateLabels)];
|
newLabels = [...newLabels, ...dealStringToArr(duplicateLabels)];
|
||||||
}
|
}
|
||||||
if (labels) {
|
if (labels) {
|
||||||
newLabels = dealStringToArr(labels);
|
newLabels = dealStringToArr(labels);
|
||||||
}
|
}
|
||||||
if (newLabels.length > 0) {
|
if (newLabels.length > 0) {
|
||||||
await doSetLabels(owner, repo, issueNumber, newLabels.toString());
|
await doSetLabels(owner, repo, issueNumber, newLabels.toString());
|
||||||
core.info(`Actions: [mark-duplicate-labels][${newLabels}] success!`);
|
core.info(`Actions: [mark-duplicate-labels][${newLabels}] success!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (closeIssue == 'true') {
|
if (closeIssue == 'true') {
|
||||||
await doCloseIssue(owner, repo, issueNumber);
|
await doCloseIssue(owner, repo, issueNumber);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
core.info(`This comment body should start whith 'duplicate-command' or 'Duplicate of' and not include '?'`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
core.info(`This comment body should start whith 'duplicate-command' or 'Duplicate of' and not include '?'`);
|
core.info(`This actions only support on 'issue_comment' created or edited!`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -234,14 +234,14 @@ jobs:
|
|||||||
|
|
||||||
## `mark-duplicate`
|
## `mark-duplicate`
|
||||||
|
|
||||||
Quickly mark duplicate questions, only for issue new comments.
|
Quickly mark duplicate questions, only for issue new comments or edit comments.
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
name: Issue Mark Duplicate
|
name: Issue Mark Duplicate
|
||||||
|
|
||||||
on:
|
on:
|
||||||
issue_comment:
|
issue_comment:
|
||||||
types: [created]
|
types: [created, edited]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
mark-duplicate:
|
mark-duplicate:
|
||||||
|
@@ -234,14 +234,14 @@ jobs:
|
|||||||
|
|
||||||
## `mark-duplicate`
|
## `mark-duplicate`
|
||||||
|
|
||||||
快捷标记重复问题,仅作用于 issue 新增评论。
|
快捷标记重复问题,仅作用于 issue 新增编辑评论。
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
name: Issue Mark Duplicate
|
name: Issue Mark Duplicate
|
||||||
|
|
||||||
on:
|
on:
|
||||||
issue_comment:
|
issue_comment:
|
||||||
types: [created]
|
types: [created, edited]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
mark-duplicate:
|
mark-duplicate:
|
||||||
|
82
src/base.js
82
src/base.js
@@ -155,55 +155,55 @@ async function doMarkDuplicate (owner, repo, labels) {
|
|||||||
core.info(`This actions only support on 'issue_comment'!`);
|
core.info(`This actions only support on 'issue_comment'!`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (context.payload.action != 'created') {
|
|
||||||
core.info(`This actions only support on 'issue_comment' created!`);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const duplicateCommand = core.getInput("duplicate-command");
|
if (context.payload.action == 'created' || context.payload.action == 'edited') {
|
||||||
const duplicateLabels = core.getInput("duplicate-labels");
|
const duplicateCommand = core.getInput("duplicate-command");
|
||||||
const removeLables = core.getInput("remove-labels");
|
const duplicateLabels = core.getInput("duplicate-labels");
|
||||||
const closeIssue = core.getInput("close-issue");
|
const removeLables = core.getInput("remove-labels");
|
||||||
|
const closeIssue = core.getInput("close-issue");
|
||||||
|
|
||||||
const commentId = context.payload.comment.id;
|
const commentId = context.payload.comment.id;
|
||||||
const commentBody = context.payload.comment.body;
|
const commentBody = context.payload.comment.body;
|
||||||
const issueNumber = context.payload.issue.number;
|
const issueNumber = context.payload.issue.number;
|
||||||
|
|
||||||
const ifCommandInput = !!duplicateCommand;
|
const ifCommandInput = !!duplicateCommand;
|
||||||
|
|
||||||
if (!commentBody.includes('?') && ((ifCommandInput && commentBody.startsWith(duplicateCommand) && commentBody.split(' ')[0] == duplicateCommand) || testDuplicate(commentBody))) {
|
if (!commentBody.includes('?') && ((ifCommandInput && commentBody.startsWith(duplicateCommand) && commentBody.split(' ')[0] == duplicateCommand) || testDuplicate(commentBody))) {
|
||||||
if (ifCommandInput) {
|
if (ifCommandInput) {
|
||||||
const nextBody = commentBody.replace(duplicateCommand, 'Duplicate of');
|
const nextBody = commentBody.replace(duplicateCommand, 'Duplicate of');
|
||||||
await doUpdateComment(owner, repo, commentId, nextBody, 'replace', true);
|
await doUpdateComment(owner, repo, commentId, nextBody, 'replace', true);
|
||||||
} else if (contents) {
|
} else if (contents) {
|
||||||
await doCreateCommentContent(owner, repo, commentId, dealStringToArr(contents));
|
await doCreateCommentContent(owner, repo, commentId, dealStringToArr(contents));
|
||||||
}
|
}
|
||||||
|
|
||||||
const issue = await octokit.issues.get({
|
const issue = await octokit.issues.get({
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
issue_number: issueNumber
|
issue_number: issueNumber
|
||||||
});
|
});
|
||||||
let newLabels = [];
|
let newLabels = [];
|
||||||
if (issue.data.labels.length > 0) {
|
if (issue.data.labels.length > 0) {
|
||||||
newLabels = issue.data.labels.map(({ name }) => name).filter(name => !dealStringToArr(removeLables).includes(name));
|
newLabels = issue.data.labels.map(({ name }) => name).filter(name => !dealStringToArr(removeLables).includes(name));
|
||||||
}
|
}
|
||||||
if (duplicateLabels) {
|
if (duplicateLabels) {
|
||||||
newLabels = [...newLabels, ...dealStringToArr(duplicateLabels)];
|
newLabels = [...newLabels, ...dealStringToArr(duplicateLabels)];
|
||||||
}
|
}
|
||||||
if (labels) {
|
if (labels) {
|
||||||
newLabels = dealStringToArr(labels);
|
newLabels = dealStringToArr(labels);
|
||||||
}
|
}
|
||||||
if (newLabels.length > 0) {
|
if (newLabels.length > 0) {
|
||||||
await doSetLabels(owner, repo, issueNumber, newLabels.toString());
|
await doSetLabels(owner, repo, issueNumber, newLabels.toString());
|
||||||
core.info(`Actions: [mark-duplicate-labels][${newLabels}] success!`);
|
core.info(`Actions: [mark-duplicate-labels][${newLabels}] success!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (closeIssue == 'true') {
|
if (closeIssue == 'true') {
|
||||||
await doCloseIssue(owner, repo, issueNumber);
|
await doCloseIssue(owner, repo, issueNumber);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
core.info(`This comment body should start whith 'duplicate-command' or 'Duplicate of' and not include '?'`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
core.info(`This comment body should start whith 'duplicate-command' or 'Duplicate of' and not include '?'`);
|
core.info(`This actions only support on 'issue_comment' created or edited!`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user