mirror of
https://github.com/peter-evans/create-or-update-comment.git
synced 2025-01-31 11:46:44 +08:00
Deprecate reaction-type in favour of reactions
This commit is contained in:
parent
f93396a2a5
commit
5005703541
14
README.md
14
README.md
@ -20,7 +20,7 @@ This action was created to help facilitate a GitHub Actions "ChatOps" solution i
|
|||||||
- Created by [create-or-update-comment][1]
|
- Created by [create-or-update-comment][1]
|
||||||
|
|
||||||
[1]: https://github.com/peter-evans/create-or-update-comment
|
[1]: https://github.com/peter-evans/create-or-update-comment
|
||||||
reaction-type: '+1'
|
reactions: '+1'
|
||||||
```
|
```
|
||||||
|
|
||||||
### Update a comment
|
### Update a comment
|
||||||
@ -32,17 +32,17 @@ This action was created to help facilitate a GitHub Actions "ChatOps" solution i
|
|||||||
comment-id: 557858210
|
comment-id: 557858210
|
||||||
body: |
|
body: |
|
||||||
**Edit:** Some additional info
|
**Edit:** Some additional info
|
||||||
reaction-type: eyes
|
reactions: eyes
|
||||||
```
|
```
|
||||||
|
|
||||||
### Add a comment reaction
|
### Add comment reactions
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
- name: Add reaction
|
- name: Add reactions
|
||||||
uses: peter-evans/create-or-update-comment@v1
|
uses: peter-evans/create-or-update-comment@v1
|
||||||
with:
|
with:
|
||||||
comment-id: 557858210
|
comment-id: 557858210
|
||||||
reaction-type: heart
|
reactions: heart, hooray, laugh
|
||||||
```
|
```
|
||||||
|
|
||||||
### Action inputs
|
### Action inputs
|
||||||
@ -55,7 +55,7 @@ This action was created to help facilitate a GitHub Actions "ChatOps" solution i
|
|||||||
| `comment-id` | The id of the comment to update. | |
|
| `comment-id` | The id of the comment to update. | |
|
||||||
| `body` | The comment body. | |
|
| `body` | The comment body. | |
|
||||||
| `edit-mode` | The mode when updating a comment, `replace` or `append`. | `append` |
|
| `edit-mode` | The mode when updating a comment, `replace` or `append`. | `append` |
|
||||||
| `reaction-type` | The reaction to add to the comment. (`+1`, `-1`, `laugh`, `confused`, `heart`, `hooray`, `rocket`, `eyes`) | |
|
| `reactions` | A comma separated list of reactions to add to the comment. (`+1`, `-1`, `laugh`, `confused`, `heart`, `hooray`, `rocket`, `eyes`) | |
|
||||||
|
|
||||||
#### Outputs
|
#### Outputs
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ jobs:
|
|||||||
uses: peter-evans/create-or-update-comment@v1
|
uses: peter-evans/create-or-update-comment@v1
|
||||||
with:
|
with:
|
||||||
comment-id: ${{ github.event.comment.id }}
|
comment-id: ${{ github.event.comment.id }}
|
||||||
reaction-type: eyes
|
reactions: eyes
|
||||||
```
|
```
|
||||||
|
|
||||||
### Accessing issues and comments in other repositories
|
### Accessing issues and comments in other repositories
|
||||||
|
@ -15,7 +15,9 @@ inputs:
|
|||||||
edit-mode:
|
edit-mode:
|
||||||
description: 'The mode when updating a comment, "replace" or "append".'
|
description: 'The mode when updating a comment, "replace" or "append".'
|
||||||
reaction-type:
|
reaction-type:
|
||||||
description: 'The reaction to add to the comment.'
|
description: 'Deprecated in favour of `reactions`'
|
||||||
|
reactions:
|
||||||
|
description: 'A comma separated list of reactions to add to the comment.'
|
||||||
outputs:
|
outputs:
|
||||||
comment-id:
|
comment-id:
|
||||||
description: 'The id of the created comment'
|
description: 'The id of the created comment'
|
||||||
|
87
dist/index.js
vendored
87
dist/index.js
vendored
@ -506,23 +506,58 @@ const REACTION_TYPES = [
|
|||||||
"heart",
|
"heart",
|
||||||
"hooray",
|
"hooray",
|
||||||
"rocket",
|
"rocket",
|
||||||
"eyes"
|
"eyes",
|
||||||
];
|
];
|
||||||
|
|
||||||
async function addReaction(octokit, repo, comment_id, reactionType) {
|
async function addReactions(octokit, repo, comment_id, reactions) {
|
||||||
if (REACTION_TYPES.includes(reactionType)) {
|
let ReactionsSet = [
|
||||||
|
...new Set(
|
||||||
|
reactions
|
||||||
|
.replace(/\s/g, "")
|
||||||
|
.split(",")
|
||||||
|
.filter((item) => {
|
||||||
|
if (!REACTION_TYPES.includes(item)) {
|
||||||
|
core.info(`Skipping invalid reaction '${item}'.`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!ReactionsSet) {
|
||||||
|
core.setFailed(
|
||||||
|
`No valid reactions are contained in '${reactions}'.`
|
||||||
|
);
|
||||||
|
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() {
|
||||||
try {
|
try {
|
||||||
@ -533,7 +568,9 @@ async function run() {
|
|||||||
commentId: core.getInput("comment-id"),
|
commentId: core.getInput("comment-id"),
|
||||||
body: core.getInput("body"),
|
body: core.getInput("body"),
|
||||||
editMode: core.getInput("edit-mode"),
|
editMode: core.getInput("edit-mode"),
|
||||||
reactionType: core.getInput("reaction-type")
|
reactions: core.getInput("reactions")
|
||||||
|
? core.getInput("reactions")
|
||||||
|
: core.getInput("reaction-type"),
|
||||||
};
|
};
|
||||||
core.debug(`Inputs: ${inspect(inputs)}`);
|
core.debug(`Inputs: ${inspect(inputs)}`);
|
||||||
|
|
||||||
@ -554,8 +591,8 @@ async function run() {
|
|||||||
|
|
||||||
if (inputs.commentId) {
|
if (inputs.commentId) {
|
||||||
// Edit a comment
|
// Edit a comment
|
||||||
if (!inputs.body && !inputs.reactionType) {
|
if (!inputs.body && !inputs.reactions) {
|
||||||
core.setFailed("Missing either comment 'body' or 'reaction-type'.");
|
core.setFailed("Missing either comment 'body' or 'reactions'.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -566,7 +603,7 @@ async function run() {
|
|||||||
const { data: comment } = await octokit.issues.getComment({
|
const { data: comment } = await octokit.issues.getComment({
|
||||||
owner: repo[0],
|
owner: repo[0],
|
||||||
repo: repo[1],
|
repo: repo[1],
|
||||||
comment_id: inputs.commentId
|
comment_id: inputs.commentId,
|
||||||
});
|
});
|
||||||
commentBody = comment.body + "\n";
|
commentBody = comment.body + "\n";
|
||||||
}
|
}
|
||||||
@ -577,16 +614,15 @@ async function run() {
|
|||||||
owner: repo[0],
|
owner: repo[0],
|
||||||
repo: repo[1],
|
repo: repo[1],
|
||||||
comment_id: inputs.commentId,
|
comment_id: inputs.commentId,
|
||||||
body: commentBody
|
body: commentBody,
|
||||||
});
|
});
|
||||||
core.info(`Updated comment id '${inputs.commentId}'.`);
|
core.info(`Updated comment id '${inputs.commentId}'.`);
|
||||||
core.setOutput('comment-id', inputs.commentId);
|
core.setOutput("comment-id", inputs.commentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set a comment reaction
|
// Set comment reactions
|
||||||
if (inputs.reactionType) {
|
if (inputs.reactions) {
|
||||||
await addReaction(octokit, repo, inputs.commentId, inputs.reactionType);
|
await addReactions(octokit, repo, inputs.commentId, inputs.reactions);
|
||||||
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
|
||||||
@ -598,15 +634,16 @@ async function run() {
|
|||||||
owner: repo[0],
|
owner: repo[0],
|
||||||
repo: repo[1],
|
repo: repo[1],
|
||||||
issue_number: inputs.issueNumber,
|
issue_number: inputs.issueNumber,
|
||||||
body: inputs.body
|
body: inputs.body,
|
||||||
});
|
});
|
||||||
core.info(`Created comment id '${comment.id}' on issue '${inputs.issueNumber}'.`);
|
core.info(
|
||||||
core.setOutput('comment-id', comment.id);
|
`Created comment id '${comment.id}' on issue '${inputs.issueNumber}'.`
|
||||||
|
);
|
||||||
|
core.setOutput("comment-id", comment.id);
|
||||||
|
|
||||||
// Set a comment reaction
|
// Set comment reactions
|
||||||
if (inputs.reactionType) {
|
if (inputs.reactions) {
|
||||||
await addReaction(octokit, repo, comment.id, inputs.reactionType);
|
await addReactions(octokit, repo, comment.id, inputs.reactions);
|
||||||
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'.");
|
||||||
|
77
index.js
77
index.js
@ -10,40 +10,53 @@ const REACTION_TYPES = [
|
|||||||
"heart",
|
"heart",
|
||||||
"hooray",
|
"hooray",
|
||||||
"rocket",
|
"rocket",
|
||||||
"eyes"
|
"eyes",
|
||||||
];
|
];
|
||||||
|
|
||||||
async function addReaction(octokit, repo, comment_id, reactionType) {
|
async function addReactions(octokit, repo, comment_id, reactions) {
|
||||||
let ReactionsSet = [...new Set(reactionType.split(', ')
|
let ReactionsSet = [
|
||||||
.filter(item => {
|
...new Set(
|
||||||
|
reactions
|
||||||
|
.replace(/\s/g, "")
|
||||||
|
.split(",")
|
||||||
|
.filter((item) => {
|
||||||
if (!REACTION_TYPES.includes(item)) {
|
if (!REACTION_TYPES.includes(item)) {
|
||||||
core.info(`Skipping invalid 'reaction-type' '${item}'.`);
|
core.info(`Skipping invalid reaction '${item}'.`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}))];
|
})
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
if (!ReactionsSet) {
|
if (!ReactionsSet) {
|
||||||
core.setFailed(`Can't find any valid 'reaction-type' in provided value: ${reactionType}.`);
|
core.setFailed(
|
||||||
|
`No valid reactions are contained in '${reactions}'.`
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let results = await Promise.allSettled(ReactionsSet.map(async (item) => {
|
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: item
|
content: item,
|
||||||
});
|
});
|
||||||
core.info(`Setting '${item}' reaction on comment.`);
|
core.info(`Setting '${item}' reaction on comment.`);
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
|
|
||||||
for (let i = 0, l = results.length; i < l; i++) {
|
for (let i = 0, l = results.length; i < l; i++) {
|
||||||
if(results[i].status === 'fulfilled'){
|
if (results[i].status === "fulfilled") {
|
||||||
core.info(`Added reaction '${ReactionsSet[i]}' to comment id '${comment_id}'.`);
|
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}.`);
|
} else if (results[i].status === "rejected") {
|
||||||
|
core.info(
|
||||||
|
`Adding reaction '${ReactionsSet[i]}' to comment id '${comment_id}' failed with ${results[i].reason}.`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ReactionsSet = undefined;
|
ReactionsSet = undefined;
|
||||||
@ -59,7 +72,9 @@ async function run() {
|
|||||||
commentId: core.getInput("comment-id"),
|
commentId: core.getInput("comment-id"),
|
||||||
body: core.getInput("body"),
|
body: core.getInput("body"),
|
||||||
editMode: core.getInput("edit-mode"),
|
editMode: core.getInput("edit-mode"),
|
||||||
reactionType: core.getInput("reaction-type")
|
reactions: core.getInput("reactions")
|
||||||
|
? core.getInput("reactions")
|
||||||
|
: core.getInput("reaction-type"),
|
||||||
};
|
};
|
||||||
core.debug(`Inputs: ${inspect(inputs)}`);
|
core.debug(`Inputs: ${inspect(inputs)}`);
|
||||||
|
|
||||||
@ -80,8 +95,8 @@ async function run() {
|
|||||||
|
|
||||||
if (inputs.commentId) {
|
if (inputs.commentId) {
|
||||||
// Edit a comment
|
// Edit a comment
|
||||||
if (!inputs.body && !inputs.reactionType) {
|
if (!inputs.body && !inputs.reactions) {
|
||||||
core.setFailed("Missing either comment 'body' or 'reaction-type'.");
|
core.setFailed("Missing either comment 'body' or 'reactions'.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +107,7 @@ async function run() {
|
|||||||
const { data: comment } = await octokit.issues.getComment({
|
const { data: comment } = await octokit.issues.getComment({
|
||||||
owner: repo[0],
|
owner: repo[0],
|
||||||
repo: repo[1],
|
repo: repo[1],
|
||||||
comment_id: inputs.commentId
|
comment_id: inputs.commentId,
|
||||||
});
|
});
|
||||||
commentBody = comment.body + "\n";
|
commentBody = comment.body + "\n";
|
||||||
}
|
}
|
||||||
@ -103,15 +118,15 @@ async function run() {
|
|||||||
owner: repo[0],
|
owner: repo[0],
|
||||||
repo: repo[1],
|
repo: repo[1],
|
||||||
comment_id: inputs.commentId,
|
comment_id: inputs.commentId,
|
||||||
body: commentBody
|
body: commentBody,
|
||||||
});
|
});
|
||||||
core.info(`Updated comment id '${inputs.commentId}'.`);
|
core.info(`Updated comment id '${inputs.commentId}'.`);
|
||||||
core.setOutput('comment-id', inputs.commentId);
|
core.setOutput("comment-id", inputs.commentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set a comment reaction
|
// Set comment reactions
|
||||||
if (inputs.reactionType) {
|
if (inputs.reactions) {
|
||||||
await addReaction(octokit, repo, inputs.commentId, inputs.reactionType);
|
await addReactions(octokit, repo, inputs.commentId, inputs.reactions);
|
||||||
}
|
}
|
||||||
} else if (inputs.issueNumber) {
|
} else if (inputs.issueNumber) {
|
||||||
// Create a comment
|
// Create a comment
|
||||||
@ -123,14 +138,16 @@ async function run() {
|
|||||||
owner: repo[0],
|
owner: repo[0],
|
||||||
repo: repo[1],
|
repo: repo[1],
|
||||||
issue_number: inputs.issueNumber,
|
issue_number: inputs.issueNumber,
|
||||||
body: inputs.body
|
body: inputs.body,
|
||||||
});
|
});
|
||||||
core.info(`Created comment id '${comment.id}' on issue '${inputs.issueNumber}'.`);
|
core.info(
|
||||||
core.setOutput('comment-id', comment.id);
|
`Created comment id '${comment.id}' on issue '${inputs.issueNumber}'.`
|
||||||
|
);
|
||||||
|
core.setOutput("comment-id", comment.id);
|
||||||
|
|
||||||
// Set a comment reaction
|
// Set comment reactions
|
||||||
if (inputs.reactionType) {
|
if (inputs.reactions) {
|
||||||
await addReaction(octokit, repo, comment.id, inputs.reactionType);
|
await addReactions(octokit, repo, comment.id, inputs.reactions);
|
||||||
}
|
}
|
||||||
} 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 -m -o dist",
|
"package": "ncc build index.js -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