@@ -11,7 +11,7 @@ export interface generateOptions {
1111 owner : string ;
1212 repo : string ;
1313 cwd : string ;
14- format : "markdown"
14+ format : "markdown" | "json"
1515}
1616
1717export const fetchRepositoryInfo = ( ) : Promise < { owner : string ; repo : string } > => {
@@ -39,15 +39,31 @@ export const generate = (options: generateOptions): string => {
3939 const ymlList = glob . sync ( path . join ( options . cwd , ".github/workflows/*" ) , {
4040 dot : true
4141 } ) ;
42- return ymlList . map ( filePath => {
42+ const items = ymlList . map ( filePath => {
4343 const content = yaml . safeLoad ( fs . readFileSync ( filePath , "utf-8" ) ) ;
4444 if ( ! content . name ) {
4545 throw new Error ( `${ filePath } does not define name` ) ;
4646 }
4747 return content . name ;
4848 } ) . map ( workflowName => {
49- // --format "markdown"
50- // https://github.com/<OWNER>/<REPOSITORY>/workflows/<WORKFLOW_NAME>/badge.svg
51- return `[ } /badge.svg)](https://github.com/${ options . owner } /${ options . repo } /actions?query=workflow%3A"${ encodeWorkflowNameQuery ( workflowName ) } ")` ;
52- } ) . join ( "\n" ) ;
49+ // --format "json"
50+ if ( options . format === "json" ) {
51+ return {
52+ name : workflowName ,
53+ actionBadgeUrl : `https://github.com/${ options . owner } /${ options . repo } /workflows/${ encodeURIComponent ( workflowName ) } /badge.svg` ,
54+ workflowUrl : `https://github.com/${ options . owner } /${ options . repo } /actions?query=workflow%3A"${ encodeWorkflowNameQuery ( workflowName ) } `
55+ } ;
56+ } else if ( options . format === "markdown" ) {
57+ // --format "markdown"
58+ // https://github.com/<OWNER>/<REPOSITORY>/workflows/<WORKFLOW_NAME>/badge.svg
59+ return `[ } /badge.svg)](https://github.com/${ options . owner } /${ options . repo } /actions?query=workflow%3A"${ encodeWorkflowNameQuery ( workflowName ) } ")` ;
60+ }
61+ return ;
62+ } ) ;
63+ if ( options . format === "json" ) {
64+ return JSON . stringify ( items ) ;
65+ } else if ( options . format === "markdown" ) {
66+ return items . join ( "\n" ) ;
67+ }
68+ return "" ;
5369} ;
0 commit comments