1
1
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" ;
3
10
4
11
export async function run ( ) : Promise < void > {
5
12
try {
@@ -11,20 +18,21 @@ export async function run(): Promise<void> {
11
18
12
19
// https://github.blog/changelog/2021-02-19-github-actions-workflows-triggered-by-dependabot-prs-will-run-with-read-only-permissions/
13
20
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 ) ;
16
23
}
17
24
18
25
const farthest = getBooleanInput ( "farthest" ) ;
19
26
const overwrite = getBooleanInput ( "overwrite" ) ;
27
+
20
28
const token = getInput ( "repo-token" ) ;
21
29
const octokit = getOctokit ( token ) ;
22
30
23
31
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." ,
26
34
) ;
27
- return ;
35
+ process . exit ( 0 ) ;
28
36
}
29
37
30
38
const { data : milestones } = await octokit . rest . issues . listMilestones ( {
@@ -36,8 +44,8 @@ export async function run(): Promise<void> {
36
44
} ) ;
37
45
38
46
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 ) ;
41
49
}
42
50
43
51
const currentDate = new Date ( Date . now ( ) ) ;
@@ -50,14 +58,21 @@ export async function run(): Promise<void> {
50
58
issue_number,
51
59
milestone : milestone . number ,
52
60
} ) ;
61
+
62
+ notice (
63
+ `Success: the issue or pull request was added to the "${ milestone . title } " milestone.` ,
64
+ ) ;
65
+
53
66
setOutput ( "milestone" , milestone ) ;
54
- return ;
67
+ process . exit ( 0 ) ;
55
68
}
56
69
}
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." ) ;
58
72
} catch ( e ) {
59
73
if ( e instanceof Error ) {
60
74
setFailed ( e . message ) ;
75
+ process . exit ( 1 ) ;
61
76
}
62
77
}
63
78
}
0 commit comments