mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2025-12-19 14:35:50 +00:00
♻️ guard error object
https://devblogs.microsoft.com/typescript/announcing-typescript-4-4/#use-unknown-catch-variables
This commit is contained in:
parent
72463c317a
commit
f202c00725
6 changed files with 33 additions and 21 deletions
18
dist/index.js
generated
vendored
18
dist/index.js
generated
vendored
|
|
@ -128,10 +128,12 @@ function buildBody() {
|
|||
const path = core.getInput("path", { required: false });
|
||||
if (path) {
|
||||
try {
|
||||
return fs_1.readFileSync(path, "utf-8");
|
||||
return (0, fs_1.readFileSync)(path, "utf-8");
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof Error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
@ -195,26 +197,28 @@ function run() {
|
|||
throw new Error("delete and recreate cannot be both set to true");
|
||||
}
|
||||
const octokit = github.getOctokit(config_1.githubToken);
|
||||
const previous = yield comment_1.findPreviousComment(octokit, config_1.repo, config_1.pullRequestNumber, config_1.header);
|
||||
const previous = yield (0, comment_1.findPreviousComment)(octokit, config_1.repo, config_1.pullRequestNumber, config_1.header);
|
||||
if (!previous) {
|
||||
yield comment_1.createComment(octokit, config_1.repo, config_1.pullRequestNumber, config_1.body, config_1.header);
|
||||
yield (0, comment_1.createComment)(octokit, config_1.repo, config_1.pullRequestNumber, config_1.body, config_1.header);
|
||||
return;
|
||||
}
|
||||
if (config_1.deleteOldComment) {
|
||||
yield comment_1.deleteComment(octokit, config_1.repo, previous.id);
|
||||
yield (0, comment_1.deleteComment)(octokit, config_1.repo, previous.id);
|
||||
return;
|
||||
}
|
||||
const previousBody = config_1.append ? previous.body : undefined;
|
||||
if (config_1.recreate) {
|
||||
yield comment_1.deleteComment(octokit, config_1.repo, previous.id);
|
||||
yield comment_1.createComment(octokit, config_1.repo, config_1.pullRequestNumber, config_1.body, config_1.header, previousBody);
|
||||
yield (0, comment_1.deleteComment)(octokit, config_1.repo, previous.id);
|
||||
yield (0, comment_1.createComment)(octokit, config_1.repo, config_1.pullRequestNumber, config_1.body, config_1.header, previousBody);
|
||||
return;
|
||||
}
|
||||
yield comment_1.updateComment(octokit, config_1.repo, previous.id, config_1.body, config_1.header, previousBody);
|
||||
yield (0, comment_1.updateComment)(octokit, config_1.repo, previous.id, config_1.body, config_1.header, previousBody);
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof Error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
run();
|
||||
|
|
|
|||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
4
lib/config.js
generated
4
lib/config.js
generated
|
|
@ -43,10 +43,12 @@ function buildBody() {
|
|||
const path = core.getInput("path", { required: false });
|
||||
if (path) {
|
||||
try {
|
||||
return fs_1.readFileSync(path, "utf-8");
|
||||
return (0, fs_1.readFileSync)(path, "utf-8");
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof Error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
14
lib/main.js
generated
14
lib/main.js
generated
|
|
@ -46,26 +46,28 @@ function run() {
|
|||
throw new Error("delete and recreate cannot be both set to true");
|
||||
}
|
||||
const octokit = github.getOctokit(config_1.githubToken);
|
||||
const previous = yield comment_1.findPreviousComment(octokit, config_1.repo, config_1.pullRequestNumber, config_1.header);
|
||||
const previous = yield (0, comment_1.findPreviousComment)(octokit, config_1.repo, config_1.pullRequestNumber, config_1.header);
|
||||
if (!previous) {
|
||||
yield comment_1.createComment(octokit, config_1.repo, config_1.pullRequestNumber, config_1.body, config_1.header);
|
||||
yield (0, comment_1.createComment)(octokit, config_1.repo, config_1.pullRequestNumber, config_1.body, config_1.header);
|
||||
return;
|
||||
}
|
||||
if (config_1.deleteOldComment) {
|
||||
yield comment_1.deleteComment(octokit, config_1.repo, previous.id);
|
||||
yield (0, comment_1.deleteComment)(octokit, config_1.repo, previous.id);
|
||||
return;
|
||||
}
|
||||
const previousBody = config_1.append ? previous.body : undefined;
|
||||
if (config_1.recreate) {
|
||||
yield comment_1.deleteComment(octokit, config_1.repo, previous.id);
|
||||
yield comment_1.createComment(octokit, config_1.repo, config_1.pullRequestNumber, config_1.body, config_1.header, previousBody);
|
||||
yield (0, comment_1.deleteComment)(octokit, config_1.repo, previous.id);
|
||||
yield (0, comment_1.createComment)(octokit, config_1.repo, config_1.pullRequestNumber, config_1.body, config_1.header, previousBody);
|
||||
return;
|
||||
}
|
||||
yield comment_1.updateComment(octokit, config_1.repo, previous.id, config_1.body, config_1.header, previousBody);
|
||||
yield (0, comment_1.updateComment)(octokit, config_1.repo, previous.id, config_1.body, config_1.header, previousBody);
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof Error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
run();
|
||||
|
|
|
|||
|
|
@ -28,7 +28,9 @@ function buildBody(): string {
|
|||
try {
|
||||
return readFileSync(path, "utf-8")
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -66,8 +66,10 @@ async function run(): Promise<undefined> {
|
|||
|
||||
await updateComment(octokit, repo, previous.id, body, header, previousBody)
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
run()
|
||||
|
|
|
|||
Loading…
Reference in a new issue