mirror of
https://gitea.com/Lydanne/issues-helper.git
synced 2025-08-19 18:25:58 +08:00
feat: add check-issue & remove labels (#12)
This commit is contained in:
104
dist/index.js
vendored
104
dist/index.js
vendored
@@ -5996,6 +5996,8 @@ const {
|
||||
doLockIssue
|
||||
} = __webpack_require__(9932);
|
||||
|
||||
const { dealInput, matchKeyword } = __webpack_require__(6254);
|
||||
|
||||
const token = core.getInput('token');
|
||||
const octokit = new Octokit({ auth: `token ${token}` });
|
||||
|
||||
@@ -6005,6 +6007,7 @@ direction = direction === 'desc' ? 'desc' : 'asc';
|
||||
const commentAuth = core.getInput("comment-auth");
|
||||
const bodyIncludes = core.getInput('body-includes');
|
||||
const titleIncludes = core.getInput('title-includes');
|
||||
const assigneeIncludes = core.getInput('assignee-includes');
|
||||
|
||||
const issueCreator = core.getInput("issue-creator");
|
||||
const issueAssignee = core.getInput('issue-assignee');
|
||||
@@ -6038,6 +6041,55 @@ async function doCheckInactive (owner, repo, labels) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 检查 issue 是否满足条件,满足返回 true
|
||||
* 当前 issue 的指定人是否有一个满足 assigneeIncludes 里的某个
|
||||
* 关键字匹配,是否包含前一个某个+后一个某个 '官网,网站/挂了,无法访问'
|
||||
*/
|
||||
async function doCheckIssue (owner, repo, issueNumber) {
|
||||
var checkResult = true;
|
||||
const issue = await octokit.issues.get({
|
||||
owner,
|
||||
repo,
|
||||
issue_number: issueNumber
|
||||
});
|
||||
|
||||
if (!!checkResult && assigneeIncludes) {
|
||||
let assigneesCheck = dealInput(assigneeIncludes);
|
||||
let checkAssignee = false;
|
||||
issue.data.assignees.forEach(it => {
|
||||
if (checkResult && !checkAssignee && assigneesCheck.includes(it.login)) {
|
||||
checkResult = true;
|
||||
checkAssignee = true;
|
||||
}
|
||||
})
|
||||
!checkAssignee ? checkResult = false : null;
|
||||
}
|
||||
|
||||
if (!!checkResult && titleIncludes) {
|
||||
const titleArr = titleIncludes.split('/');
|
||||
const keyword1 = dealInput(titleArr[0]);
|
||||
const keyword2 = dealInput(titleArr[1]);
|
||||
checkResult =
|
||||
keyword2.length ?
|
||||
matchKeyword(issue.data.title, keyword1) && matchKeyword(issue.data.title, keyword2) :
|
||||
matchKeyword(issue.data.title, keyword1);
|
||||
}
|
||||
|
||||
if (!!checkResult && bodyIncludes) {
|
||||
const bodyArr = bodyIncludes.split('/');
|
||||
const keyword1 = dealInput(bodyArr[0]);
|
||||
const keyword2 = dealInput(bodyArr[1]);
|
||||
checkResult =
|
||||
keyword2.length ?
|
||||
matchKeyword(issue.data.body, keyword1) && matchKeyword(issue.data.body, keyword2) :
|
||||
matchKeyword(issue.data.body, keyword1);
|
||||
console.log(!!checkResult)
|
||||
}
|
||||
core.info(`Actions: [check-issue][${!!checkResult}] success!`);
|
||||
core.setOutput("check-result", !!checkResult);
|
||||
};
|
||||
|
||||
async function doCloseIssues (owner, repo, labels) {
|
||||
const issues = await doQueryIssues(owner, repo, labels, 'open');
|
||||
|
||||
@@ -6115,7 +6167,12 @@ async function doQueryIssues (owner, repo, labels, state) {
|
||||
res.data.forEach(iss => {
|
||||
const a = bodyIncludes ? iss.body.includes(bodyIncludes) : true;
|
||||
const b = titleIncludes ? iss.title.includes(titleIncludes) : true;
|
||||
if (a && b) {
|
||||
/**
|
||||
* Note: GitHub's REST API v3 considers every pull request an issue, but not every issue is a pull request.
|
||||
* For this reason, "Issues" endpoints may return both issues and pull requests in the response.
|
||||
* You can identify pull requests by the pull_request key.
|
||||
*/
|
||||
if (a && b && iss.pull_request === undefined) {
|
||||
if (inactiveDay && typeof(inactiveDay) === 'number') {
|
||||
let lastTime = dayjs.utc().subtract(inactiveDay, 'day');
|
||||
let updateTime = dayjs.utc(iss.updated_at);
|
||||
@@ -6133,6 +6190,7 @@ async function doQueryIssues (owner, repo, labels, state) {
|
||||
|
||||
module.exports = {
|
||||
doCheckInactive,
|
||||
doCheckIssue,
|
||||
doCloseIssues,
|
||||
doFindComments,
|
||||
doLockIssues,
|
||||
@@ -6300,6 +6358,28 @@ async function doRemoveAssignees (owner, repo, issueNumber, assignees) {
|
||||
core.info(`Actions: [remove-assignees][${assignees}] success!`);
|
||||
};
|
||||
|
||||
async function doRemoveLabels (owner, repo, issueNumber, labels) {
|
||||
const issue = await octokit.issues.get({
|
||||
owner,
|
||||
repo,
|
||||
issue_number: issueNumber
|
||||
});
|
||||
const dealLabels = dealInput(labels);
|
||||
let addLables = [];
|
||||
if (dealLabels.length) {
|
||||
issue.data.labels.forEach(item => {
|
||||
!dealLabels.includes(item.name) ? addLables.push(item.name) : '';
|
||||
})
|
||||
await octokit.issues.setLabels({
|
||||
owner,
|
||||
repo,
|
||||
issue_number: issueNumber,
|
||||
labels: addLables
|
||||
});
|
||||
core.info(`Actions: [remove-labels][${labels}] success!`);
|
||||
}
|
||||
};
|
||||
|
||||
async function doSetLabels (owner, repo, issueNumber, labels) {
|
||||
await octokit.issues.setLabels({
|
||||
owner,
|
||||
@@ -6348,7 +6428,7 @@ async function doUpdateComment (
|
||||
|
||||
await octokit.issues.updateComment(params);
|
||||
core.info(`Actions: [update-comment][${commentId}] success!`);
|
||||
}
|
||||
}
|
||||
|
||||
if (contents) {
|
||||
await doCreateCommentContent(owner, repo, commentId, dealInput(contents));
|
||||
@@ -6443,6 +6523,7 @@ module.exports = {
|
||||
doLockIssue,
|
||||
doOpenIssue,
|
||||
doRemoveAssignees,
|
||||
doRemoveLabels,
|
||||
doSetLabels,
|
||||
doUnlockIssue,
|
||||
doUpdateComment,
|
||||
@@ -6470,6 +6551,7 @@ const {
|
||||
doLockIssue,
|
||||
doOpenIssue,
|
||||
doRemoveAssignees,
|
||||
doRemoveLabels,
|
||||
doSetLabels,
|
||||
doUnlockIssue,
|
||||
doUpdateComment,
|
||||
@@ -6478,6 +6560,7 @@ const {
|
||||
|
||||
const {
|
||||
doCheckInactive,
|
||||
doCheckIssue,
|
||||
doCloseIssues,
|
||||
doFindComments,
|
||||
doLockIssues,
|
||||
@@ -6494,6 +6577,7 @@ const ALLACTIONS = [
|
||||
'lock-issue',
|
||||
'open-issue',
|
||||
'remove-assignees',
|
||||
'remove-labels',
|
||||
'set-labels',
|
||||
'unlock-issue',
|
||||
'update-comment',
|
||||
@@ -6501,6 +6585,7 @@ const ALLACTIONS = [
|
||||
|
||||
// advanced
|
||||
'check-inactive',
|
||||
'check-issue',
|
||||
'close-issues',
|
||||
'find-comments',
|
||||
'lock-issues',
|
||||
@@ -6574,6 +6659,9 @@ async function main() {
|
||||
case 'remove-assignees':
|
||||
await doRemoveAssignees(owner, repo, issueNumber, assignees);
|
||||
break;
|
||||
case 'remove-labels':
|
||||
await doRemoveLabels(owner, repo, issueNumber, labels);
|
||||
break;
|
||||
case 'set-labels':
|
||||
await doSetLabels(owner, repo, issueNumber, labels);
|
||||
break;
|
||||
@@ -6611,6 +6699,13 @@ async function main() {
|
||||
labels
|
||||
)
|
||||
break;
|
||||
case 'check-issue':
|
||||
await doCheckIssue(
|
||||
owner,
|
||||
repo,
|
||||
issueNumber
|
||||
);
|
||||
break;
|
||||
case 'close-issues':
|
||||
await doCloseIssues(
|
||||
owner,
|
||||
@@ -6664,8 +6759,13 @@ function dealInput (para) {
|
||||
return arr;
|
||||
};
|
||||
|
||||
function matchKeyword(content, keywords) {
|
||||
return keywords.find(item => content.toLowerCase().includes(item));
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
dealInput,
|
||||
matchKeyword,
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user