@@ -6,46 +6,63 @@ import { closeIssueForFinding } from "./closeIssueForFinding.js";
66import { openIssueForFinding } from "./openIssueForFinding.js" ;
77
88export default async function ( ) {
9+ core . info ( "Started 'file' action" ) ;
910 const findings : Finding [ ] = JSON . parse ( core . getInput ( 'findings' , { required : true } ) ) ;
1011 const repoWithOwner = core . getInput ( 'repository' , { required : true } ) ;
1112 const token = core . getInput ( 'token' , { required : true } ) ;
1213 const cachedFindings : Finding [ ] = JSON . parse ( core . getInput ( 'cached_findings' , { required : false } ) || "[]" ) ;
14+ core . debug ( `Input: 'findings: ${ JSON . stringify ( findings ) } '` ) ;
15+ core . debug ( `Input: 'repository: ${ repoWithOwner } '` ) ;
16+ core . debug ( `Input: 'cached_findings: ${ JSON . stringify ( cachedFindings ) } '` ) ;
1317
1418 const findingsMap = toFindingsMap ( findings ) ;
1519 const cachedFindingsMap = toFindingsMap ( cachedFindings ) ;
1620
1721 const octokit = new Octokit ( { auth : token } ) ;
18-
1922 const closedIssueUrls = [ ] ;
23+ const openedIssueUrls = [ ] ;
24+ const repeatIssueUrls = [ ] ;
25+
2026 for ( const cachedFinding of cachedFindings ) {
2127 if ( ! findingsMap . has ( `${ cachedFinding . url } ;${ cachedFinding . problemShort } ;${ cachedFinding . html } ` ) ) {
22- // Finding was not found in the latest run, so close its issue (if necessary)
23- const response = await closeIssueForFinding ( octokit , repoWithOwner , cachedFinding ) ;
24- closedIssueUrls . push ( response . data . html_url ) ;
25- console . log ( `Closed issue: ${ response . data . title } (${ repoWithOwner } #${ response . data . number } )` ) ;
28+ try {
29+ // Finding was not found in the latest run, so close its issue (if necessary)
30+ const response = await closeIssueForFinding ( octokit , repoWithOwner , cachedFinding ) ;
31+ closedIssueUrls . push ( response . data . html_url ) ;
32+ core . info ( `Closed issue: ${ response . data . title } (${ repoWithOwner } #${ response . data . number } )` ) ;
33+ } catch ( error ) {
34+ core . error ( `Failed to close issue for finding: ${ error } ` ) ;
35+ }
2636 }
2737 }
2838
29- const openedIssueUrls = [ ] ;
30- const repeatIssueUrls = [ ] ;
3139 for ( const finding of findings ) {
3240 const cachedIssueUrl = cachedFindingsMap . get ( `${ finding . url } ;${ finding . problemShort } ;${ finding . html } ` ) ?. issueUrl
3341 finding . issueUrl = cachedIssueUrl ;
34- const response = await openIssueForFinding ( octokit , repoWithOwner , finding ) ;
35- finding . issueUrl = response . data . html_url ;
36- if ( response . data . html_url === cachedIssueUrl ) {
37- // Finding was found in previous and latest runs, so reopen its issue (if necessary)
38- repeatIssueUrls . push ( response . data . html_url ) ;
39- console . log ( `Repeated issue: ${ response . data . title } (${ repoWithOwner } #${ response . data . number } )` ) ;
40- } else {
41- // New finding was found in the latest run, so create its issue
42- openedIssueUrls . push ( response . data . html_url ) ;
43- console . log ( `Created issue: ${ response . data . title } (${ repoWithOwner } #${ response . data . number } )` ) ;
42+ try {
43+ const response = await openIssueForFinding ( octokit , repoWithOwner , finding ) ;
44+ finding . issueUrl = response . data . html_url ;
45+ if ( response . data . html_url === cachedIssueUrl ) {
46+ // Finding was found in previous and latest runs, so reopen its issue (if necessary)
47+ repeatIssueUrls . push ( response . data . html_url ) ;
48+ core . info ( `Repeated issue: ${ response . data . title } (${ repoWithOwner } #${ response . data . number } )` ) ;
49+ } else {
50+ // New finding was found in the latest run, so create its issue
51+ openedIssueUrls . push ( response . data . html_url ) ;
52+ core . info ( `Created issue: ${ response . data . title } (${ repoWithOwner } #${ response . data . number } )` ) ;
53+ }
54+ } catch ( error ) {
55+ core . error ( `Failed to open/reopen issue for finding: ${ error } ` ) ;
4456 }
4557 }
4658
4759 core . setOutput ( "closed_issue_urls" , JSON . stringify ( closedIssueUrls ) ) ;
4860 core . setOutput ( "opened_issue_urls" , JSON . stringify ( openedIssueUrls ) ) ;
4961 core . setOutput ( "repeated_issue_urls" , JSON . stringify ( repeatIssueUrls ) ) ;
5062 core . setOutput ( "findings" , JSON . stringify ( findings ) ) ;
63+ core . debug ( `Output: 'closed_issue_urls: ${ JSON . stringify ( closedIssueUrls ) } '` ) ;
64+ core . debug ( `Output: 'opened_issue_urls: ${ JSON . stringify ( openedIssueUrls ) } '` ) ;
65+ core . debug ( `Output: 'repeated_issue_urls: ${ JSON . stringify ( repeatIssueUrls ) } '` ) ;
66+ core . debug ( `Output: 'findings: ${ JSON . stringify ( findings ) } '` ) ;
67+ core . info ( "Finished 'file' action" ) ;
5168}
0 commit comments