mirror of
https://github.com/peter-evans/create-or-update-comment.git
synced 2025-02-23 21:30:10 +08:00
Merge pull request #27 from afwn90cj93201nixr2e1re/multi-reactions
Implemented multi reactions?
This commit is contained in:
commit
f93396a2a5
36
index.js
36
index.js
@ -14,18 +14,40 @@ const REACTION_TYPES = [
|
||||
];
|
||||
|
||||
async function addReaction(octokit, repo, comment_id, reactionType) {
|
||||
if (REACTION_TYPES.includes(reactionType)) {
|
||||
let ReactionsSet = [...new Set(reactionType.split(', ')
|
||||
.filter(item => {
|
||||
if(!REACTION_TYPES.includes(item)){
|
||||
core.info(`Skipping invalid 'reaction-type' '${item}'.`);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}))];
|
||||
|
||||
if(!ReactionsSet){
|
||||
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: reactionType
|
||||
content: item
|
||||
});
|
||||
core.info(`Set '${reactionType}' reaction on comment.`);
|
||||
} else {
|
||||
core.setFailed("Invalid 'reaction-type'.");
|
||||
return;
|
||||
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() {
|
||||
@ -90,7 +112,6 @@ async function run() {
|
||||
// Set a comment reaction
|
||||
if (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) {
|
||||
// Create a comment
|
||||
@ -110,7 +131,6 @@ async function run() {
|
||||
// Set a comment reaction
|
||||
if (inputs.reactionType) {
|
||||
await addReaction(octokit, repo, comment.id, inputs.reactionType);
|
||||
core.info(`Added reaction '${inputs.reactionType}' to comment id '${comment.id}'.`);
|
||||
}
|
||||
} else {
|
||||
core.setFailed("Missing either 'issue-number' or 'comment-id'.");
|
||||
|
@ -5,7 +5,7 @@
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"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"
|
||||
},
|
||||
"repository": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user