@@ -10,7 +10,7 @@ module.exports = async ({
1010 const packageName = imageName . replace ( `${ repositoryOwner } /` , "" ) ;
1111
1212 let currentPage = 1 ;
13- const allDeletedTags = [ ] ;
13+ const allTagsToDelete = [ ] ;
1414 for ( ; ; ) {
1515 const data = await getAllPackageVersions ( {
1616 github,
@@ -26,23 +26,21 @@ module.exports = async ({
2626 break ;
2727 }
2828
29- const deletedTags = await Promise . all (
29+ const tagsToDelete = await Promise . all (
3030 data . map ( ( packageVersion ) =>
31- processPackageVersion ( {
31+ getTagsToDeleteFromPackageVersion ( {
3232 github,
3333 context,
3434 core,
35- isOrganization,
36- packageName,
3735 pullRequestTagFilter,
3836 packageVersion,
3937 } ) ,
4038 ) ,
4139 ) ;
42- allDeletedTags . push ( ...deletedTags . flat ( ) ) ;
40+ allTagsToDelete . push ( ...tagsToDelete . flat ( ) ) ;
4341 }
4442
45- return [ ...new Set ( allDeletedTags ) ] ;
43+ return [ ...new Set ( allTagsToDelete ) ] ;
4644} ;
4745
4846async function getAllPackageVersions ( {
@@ -81,12 +79,10 @@ async function getAllPackageVersions({
8179 return data ;
8280}
8381
84- async function processPackageVersion ( {
82+ async function getTagsToDeleteFromPackageVersion ( {
8583 github,
8684 context,
8785 core,
88- packageName,
89- isOrganization,
9086 pullRequestTagFilter,
9187 packageVersion,
9288} ) {
@@ -127,15 +123,6 @@ async function processPackageVersion({
127123 return [ ] ;
128124 }
129125
130- await deletePackageVersion ( {
131- github,
132- core,
133- context,
134- packageName,
135- isOrganization,
136- packageVersion,
137- } ) ;
138-
139126 return tags ;
140127}
141128
@@ -171,47 +158,6 @@ async function isPullRequestClosed({ github, context, pullRequestNumber }) {
171158 return closedPullRequests . get ( pullRequestNumber ) ;
172159}
173160
174- async function deletePackageVersion ( {
175- github,
176- core,
177- context,
178- packageName,
179- isOrganization,
180- packageVersion,
181- } ) {
182- try {
183- if ( isOrganization ) {
184- return await rateLimitRetryCall (
185- github . rest . packages . deletePackageVersionForOrg ,
186- {
187- package_type : "container" ,
188- package_name : packageName ,
189- org : context . repo . owner ,
190- package_version_id : packageVersion . id ,
191- } ,
192- ) ;
193- }
194-
195- return await rateLimitRetryCall (
196- github . rest . packages . deletePackageVersionForUser ,
197- {
198- package_type : "container" ,
199- package_name : packageName ,
200- username : context . repo . owner ,
201- package_version_id : packageVersion . id ,
202- } ,
203- ) ;
204- } catch ( error ) {
205- if ( error . status === 404 ) {
206- core . warning (
207- `Package version ${ packageVersion . name } (${ packageVersion . id } ) cannot be deleted as it is not found` ,
208- ) ;
209- } else {
210- throw error ;
211- }
212- }
213- }
214-
215161async function rateLimitRetryCall ( fn , ...args ) {
216162 try {
217163 return await fn ( ...args ) ;
0 commit comments