1- const fs = require ( 'fs' ) ;
2- const core = require ( ' @actions/core' ) ;
1+ const fs = require ( "fs" ) ;
2+ const core = require ( " @actions/core" ) ;
33
44async function run ( ) {
55 try {
6- const serverHostname = core . getInput ( ' serverhostname' ) ;
7- const port = core . getInput ( ' port' ) ;
8- const protocol = core . getInput ( ' protocol' ) ;
9- const apiKey = core . getInput ( ' apikey' ) ;
10- const project = core . getInput ( ' project' ) ;
11- const projectName = core . getInput ( ' projectname' ) ;
12- const projectVersion = core . getInput ( ' projectversion' ) ;
13- const projectTags = core . getInput ( ' projecttags' ) ;
14- const autoCreate = core . getInput ( ' autocreate' ) !== ' false' ;
15- const bomFilename = core . getInput ( ' bomfilename' ) ;
16- const parent = core . getInput ( ' parent' ) ;
17- const parentName = core . getInput ( ' parentname' ) ;
18- const parentVersion = core . getInput ( ' parentversion' ) ;
6+ const serverHostname = core . getInput ( " serverhostname" ) ;
7+ const port = core . getInput ( " port" ) ;
8+ const protocol = core . getInput ( " protocol" ) ;
9+ const apiKey = core . getInput ( " apikey" ) ;
10+ const project = core . getInput ( " project" ) ;
11+ const projectName = core . getInput ( " projectname" ) ;
12+ const projectVersion = core . getInput ( " projectversion" ) ;
13+ const projectTags = core . getInput ( " projecttags" ) ;
14+ const autoCreate = core . getInput ( " autocreate" ) !== " false" ;
15+ const bomFilename = core . getInput ( " bomfilename" ) ;
16+ const parent = core . getInput ( " parent" ) ;
17+ const parentName = core . getInput ( " parentname" ) ;
18+ const parentVersion = core . getInput ( " parentversion" ) ;
1919
2020 if ( protocol !== "http" && protocol !== "https" ) {
21- throw 'protocol "' + protocol + '" not supported, must be one of: https, http'
21+ throw (
22+ 'protocol "' + protocol + '" not supported, must be one of: https, http'
23+ ) ;
2224 }
2325
2426 if ( project === "" && ( projectName === "" || projectVersion === "" ) ) {
25- throw ' project or projectName + projectVersion must be set'
27+ throw " project or projectName + projectVersion must be set" ;
2628 }
2729
2830 if ( ! autoCreate && project === "" ) {
29- throw ' project can\ 't be empty if autoCreate is false'
31+ throw " project can't be empty if autoCreate is false" ;
3032 }
3133
3234 if ( project === "" && ( projectName === "" || projectVersion === "" ) ) {
33- throw ' project or projectName + projectVersion must be set'
35+ throw " project or projectName + projectVersion must be set" ;
3436 }
3537
36- if ( ( parentName === "" && parentVersion !== "" ) || ( parentName !== "" && parentVersion === "" ) ) {
37- throw 'parentName + parentVersion must both be set'
38+ if (
39+ ( parentName === "" && parentVersion !== "" ) ||
40+ ( parentName !== "" && parentVersion === "" )
41+ ) {
42+ throw "parentName + parentVersion must both be set" ;
3843 }
3944
4045 core . info ( `Reading BOM: ${ bomFilename } ...` ) ;
4146 const bomContents = fs . readFileSync ( bomFilename ) ;
42- let encodedBomContents = Buffer . from ( bomContents ) . toString ( ' base64' ) ;
43- if ( encodedBomContents . startsWith ( ' 77u/' ) ) {
47+ let encodedBomContents = Buffer . from ( bomContents ) . toString ( " base64" ) ;
48+ if ( encodedBomContents . startsWith ( " 77u/" ) ) {
4449 encodedBomContents = encodedBomContents . substring ( 4 ) ;
4550 }
4651
@@ -50,56 +55,62 @@ async function run() {
5055 projectName : projectName ,
5156 projectVersion : projectVersion ,
5257 autoCreate : autoCreate ,
53- bom : encodedBomContents
54- }
58+ bom : encodedBomContents ,
59+ } ;
5560 if ( projectTags ) {
56- bomPayload . projectTags = projectTags . split ( ',' ) . map ( tag => ( { name : tag . trim ( ) } ) ) ;
61+ bomPayload . projectTags = projectTags
62+ . split ( "," )
63+ . map ( ( tag ) => ( { name : tag . trim ( ) } ) ) ;
5764 }
5865 } else {
5966 bomPayload = {
6067 project : project ,
61- bom : encodedBomContents
62- }
68+ bom : encodedBomContents ,
69+ } ;
6370 }
6471
6572 if ( parent && parent . trim ( ) . length > 0 ) {
6673 bomPayload . parentUUID = parent ;
67- } else if ( parentName && parentName . trim ( ) . length > 0 && parentVersion && parentVersion . trim ( ) . length > 0 ) {
74+ } else if (
75+ parentName &&
76+ parentName . trim ( ) . length > 0 &&
77+ parentVersion &&
78+ parentVersion . trim ( ) . length > 0
79+ ) {
6880 bomPayload . parentName = parentName ;
6981 bomPayload . parentVersion = parentVersion ;
7082 }
7183
7284 const postData = JSON . stringify ( bomPayload ) ;
7385
7486 const requestOptions = {
75- method : ' PUT' ,
87+ method : " PUT" ,
7688 headers : {
77- ' X-API-Key' : apiKey ,
78- ' Content-Type' : ' application/json' ,
89+ " X-API-Key" : apiKey ,
90+ " Content-Type" : " application/json" ,
7991 } ,
80- body : postData
92+ body : postData ,
8193 } ;
8294
8395 const url = new URL ( `${ protocol } ://${ serverHostname } ` ) ;
8496 if ( port ) {
8597 url . port = port ;
8698 }
87- url . pathname = ' /api/v1/bom' ;
99+ url . pathname = " /api/v1/bom" ;
88100
89101 core . info ( `Uploading to Dependency-Track server ${ serverHostname } ...` ) ;
90102
91103 const response = await fetch ( url . toString ( ) , requestOptions ) ;
92104
93105 if ( response . ok ) {
94- core . info ( ' Finished uploading BOM to Dependency-Track server.' ) ;
106+ core . info ( " Finished uploading BOM to Dependency-Track server." ) ;
95107 } else {
96108 const responseBody = await response . text ( ) ;
97109 if ( responseBody ) {
98110 core . debug ( responseBody ) ;
99111 }
100- core . setFailed ( ' Failed response status code:' + response . status ) ;
112+ core . setFailed ( " Failed response status code:" + response . status ) ;
101113 }
102-
103114 } catch ( error ) {
104115 core . setFailed ( error . message ) ;
105116 }
0 commit comments