@@ -24,6 +24,7 @@ export default async function () {
2424 const cachedFilings : ( ResolvedFiling | RepeatedFiling ) [ ] = JSON . parse (
2525 core . getInput ( "cached_filings" , { required : false } ) || "[]" ,
2626 ) ;
27+ const shouldOpenTrackingIssues = core . getBooleanInput ( "open_tracking_issues" ) ;
2728 core . debug ( `Input: 'findings: ${ JSON . stringify ( findings ) } '` ) ;
2829 core . debug ( `Input: 'repository: ${ repoWithOwner } '` ) ;
2930 core . debug ( `Input: 'cached_filings: ${ JSON . stringify ( cachedFilings ) } '` ) ;
@@ -70,13 +71,15 @@ export default async function () {
7071 response = await openIssue ( octokit , repoWithOwner , filing . findings [ 0 ] ) ;
7172 ( filing as any ) . issue = { state : "open" } as Issue ;
7273 // Track for grouping
73- const problemShort : string = filing . findings [ 0 ] . problemShort ;
74- if ( ! newIssuesByProblemShort [ problemShort ] )
75- newIssuesByProblemShort [ problemShort ] = [ ] ;
76- newIssuesByProblemShort [ problemShort ] . push ( {
77- url : response . data . html_url ,
78- id : response . data . number ,
79- } ) ;
74+ if ( shouldOpenTrackingIssues ) {
75+ const problemShort : string = filing . findings [ 0 ] . problemShort ;
76+ if ( ! newIssuesByProblemShort [ problemShort ] )
77+ newIssuesByProblemShort [ problemShort ] = [ ] ;
78+ newIssuesByProblemShort [ problemShort ] . push ( {
79+ url : response . data . html_url ,
80+ id : response . data . number ,
81+ } ) ;
82+ }
8083 } else if ( isRepeatedFiling ( filing ) ) {
8184 // Reopen the filing’s issue (if necessary)
8285 response = await reopenIssue ( octokit , new Issue ( filing . issue ) ) ;
@@ -98,39 +101,41 @@ export default async function () {
98101 }
99102 }
100103
101- // Open tracking issues for groups with >1 new issue and link back from each new issue
102- for ( const [ problemShort , issues ] of Object . entries (
103- newIssuesByProblemShort ,
104- ) as [ string , { url : string ; id : number } [ ] ] [ ] ) {
105- if ( issues . length > 1 ) {
106- const title : string = `${ problemShort } issues` ;
107- const body : string =
108- `# ${ problemShort } issues\n\n` +
109- issues . map ( ( issue ) => `- [ ] ${ issue . url } ` ) . join ( "\n" ) ;
110- try {
111- const trackingResponse = await octokit . request (
112- `POST /repos/${ repoWithOwner } /issues` ,
113- {
114- owner : repoWithOwner . split ( "/" ) [ 0 ] ,
115- repo : repoWithOwner . split ( "/" ) [ 1 ] ,
116- title,
117- body,
118- } ,
119- ) ;
120- const trackingUrl : string = trackingResponse . data . html_url ;
121- trackingIssueUrls [ problemShort ] = trackingUrl ;
122- core . info (
123- `Opened tracking issue for '${ problemShort } ' with ${ issues . length } issues.` ,
124- ) ;
125- } catch ( error ) {
126- core . warning (
127- `Failed to open tracking issue for '${ problemShort } ': ${ error } ` ,
128- ) ;
104+ // Open tracking issues for each root cause and link back from each newly-created issue
105+ if ( shouldOpenTrackingIssues ) {
106+ for ( const [ problemShort , issues ] of Object . entries (
107+ newIssuesByProblemShort ,
108+ ) as [ string , { url : string ; id : number } [ ] ] [ ] ) {
109+ if ( issues . length > 1 ) {
110+ const title : string = `${ problemShort } issues` ;
111+ const body : string =
112+ `# ${ problemShort } issues\n\n` +
113+ issues . map ( ( issue ) => `- [ ] ${ issue . url } ` ) . join ( "\n" ) ;
114+ try {
115+ const trackingResponse = await octokit . request (
116+ `POST /repos/${ repoWithOwner } /issues` ,
117+ {
118+ owner : repoWithOwner . split ( "/" ) [ 0 ] ,
119+ repo : repoWithOwner . split ( "/" ) [ 1 ] ,
120+ title,
121+ body,
122+ } ,
123+ ) ;
124+ const trackingUrl : string = trackingResponse . data . html_url ;
125+ trackingIssueUrls [ problemShort ] = trackingUrl ;
126+ core . info (
127+ `Opened tracking issue for '${ problemShort } ': ${ issues . length } issues.` ,
128+ ) ;
129+ } catch ( error ) {
130+ core . warning (
131+ `Failed to open tracking issue for '${ problemShort } ': ${ error } ` ,
132+ ) ;
133+ }
129134 }
130135 }
131- }
132136
133- core . setOutput ( "filings" , JSON . stringify ( filings ) ) ;
134- core . debug ( `Output: 'filings: ${ JSON . stringify ( filings ) } '` ) ;
135- core . info ( "Finished 'file' action" ) ;
137+ core . setOutput ( "filings" , JSON . stringify ( filings ) ) ;
138+ core . debug ( `Output: 'filings: ${ JSON . stringify ( filings ) } '` ) ;
139+ core . info ( "Finished 'file' action" ) ;
140+ }
136141}
0 commit comments