Skip to content

Commit 4a7383b

Browse files
committed
feat: use GitHub Action annotations instead of console.log()
ref: https://github.com/actions/toolkit/tree/main/packages/core#annotations
1 parent ae5c20e commit 4a7383b

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

src/main.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { context, getOctokit } from "@actions/github";
2-
import { getBooleanInput, getInput, setFailed, setOutput } from "@actions/core";
2+
import {
3+
getBooleanInput,
4+
getInput,
5+
setFailed,
6+
setOutput,
7+
notice,
8+
warning,
9+
} from "@actions/core";
310

411
export async function run(): Promise<void> {
512
try {
@@ -11,20 +18,21 @@ export async function run(): Promise<void> {
1118

1219
// https://github.blog/changelog/2021-02-19-github-actions-workflows-triggered-by-dependabot-prs-will-run-with-read-only-permissions/
1320
if (sender?.login === "dependabot[bot]") {
14-
console.log("Dependabot created the pull request, ending run.");
15-
return;
21+
notice("Exit: dependabot created the pull request.");
22+
process.exit(0);
1623
}
1724

1825
const farthest = getBooleanInput("farthest");
1926
const overwrite = getBooleanInput("overwrite");
27+
2028
const token = getInput("repo-token");
2129
const octokit = getOctokit(token);
2230

2331
if (!overwrite && (issue?.milestone || pull_request?.milestone)) {
24-
console.log(
25-
"The `overwrite` option is not enabled and the issue or pull request already has a milestone, ending run.",
32+
notice(
33+
"Exit: the `overwrite` option is not enabled and the issue or pull request already has a milestone.",
2634
);
27-
return;
35+
process.exit(0);
2836
}
2937

3038
const { data: milestones } = await octokit.rest.issues.listMilestones({
@@ -36,8 +44,8 @@ export async function run(): Promise<void> {
3644
});
3745

3846
if (!milestones.length) {
39-
console.log("There are no open milestones in this repo, ending run.");
40-
return;
47+
warning("Exit: there are no open milestones in this repo.");
48+
process.exit(0);
4149
}
4250

4351
const currentDate = new Date(Date.now());
@@ -50,14 +58,21 @@ export async function run(): Promise<void> {
5058
issue_number,
5159
milestone: milestone.number,
5260
});
61+
62+
notice(
63+
`Success: the issue or pull request was added to the "${milestone.title}" milestone.`,
64+
);
65+
5366
setOutput("milestone", milestone);
54-
return;
67+
process.exit(0);
5568
}
5669
}
57-
console.log("No matching milestone was found or added, ending run.");
70+
71+
notice("Exit: all open milestones are past due or do not have a due date.");
5872
} catch (e) {
5973
if (e instanceof Error) {
6074
setFailed(e.message);
75+
process.exit(1);
6176
}
6277
}
6378
}

0 commit comments

Comments
 (0)