mirror of
https://gitea.com/Lydanne/issues-helper.git
synced 2025-08-19 18:25:58 +08:00
feat: add random to (#35)
* feat: add random to * add actions * up * up version * add less
This commit is contained in:
@@ -17,7 +17,7 @@ const {
|
||||
} = require('./public.js');
|
||||
|
||||
const {
|
||||
dealInput,
|
||||
dealStringToArr,
|
||||
matchKeyword,
|
||||
getPreMonth
|
||||
} = require('./util.js');
|
||||
@@ -83,7 +83,7 @@ async function doCheckIssue (owner, repo, issueNumber) {
|
||||
});
|
||||
|
||||
if (!!checkResult && assigneeIncludes) {
|
||||
let assigneesCheck = dealInput(assigneeIncludes);
|
||||
let assigneesCheck = dealStringToArr(assigneeIncludes);
|
||||
let checkAssignee = false;
|
||||
issue.data.assignees.forEach(it => {
|
||||
if (checkResult && !checkAssignee && assigneesCheck.includes(it.login)) {
|
||||
@@ -96,8 +96,8 @@ async function doCheckIssue (owner, repo, issueNumber) {
|
||||
|
||||
if (!!checkResult && titleIncludes) {
|
||||
const titleArr = titleIncludes.split('/');
|
||||
const keyword1 = dealInput(titleArr[0]);
|
||||
const keyword2 = dealInput(titleArr[1]);
|
||||
const keyword1 = dealStringToArr(titleArr[0]);
|
||||
const keyword2 = dealStringToArr(titleArr[1]);
|
||||
checkResult =
|
||||
keyword2.length ?
|
||||
matchKeyword(issue.data.title, keyword1) && matchKeyword(issue.data.title, keyword2) :
|
||||
@@ -106,8 +106,8 @@ async function doCheckIssue (owner, repo, issueNumber) {
|
||||
|
||||
if (!!checkResult && bodyIncludes) {
|
||||
const bodyArr = bodyIncludes.split('/');
|
||||
const keyword1 = dealInput(bodyArr[0]);
|
||||
const keyword2 = dealInput(bodyArr[1]);
|
||||
const keyword1 = dealStringToArr(bodyArr[0]);
|
||||
const keyword2 = dealStringToArr(bodyArr[1]);
|
||||
checkResult =
|
||||
keyword2.length ?
|
||||
matchKeyword(issue.data.body, keyword1) && matchKeyword(issue.data.body, keyword2) :
|
||||
|
38
src/base.js
38
src/base.js
@@ -20,7 +20,8 @@ const {
|
||||
} = require('./public.js');
|
||||
|
||||
const {
|
||||
dealInput,
|
||||
dealStringToArr,
|
||||
dealRandomAssignees,
|
||||
testDuplicate,
|
||||
} = require('./util.js');
|
||||
|
||||
@@ -31,15 +32,18 @@ const context = github.context;
|
||||
|
||||
const contents = core.getInput("contents");
|
||||
|
||||
const randomTo = core.getInput("random-to");
|
||||
|
||||
// **************************************************************************
|
||||
async function doAddAssignees (owner, repo, issueNumber, assignees) {
|
||||
const arr = dealRandomAssignees(assignees, randomTo);
|
||||
await octokit.issues.addAssignees({
|
||||
owner,
|
||||
repo,
|
||||
issue_number: issueNumber,
|
||||
assignees: dealInput(assignees)
|
||||
assignees: arr
|
||||
});
|
||||
core.info(`Actions: [add-assignees][${assignees}] success!`);
|
||||
core.info(`Actions: [add-assignees][${arr}] success!`);
|
||||
};
|
||||
|
||||
async function doAddLabels (owner, repo, issueNumber, labels) {
|
||||
@@ -47,7 +51,7 @@ async function doAddLabels (owner, repo, issueNumber, labels) {
|
||||
owner,
|
||||
repo,
|
||||
issue_number: issueNumber,
|
||||
labels: dealInput(labels)
|
||||
labels: dealStringToArr(labels)
|
||||
});
|
||||
core.info(`Actions: [add-labels][${labels}] success!`);
|
||||
};
|
||||
@@ -73,7 +77,7 @@ async function doCreateComment (owner, repo, issueNumber, body) {
|
||||
core.setOutput("comment-id", data.id);
|
||||
|
||||
if (contents) {
|
||||
await doCreateCommentContent(owner, repo, data.id, dealInput(contents));
|
||||
await doCreateCommentContent(owner, repo, data.id, dealStringToArr(contents));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -99,8 +103,8 @@ async function doCreateIssue (owner, repo, title, body, labels, assignees) {
|
||||
repo,
|
||||
title,
|
||||
body,
|
||||
labels: dealInput(labels),
|
||||
assignees: dealInput(assignees),
|
||||
labels: dealStringToArr(labels),
|
||||
assignees: dealRandomAssignees(assignees, randomTo),
|
||||
};
|
||||
|
||||
const { data } = await octokit.issues.create(params);
|
||||
@@ -108,7 +112,7 @@ async function doCreateIssue (owner, repo, title, body, labels, assignees) {
|
||||
core.setOutput("issue-number", data.number);
|
||||
|
||||
if (contents) {
|
||||
await doCreateIssueContent(owner, repo, data.number, dealInput(contents));
|
||||
await doCreateIssueContent(owner, repo, data.number, dealStringToArr(contents));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -160,7 +164,7 @@ async function doMarkDuplicate (owner, repo, labels) {
|
||||
const duplicateLabels = core.getInput("duplicate-labels");
|
||||
const removeLables = core.getInput("remove-labels");
|
||||
const closeIssue = core.getInput("close-issue");
|
||||
|
||||
|
||||
const commentId = context.payload.comment.id;
|
||||
const commentBody = context.payload.comment.body;
|
||||
const issueNumber = context.payload.issue.number;
|
||||
@@ -172,7 +176,7 @@ async function doMarkDuplicate (owner, repo, labels) {
|
||||
const nextBody = commentBody.replace(duplicateCommand, 'Duplicate of');
|
||||
await doUpdateComment(owner, repo, commentId, nextBody, 'replace', true);
|
||||
} else if (contents) {
|
||||
await doCreateCommentContent(owner, repo, commentId, dealInput(contents));
|
||||
await doCreateCommentContent(owner, repo, commentId, dealStringToArr(contents));
|
||||
}
|
||||
if (duplicateLabels) {
|
||||
await doAddLabels(owner, repo, issueNumber, duplicateLabels);
|
||||
@@ -206,7 +210,7 @@ async function doRemoveAssignees (owner, repo, issueNumber, assignees) {
|
||||
owner,
|
||||
repo,
|
||||
issue_number: issueNumber,
|
||||
assignees: dealInput(assignees),
|
||||
assignees: dealStringToArr(assignees)
|
||||
});
|
||||
core.info(`Actions: [remove-assignees][${assignees}] success!`);
|
||||
};
|
||||
@@ -217,7 +221,7 @@ async function doRemoveLabels (owner, repo, issueNumber, labels) {
|
||||
repo,
|
||||
issue_number: issueNumber
|
||||
});
|
||||
const dealLabels = dealInput(labels);
|
||||
const dealLabels = dealStringToArr(labels);
|
||||
let addLables = [];
|
||||
if (dealLabels.length) {
|
||||
issue.data.labels.forEach(item => {
|
||||
@@ -238,7 +242,7 @@ async function doSetLabels (owner, repo, issueNumber, labels) {
|
||||
owner,
|
||||
repo,
|
||||
issue_number: issueNumber,
|
||||
labels: dealInput(labels)
|
||||
labels: dealStringToArr(labels)
|
||||
});
|
||||
core.info(`Actions: [set-labels][${labels}] success!`);
|
||||
};
|
||||
@@ -285,7 +289,7 @@ async function doUpdateComment (
|
||||
}
|
||||
|
||||
if (contents) {
|
||||
await doCreateCommentContent(owner, repo, commentId, dealInput(contents));
|
||||
await doCreateCommentContent(owner, repo, commentId, dealStringToArr(contents));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -343,8 +347,8 @@ async function doUpdateIssue (
|
||||
}
|
||||
params.body = next_body;
|
||||
|
||||
params.labels = labels ? dealInput(labels) : issue_labels;
|
||||
params.assignees = assignees ? dealInput(assignees) : issue_assignees;
|
||||
params.labels = labels ? dealStringToArr(labels) : issue_labels;
|
||||
params.assignees = assignees ? dealStringToArr(assignees) : issue_assignees;
|
||||
|
||||
await octokit.issues.update(params);
|
||||
core.info(`Actions: [update-issue][${issueNumber}] success!`);
|
||||
@@ -381,7 +385,7 @@ async function doWelcome (owner, repo, assignees, labels, body) {
|
||||
}
|
||||
|
||||
if (issueContents) {
|
||||
await doCreateIssueContent(owner, repo, issueNumber, dealInput(issueContents));
|
||||
await doCreateIssueContent(owner, repo, issueNumber, dealStringToArr(issueContents));
|
||||
}
|
||||
} else {
|
||||
core.info(`Actions: [welcome][${auth}] is not first time!`);
|
||||
|
@@ -97,4 +97,10 @@
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.__dumi-default-menu + .__dumi-default-layout-content {
|
||||
tbody tr:hover {
|
||||
background: #fafafa;
|
||||
}
|
||||
}
|
||||
|
15
src/util.js
15
src/util.js
@@ -1,4 +1,6 @@
|
||||
function dealInput (para) {
|
||||
const sampleSize = require('lodash/sampleSize');
|
||||
|
||||
function dealStringToArr (para) {
|
||||
/**
|
||||
* in 'x1,x2,x3'
|
||||
* out ['x1','x2','x3']
|
||||
@@ -15,6 +17,14 @@ function dealInput (para) {
|
||||
return arr;
|
||||
};
|
||||
|
||||
function dealRandomAssignees (assignees, randomTo) {
|
||||
let arr = dealStringToArr(assignees);
|
||||
if (randomTo && Number(randomTo) > 0 && Number(randomTo) < arr.length) {
|
||||
arr = sampleSize(arr, randomTo);
|
||||
}
|
||||
return arr;
|
||||
};
|
||||
|
||||
function matchKeyword (content, keywords) {
|
||||
return keywords.find(item => content.toLowerCase().includes(item));
|
||||
};
|
||||
@@ -37,7 +47,8 @@ function getPreMonth (m) {
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
dealInput,
|
||||
dealStringToArr,
|
||||
dealRandomAssignees,
|
||||
getPreMonth,
|
||||
matchKeyword,
|
||||
testDuplicate,
|
||||
|
Reference in New Issue
Block a user