add comments

This commit is contained in:
Namrata Jha
2021-12-23 13:01:35 +00:00
committed by GitHub
parent cfbae0ac37
commit 81676df338
4 changed files with 65 additions and 24 deletions
+26 -5
View File
@@ -47,22 +47,26 @@ export function finalIds(input: Input): Observable<string[]> {
}
if (input.hasOldestVersionQueryInfo()) {
if (input.minVersionsToKeep < 0) {
// This code block is when num-old-versions-to-delete is specified.
// Setting input.numOldVersionsToDelete is set as minimum of input.numOldVersionsToDelete and RATE_LIMIT
input.numOldVersionsToDelete =
input.numOldVersionsToDelete < RATE_LIMIT
? input.numOldVersionsToDelete
: RATE_LIMIT
console.log(
`input.numOldVersionsToDelete: ${input.numOldVersionsToDelete}`
)
return getVersionIds(
input.owner,
input.repo,
input.packageName,
input.numOldVersionsToDelete,
RATE_LIMIT,
'',
input.token
).pipe(
// This code block executes on batches of 100 versions starting from oldest
map(value => {
/*
Here first filter out the versions that are to be ignored.
Then update input.numOldeVersionsToDelete to the no of versions deleted from the next 100 versions batch.
*/
value = value.filter(info => !input.ignoreVersions.test(info.version))
const temp = input.numOldVersionsToDelete
input.numOldVersionsToDelete =
@@ -73,6 +77,7 @@ export function finalIds(input: Input): Observable<string[]> {
})
)
} else {
// This code block is when min-versions-to-keep is specified.
return getVersionIds(
input.owner,
input.repo,
@@ -81,15 +86,31 @@ export function finalIds(input: Input): Observable<string[]> {
'',
input.token
).pipe(
// This code block executes on batches of 100 versions starting from oldest
map(value => {
/*
Here totalCount is the total no of versions in the package.
First we update totalCount by removing no of ignored versions from it and also filter them out from value.
toDelete is the no of versions that need to be deleted and input.numDeleted is the total no of versions deleted before this batch.
We calculate this from total no of versions in the package, the min no of versions to keep and the no of versions we have deleted in earlier batch.
Then we update toDelete to not exceed the length of current batch of versions.
Now toDelete holds the no of versions to be deleted from the current batch of versions.
*/
totalCount =
totalCount -
value.filter(info => input.ignoreVersions.test(info.version)).length
value = value.filter(info => !input.ignoreVersions.test(info.version))
let toDelete = totalCount - input.minVersionsToKeep - input.numDeleted
toDelete = toDelete > value.length ? value.length : toDelete
//Checking here if we have any versions to delete and whether we are within the RATE_LIMIT.
if (toDelete > 0 && input.numDeleted < RATE_LIMIT) {
// using input.numDeleted to keep track of deleted and remaining packages
/*
Checking here if we can delete all the versions left in the current batch.
input.numDeleted + toDelete should not exceed RATE_LIMIT.
If it is exceeding we only delete the no of versions from this batch that are allowed within the RATE_LIMIT.
i.e. diff between RATE_LIMIT and versions deleted till now (input.numDeleted)
input.numDeleted is updated accordingly.
*/
if (input.numDeleted + toDelete > RATE_LIMIT) {
toDelete = RATE_LIMIT - input.numDeleted
input.numDeleted = RATE_LIMIT
+3 -5
View File
@@ -35,7 +35,7 @@ export function deletePackageVersion(
return throwError(
err.errors && err.errors.length > 0
? `${msg} ${err.errors[0].message}`
: `${msg} ${err.message}`
: `${msg} ${err.message} \n${deleted - 1} versions deleted till now.`
)
}),
map(response => response.deletePackageVersion.success)
@@ -53,14 +53,12 @@ export function deletePackageVersions(
const deletes = packageVersionIds.map(id =>
deletePackageVersion(id, token).pipe(
tap(result => {
if (result) {
console.log(`version with id: ${id}, deleted`)
} else {
if (!result) {
console.log(`version with id: ${id}, not deleted`)
}
})
)
)
console.log(`Versions Deleted: ${deleted}`)
console.log(`Total versions deleted till now: ${deleted}`)
return merge(...deletes)
}
+2 -2
View File
@@ -101,7 +101,7 @@ export function queryForOldestVersions(
owner,
repo,
package: packageName,
last: numVersions > 100 ? 100 : numVersions,
last: numVersions,
headers: {
Accept: 'application/vnd.github.packages-preview+json'
}
@@ -123,7 +123,7 @@ export function queryForOldestVersions(
owner,
repo,
package: packageName,
last: numVersions > 100 ? 100 : numVersions,
last: numVersions,
before: startCursor,
headers: {
Accept: 'application/vnd.github.packages-preview+json'