Check input combinations

This commit is contained in:
Namrata Jha
2021-12-14 12:34:03 +00:00
committed by GitHub
parent 248e3651e3
commit c253b9d27a
3 changed files with 42 additions and 29 deletions

View File

@@ -49,6 +49,10 @@ export function deleteVersions(input: Input): Observable<boolean> {
return throwError('No token found')
}
if (!input.checkInput()) {
return throwError('Invalid input combination')
}
if (input.numOldVersionsToDelete <= 0) {
console.log(
'Number of old versions to delete input is 0 or less, no versions will be deleted'

View File

@@ -47,23 +47,6 @@ export class Input {
this.ignoreVersions = validatedParams.ignoreVersions
this.deletePreReleaseVersions = validatedParams.deletePreReleaseVersions
this.token = validatedParams.token
if (
this.numOldVersionsToDelete > 1 &&
(this.minVersionsToKeep >= 0 || this.deletePreReleaseVersions == 'true')
) {
throwError('Invalid input combination')
}
if (this.deletePreReleaseVersions === 'true') {
this.minVersionsToKeep =
this.minVersionsToKeep > 0 ? this.minVersionsToKeep : 0
this.ignoreVersions = new RegExp('^(0|[1-9]\\d*)((\\.(0|[1-9]\\d*))*)$')
}
if (this.minVersionsToKeep >= 0) {
this.numOldVersionsToDelete = 0
}
}
hasOldestVersionQueryInfo(): boolean {
@@ -76,4 +59,25 @@ export class Input {
this.token
)
}
checkInput(): boolean {
if (
this.numOldVersionsToDelete > 1 &&
(this.minVersionsToKeep >= 0 || this.deletePreReleaseVersions === 'true')
) {
return false
}
if (this.deletePreReleaseVersions === 'true') {
this.minVersionsToKeep =
this.minVersionsToKeep > 0 ? this.minVersionsToKeep : 0
this.ignoreVersions = new RegExp('^(0|[1-9]\\d*)((\\.(0|[1-9]\\d*))*)$')
}
if (this.minVersionsToKeep >= 0) {
this.numOldVersionsToDelete = 0
}
return true
}
}