mirror of
https://github.com/peter-evans/create-or-update-comment.git
synced 2025-01-19 03:26:42 +08:00
Update distribution
This commit is contained in:
parent
f45a0a4d45
commit
54141f84ca
357
dist/index.js
vendored
357
dist/index.js
vendored
@ -1,179 +1,6 @@
|
|||||||
module.exports =
|
|
||||||
/******/ (() => { // webpackBootstrap
|
/******/ (() => { // webpackBootstrap
|
||||||
/******/ var __webpack_modules__ = ({
|
/******/ var __webpack_modules__ = ({
|
||||||
|
|
||||||
/***/ 932:
|
|
||||||
/***/ ((__unused_webpack_module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
||||||
|
|
||||||
const { inspect } = __nccwpck_require__(669);
|
|
||||||
const core = __nccwpck_require__(186);
|
|
||||||
const github = __nccwpck_require__(438);
|
|
||||||
|
|
||||||
const REACTION_TYPES = [
|
|
||||||
"+1",
|
|
||||||
"-1",
|
|
||||||
"laugh",
|
|
||||||
"confused",
|
|
||||||
"heart",
|
|
||||||
"hooray",
|
|
||||||
"rocket",
|
|
||||||
"eyes",
|
|
||||||
];
|
|
||||||
|
|
||||||
async function addReactions(octokit, repo, comment_id, reactions) {
|
|
||||||
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({
|
|
||||||
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() {
|
|
||||||
try {
|
|
||||||
const inputs = {
|
|
||||||
token: core.getInput("token"),
|
|
||||||
repository: core.getInput("repository"),
|
|
||||||
issueNumber: core.getInput("issue-number"),
|
|
||||||
commentId: core.getInput("comment-id"),
|
|
||||||
body: core.getInput("body"),
|
|
||||||
editMode: core.getInput("edit-mode"),
|
|
||||||
reactions: core.getInput("reactions")
|
|
||||||
? core.getInput("reactions")
|
|
||||||
: core.getInput("reaction-type"),
|
|
||||||
};
|
|
||||||
core.debug(`Inputs: ${inspect(inputs)}`);
|
|
||||||
|
|
||||||
const repository = inputs.repository
|
|
||||||
? inputs.repository
|
|
||||||
: process.env.GITHUB_REPOSITORY;
|
|
||||||
const repo = repository.split("/");
|
|
||||||
core.debug(`repository: ${repository}`);
|
|
||||||
|
|
||||||
const editMode = inputs.editMode ? inputs.editMode : "append";
|
|
||||||
core.debug(`editMode: ${editMode}`);
|
|
||||||
if (!["append", "replace"].includes(editMode)) {
|
|
||||||
core.setFailed(`Invalid edit-mode '${editMode}'.`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const octokit = github.getOctokit(inputs.token);
|
|
||||||
|
|
||||||
if (inputs.commentId) {
|
|
||||||
// Edit a comment
|
|
||||||
if (!inputs.body && !inputs.reactions) {
|
|
||||||
core.setFailed("Missing either comment 'body' or 'reactions'.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inputs.body) {
|
|
||||||
var commentBody = "";
|
|
||||||
if (editMode == "append") {
|
|
||||||
// Get the comment body
|
|
||||||
const { data: comment } = await octokit.issues.getComment({
|
|
||||||
owner: repo[0],
|
|
||||||
repo: repo[1],
|
|
||||||
comment_id: inputs.commentId,
|
|
||||||
});
|
|
||||||
commentBody = comment.body + "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
commentBody = commentBody + inputs.body;
|
|
||||||
core.debug(`Comment body: ${commentBody}`);
|
|
||||||
await octokit.issues.updateComment({
|
|
||||||
owner: repo[0],
|
|
||||||
repo: repo[1],
|
|
||||||
comment_id: inputs.commentId,
|
|
||||||
body: commentBody,
|
|
||||||
});
|
|
||||||
core.info(`Updated comment id '${inputs.commentId}'.`);
|
|
||||||
core.setOutput("comment-id", inputs.commentId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set comment reactions
|
|
||||||
if (inputs.reactions) {
|
|
||||||
await addReactions(octokit, repo, inputs.commentId, inputs.reactions);
|
|
||||||
}
|
|
||||||
} else if (inputs.issueNumber) {
|
|
||||||
// Create a comment
|
|
||||||
if (!inputs.body) {
|
|
||||||
core.setFailed("Missing comment 'body'.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const { data: comment } = await octokit.issues.createComment({
|
|
||||||
owner: repo[0],
|
|
||||||
repo: repo[1],
|
|
||||||
issue_number: inputs.issueNumber,
|
|
||||||
body: inputs.body,
|
|
||||||
});
|
|
||||||
core.info(
|
|
||||||
`Created comment id '${comment.id}' on issue '${inputs.issueNumber}'.`
|
|
||||||
);
|
|
||||||
core.setOutput("comment-id", comment.id);
|
|
||||||
|
|
||||||
// Set comment reactions
|
|
||||||
if (inputs.reactions) {
|
|
||||||
await addReactions(octokit, repo, comment.id, inputs.reactions);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
core.setFailed("Missing either 'issue-number' or 'comment-id'.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
core.debug(inspect(error));
|
|
||||||
core.setFailed(error.message);
|
|
||||||
if (error.message == 'Resource not accessible by integration') {
|
|
||||||
core.error(`See this action's readme for details about this error`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
run();
|
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
|
||||||
|
|
||||||
/***/ 351:
|
/***/ 351:
|
||||||
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||||
|
|
||||||
@ -370,6 +197,7 @@ exports.getInput = getInput;
|
|||||||
*/
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
function setOutput(name, value) {
|
function setOutput(name, value) {
|
||||||
|
process.stdout.write(os.EOL);
|
||||||
command_1.issueCommand('set-output', { name }, value);
|
command_1.issueCommand('set-output', { name }, value);
|
||||||
}
|
}
|
||||||
exports.setOutput = setOutput;
|
exports.setOutput = setOutput;
|
||||||
@ -6183,8 +6011,9 @@ module.exports = require("zlib");;
|
|||||||
/******/ // The require function
|
/******/ // The require function
|
||||||
/******/ function __nccwpck_require__(moduleId) {
|
/******/ function __nccwpck_require__(moduleId) {
|
||||||
/******/ // Check if module is in cache
|
/******/ // Check if module is in cache
|
||||||
/******/ if(__webpack_module_cache__[moduleId]) {
|
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
||||||
/******/ return __webpack_module_cache__[moduleId].exports;
|
/******/ if (cachedModule !== undefined) {
|
||||||
|
/******/ return cachedModule.exports;
|
||||||
/******/ }
|
/******/ }
|
||||||
/******/ // Create a new module (and put it into the cache)
|
/******/ // Create a new module (and put it into the cache)
|
||||||
/******/ var module = __webpack_module_cache__[moduleId] = {
|
/******/ var module = __webpack_module_cache__[moduleId] = {
|
||||||
@ -6209,10 +6038,178 @@ module.exports = require("zlib");;
|
|||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
/******/ /* webpack/runtime/compat */
|
/******/ /* webpack/runtime/compat */
|
||||||
/******/
|
/******/
|
||||||
/******/ __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
|
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
|
||||||
/******/ // module exports must be returned from runtime so entry inlining is disabled
|
var __webpack_exports__ = {};
|
||||||
/******/ // startup
|
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
||||||
/******/ // Load entry module and return exports
|
(() => {
|
||||||
/******/ return __nccwpck_require__(932);
|
const { inspect } = __nccwpck_require__(669);
|
||||||
|
const core = __nccwpck_require__(186);
|
||||||
|
const github = __nccwpck_require__(438);
|
||||||
|
|
||||||
|
const REACTION_TYPES = [
|
||||||
|
"+1",
|
||||||
|
"-1",
|
||||||
|
"laugh",
|
||||||
|
"confused",
|
||||||
|
"heart",
|
||||||
|
"hooray",
|
||||||
|
"rocket",
|
||||||
|
"eyes",
|
||||||
|
];
|
||||||
|
|
||||||
|
async function addReactions(octokit, repo, comment_id, reactions) {
|
||||||
|
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({
|
||||||
|
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() {
|
||||||
|
try {
|
||||||
|
const inputs = {
|
||||||
|
token: core.getInput("token"),
|
||||||
|
repository: core.getInput("repository"),
|
||||||
|
issueNumber: core.getInput("issue-number"),
|
||||||
|
commentId: core.getInput("comment-id"),
|
||||||
|
body: core.getInput("body"),
|
||||||
|
editMode: core.getInput("edit-mode"),
|
||||||
|
reactions: core.getInput("reactions")
|
||||||
|
? core.getInput("reactions")
|
||||||
|
: core.getInput("reaction-type"),
|
||||||
|
};
|
||||||
|
core.debug(`Inputs: ${inspect(inputs)}`);
|
||||||
|
|
||||||
|
const repository = inputs.repository
|
||||||
|
? inputs.repository
|
||||||
|
: process.env.GITHUB_REPOSITORY;
|
||||||
|
const repo = repository.split("/");
|
||||||
|
core.debug(`repository: ${repository}`);
|
||||||
|
|
||||||
|
const editMode = inputs.editMode ? inputs.editMode : "append";
|
||||||
|
core.debug(`editMode: ${editMode}`);
|
||||||
|
if (!["append", "replace"].includes(editMode)) {
|
||||||
|
core.setFailed(`Invalid edit-mode '${editMode}'.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const octokit = github.getOctokit(inputs.token);
|
||||||
|
|
||||||
|
if (inputs.commentId) {
|
||||||
|
// Edit a comment
|
||||||
|
if (!inputs.body && !inputs.reactions) {
|
||||||
|
core.setFailed("Missing either comment 'body' or 'reactions'.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inputs.body) {
|
||||||
|
var commentBody = "";
|
||||||
|
if (editMode == "append") {
|
||||||
|
// Get the comment body
|
||||||
|
const { data: comment } = await octokit.issues.getComment({
|
||||||
|
owner: repo[0],
|
||||||
|
repo: repo[1],
|
||||||
|
comment_id: inputs.commentId,
|
||||||
|
});
|
||||||
|
commentBody = comment.body + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
commentBody = commentBody + inputs.body;
|
||||||
|
core.debug(`Comment body: ${commentBody}`);
|
||||||
|
await octokit.issues.updateComment({
|
||||||
|
owner: repo[0],
|
||||||
|
repo: repo[1],
|
||||||
|
comment_id: inputs.commentId,
|
||||||
|
body: commentBody,
|
||||||
|
});
|
||||||
|
core.info(`Updated comment id '${inputs.commentId}'.`);
|
||||||
|
core.setOutput("comment-id", inputs.commentId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set comment reactions
|
||||||
|
if (inputs.reactions) {
|
||||||
|
await addReactions(octokit, repo, inputs.commentId, inputs.reactions);
|
||||||
|
}
|
||||||
|
} else if (inputs.issueNumber) {
|
||||||
|
// Create a comment
|
||||||
|
if (!inputs.body) {
|
||||||
|
core.setFailed("Missing comment 'body'.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { data: comment } = await octokit.issues.createComment({
|
||||||
|
owner: repo[0],
|
||||||
|
repo: repo[1],
|
||||||
|
issue_number: inputs.issueNumber,
|
||||||
|
body: inputs.body,
|
||||||
|
});
|
||||||
|
core.info(
|
||||||
|
`Created comment id '${comment.id}' on issue '${inputs.issueNumber}'.`
|
||||||
|
);
|
||||||
|
core.setOutput("comment-id", comment.id);
|
||||||
|
|
||||||
|
// Set comment reactions
|
||||||
|
if (inputs.reactions) {
|
||||||
|
await addReactions(octokit, repo, comment.id, inputs.reactions);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
core.setFailed("Missing either 'issue-number' or 'comment-id'.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
core.debug(inspect(error));
|
||||||
|
core.setFailed(error.message);
|
||||||
|
if (error.message == 'Resource not accessible by integration') {
|
||||||
|
core.error(`See this action's readme for details about this error`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run();
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
||||||
|
module.exports = __webpack_exports__;
|
||||||
/******/ })()
|
/******/ })()
|
||||||
;
|
;
|
Loading…
x
Reference in New Issue
Block a user