Merge pull request #27 from afwn90cj93201nixr2e1re/multi-reactions

Implemented multi reactions?
This commit is contained in:
Peter Evans 2020-04-17 15:16:21 +09:00 committed by GitHub
commit f93396a2a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 15 deletions

View File

@ -14,18 +14,40 @@ const REACTION_TYPES = [
]; ];
async function addReaction(octokit, repo, comment_id, reactionType) { async function addReaction(octokit, repo, comment_id, reactionType) {
if (REACTION_TYPES.includes(reactionType)) { let ReactionsSet = [...new Set(reactionType.split(', ')
await octokit.reactions.createForIssueComment({ .filter(item => {
owner: repo[0], if(!REACTION_TYPES.includes(item)){
repo: repo[1], core.info(`Skipping invalid 'reaction-type' '${item}'.`);
comment_id: comment_id, return false;
content: reactionType }
}); return true;
core.info(`Set '${reactionType}' reaction on comment.`); }))];
} else {
core.setFailed("Invalid 'reaction-type'."); if(!ReactionsSet){
return; core.setFailed(`Can't find any valid 'reaction-type' in provided value: ${reactionType}.`);
} return false;
}
let results = await Promise.allSettled(ReactionsSet.map(async (item) => {
await octokit.reactions.createForIssueComment({
owner: repo[0],
repo: repo[1],
comment_id: comment_id,
content: item
});
core.info(`Setting '${item}' reaction on comment.`);
}));
for(let i = 0, l = results.length; i<l; i++){
if(results[i].status === 'fulfilled'){
core.info(`Added reaction '${ReactionsSet[i]}' to comment id '${comment_id}'.`);
}
else if(results[i].status === 'rejected'){
core.info(`Adding reaction '${ReactionsSet[i]}' to comment id '${comment_id}' failed with ${results[i].reason}.`);
}
}
ReactionsSet = undefined;
results = undefined;
} }
async function run() { async function run() {
@ -90,7 +112,6 @@ async function run() {
// Set a comment reaction // Set a comment reaction
if (inputs.reactionType) { if (inputs.reactionType) {
await addReaction(octokit, repo, inputs.commentId, inputs.reactionType); await addReaction(octokit, repo, inputs.commentId, inputs.reactionType);
core.info(`Added reaction '${inputs.reactionType}' to comment id '${inputs.commentId}'.`);
} }
} else if (inputs.issueNumber) { } else if (inputs.issueNumber) {
// Create a comment // Create a comment
@ -110,7 +131,6 @@ async function run() {
// Set a comment reaction // Set a comment reaction
if (inputs.reactionType) { if (inputs.reactionType) {
await addReaction(octokit, repo, comment.id, inputs.reactionType); await addReaction(octokit, repo, comment.id, inputs.reactionType);
core.info(`Added reaction '${inputs.reactionType}' to comment id '${comment.id}'.`);
} }
} else { } else {
core.setFailed("Missing either 'issue-number' or 'comment-id'."); core.setFailed("Missing either 'issue-number' or 'comment-id'.");

View File

@ -5,7 +5,7 @@
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"lint": "eslint index.js", "lint": "eslint index.js",
"package": "ncc build index.js -o dist", "package": "ncc build index.js -m -o dist",
"test": "eslint index.js && jest --passWithNoTests" "test": "eslint index.js && jest --passWithNoTests"
}, },
"repository": { "repository": {