chore: add catch (#59)

* chore: add catch

* format
This commit is contained in:
xrkffgg
2021-02-03 09:28:14 +08:00
committed by GitHub
parent 65461c17ed
commit f743eedacb
2 changed files with 86 additions and 79 deletions

83
dist/index.js vendored
View File

@@ -8060,49 +8060,52 @@ async function doMarkDuplicate(owner, repo, labels) {
commentBody.split(' ')[0] == duplicateCommand) || commentBody.split(' ')[0] == duplicateCommand) ||
testDuplicate(commentBody)) testDuplicate(commentBody))
) { ) {
try {
const res = await octokit.repos.getCollaboratorPermissionLevel({
owner,
repo,
username: commentUser,
});
const { permission } = res.data;
if (!checkPermission(requirePermission, permission)) {
core.info(`The user ${commentUser} is not allow!`);
return false;
}
const res = await octokit.repos.getCollaboratorPermissionLevel({ if (ifCommandInput) {
owner, const nextBody = commentBody.replace(duplicateCommand, 'Duplicate of');
repo, await doUpdateComment(owner, repo, commentId, nextBody, 'replace', true);
username: commentUser, } else if (contents) {
}); await doCreateCommentContent(owner, repo, commentId, dealStringToArr(contents));
const { permission } = res.data; }
if (!checkPermission(requirePermission, permission)) {
core.info(`The user ${commentUser} is not allow!`);
return false;
}
if (ifCommandInput) { const issue = await octokit.issues.get({
const nextBody = commentBody.replace(duplicateCommand, 'Duplicate of'); owner,
await doUpdateComment(owner, repo, commentId, nextBody, 'replace', true); repo,
} else if (contents) { issue_number: issueNumber,
await doCreateCommentContent(owner, repo, commentId, dealStringToArr(contents)); });
} let newLabels = [];
if (issue.data.labels.length > 0) {
newLabels = issue.data.labels
.map(({ name }) => name)
.filter(name => !dealStringToArr(removeLables).includes(name));
}
if (duplicateLabels) {
newLabels = [...newLabels, ...dealStringToArr(duplicateLabels)];
}
if (labels) {
newLabels = dealStringToArr(labels);
}
if (newLabels.length > 0) {
await doSetLabels(owner, repo, issueNumber, newLabels.toString());
core.info(`Actions: [mark-duplicate-labels][${newLabels}] success!`);
}
const issue = await octokit.issues.get({ if (closeIssue == 'true') {
owner, await doCloseIssue(owner, repo, issueNumber);
repo, }
issue_number: issueNumber, } catch (error) {
}); core.info(error.message);
let newLabels = [];
if (issue.data.labels.length > 0) {
newLabels = issue.data.labels
.map(({ name }) => name)
.filter(name => !dealStringToArr(removeLables).includes(name));
}
if (duplicateLabels) {
newLabels = [...newLabels, ...dealStringToArr(duplicateLabels)];
}
if (labels) {
newLabels = dealStringToArr(labels);
}
if (newLabels.length > 0) {
await doSetLabels(owner, repo, issueNumber, newLabels.toString());
core.info(`Actions: [mark-duplicate-labels][${newLabels}] success!`);
}
if (closeIssue == 'true') {
await doCloseIssue(owner, repo, issueNumber);
} }
} else { } else {
core.info( core.info(

View File

@@ -197,48 +197,52 @@ async function doMarkDuplicate(owner, repo, labels) {
commentBody.split(' ')[0] == duplicateCommand) || commentBody.split(' ')[0] == duplicateCommand) ||
testDuplicate(commentBody)) testDuplicate(commentBody))
) { ) {
const res = await octokit.repos.getCollaboratorPermissionLevel({ try {
owner, const res = await octokit.repos.getCollaboratorPermissionLevel({
repo, owner,
username: commentUser, repo,
}); username: commentUser,
const { permission } = res.data; });
if (!checkPermission(requirePermission, permission)) { const { permission } = res.data;
core.info(`The user ${commentUser} is not allow!`); if (!checkPermission(requirePermission, permission)) {
return false; core.info(`The user ${commentUser} is not allow!`);
} return false;
}
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 newLabels = issue.data.labels
.map(({ name }) => name) .map(({ name }) => name)
.filter(name => !dealStringToArr(removeLables).includes(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);
}
} catch (error) {
core.info(error.message);
} }
} else { } else {
core.info( core.info(