11require ( 'pretty-error' ) . start ( )
22
3- import { endGroup , getInput , info , setFailed , startGroup } from '@actions/core'
3+ import * as core from '@actions/core'
44import githubLabelSync , { LabelInfo } from 'github-label-sync'
55import fs from 'fs'
66import path from 'path'
77import yaml from 'yamljs'
88import axios from 'axios'
99
10+ const { endGroup, getInput, startGroup } = core
11+ const log = {
12+ info : ( str : string ) => core . info ( '🛈 ' + str ) ,
13+ success : ( str : string ) => core . info ( '✓ ' + str ) ,
14+ warning : ( str : string , showInReport = true ) => core [ ( showInReport ? 'warning' : 'info' ) ] ( '⚠ ' + str ) ,
15+ error : ( str : string , showInReport = true ) => core [ ( showInReport ? 'error' : 'info' ) ] ( '✗ ' + str ) ,
16+ fatal : ( str : string ) => core . setFailed ( '✗ ' + str )
17+ }
1018let usingLocalFile : boolean
1119
1220( async ( ) => {
@@ -28,9 +36,9 @@ let usingLocalFile: boolean
2836 } )
2937
3038 startGroup ( 'Label diff' )
31- info ( JSON . stringify ( diff , null , 2 ) )
39+ core . info ( JSON . stringify ( diff , null , 2 ) )
3240 endGroup ( )
33- } catch ( e ) { setFailed ( e ) }
41+ } catch ( e ) { log . fatal ( e ) }
3442} ) ( )
3543
3644function isProperConfig ( value : any ) : value is LabelInfo [ ] {
@@ -92,13 +100,13 @@ async function fetchRepoLabels(repo: string, token?: string): Promise<LabelInfo[
92100
93101 const url = `https://api.github.com/repos/${ repo } /labels` ,
94102 headers = token ? { Authorization : `token ${ token } ` } : undefined
95- info ( `Using following URL: ${ url } ` )
103+ log . info ( `Using following URL: ${ url } ` )
96104
97105 const { data } = await axios . get ( url , { headers } )
98106 if ( ! data || ! ( data instanceof Array ) )
99107 throw 'Can\'t get label data from GitHub API'
100108
101- info ( `${ data . length } labels fetched.` )
109+ log . success ( `${ data . length } labels fetched.` )
102110 endGroup ( )
103111
104112 return data . map ( element => ( {
@@ -111,24 +119,24 @@ async function fetchRepoLabels(repo: string, token?: string): Promise<LabelInfo[
111119
112120function checkInputs ( ) {
113121 if ( ! getInput ( 'token' ) )
114- setFailed ( 'The token parameter is required.' )
122+ throw 'The token parameter is required.'
115123
116124 const configFile = getInput ( 'config-file' ) ,
117125 sourceRepo = getInput ( 'source-repo' )
118126
119127 if ( ! ! configFile == ! ! sourceRepo )
120- setFailed ( 'You can\'t use a config file and a source repo at the same time. Choose one!' )
128+ throw 'You can\'t use a config file and a source repo at the same time. Choose one!'
121129
122130 // config-file: doesn't need evaluation, will be evaluated when parsing
123131 usingLocalFile = ! ! configFile
124132
125133 if ( sourceRepo && sourceRepo . split ( '/' ) . length != 2 )
126- setFailed ( 'Source repo should be in the owner/repo format, like EndBug/label-sync!' )
134+ throw 'Source repo should be in the owner/repo format, like EndBug/label-sync!'
127135 if ( sourceRepo && ! getInput ( 'source-repo-token' ) )
128- info ( 'You\'re using a source repo without a token: if your repository is private the action won\'t be able to read the labels.' )
136+ log . warning ( 'You\'re using a source repo without a token: if your repository is private the action won\'t be able to read the labels.' , false )
129137
130138 if ( ! [ 'true' , 'false' ] . includes ( getInput ( 'delete-other-labels' ) ) )
131- setFailed ( 'The only values you can use for the `delete-other-labels` option are `true` and `false`' )
139+ throw 'The only values you can use for the `delete-other-labels` option are `true` and `false`'
132140 if ( ! [ 'true' , 'false' ] . includes ( getInput ( 'dry-run' ) ) )
133- setFailed ( 'The only values you can use for the `dry-run` option are `true` and `false`' )
141+ throw 'The only values you can use for the `dry-run` option are `true` and `false`'
134142}
0 commit comments