mirror of
https://github.com/peter-evans/create-or-update-comment.git
synced 2025-02-24 05:40:11 +08:00
Implemented multi reactions?
This commit is contained in:
parent
9f320992d5
commit
38027e8dbe
36
index.js
36
index.js
@ -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(', ')
|
||||||
|
.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({
|
await octokit.reactions.createForIssueComment({
|
||||||
owner: repo[0],
|
owner: repo[0],
|
||||||
repo: repo[1],
|
repo: repo[1],
|
||||||
comment_id: comment_id,
|
comment_id: comment_id,
|
||||||
content: reactionType
|
content: item
|
||||||
});
|
});
|
||||||
core.info(`Set '${reactionType}' reaction on comment.`);
|
core.info(`Setting '${item}' reaction on comment.`);
|
||||||
} else {
|
}));
|
||||||
core.setFailed("Invalid 'reaction-type'.");
|
|
||||||
return;
|
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'.");
|
||||||
|
@ -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": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user