Releases/v1 (#1)
* delete package versions action v1 * updated action for build and smoke test * test and error message update * test fix * ci testing * ci testing * ci testing * ci testing * ci test * ci testing * ci test name * docs * docs * docs * test * test * test * docs * usage doc * doc * docs * format test * doc update * doc test * formatting check * scenario update * usage update * format * test * test * test * test * test * table test * test * format update * links * test * test * test * test * test * docs update * test * formatting * fix broken links * doc update * test * table test * test * test * test * test * test * test * test * test * test * test * doc test * test * test * test * test * test * test * test t * test * test * test * test * test * test * docs * doc update
This commit is contained in:
66
src/version/delete-version.ts
Normal file
66
src/version/delete-version.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import {from, Observable, merge, throwError, of} from 'rxjs'
|
||||
import {graphql} from '@octokit/graphql'
|
||||
import {catchError, map, tap} from 'rxjs/operators'
|
||||
import {GraphQlQueryResponse} from '@octokit/graphql/dist-types/types'
|
||||
|
||||
export interface DeletePackageVersionMutationResponse {
|
||||
deletePackageVersion: {
|
||||
success: boolean
|
||||
}
|
||||
}
|
||||
|
||||
const mutation = `
|
||||
mutation deletePackageVersion($packageVersionId: String!) {
|
||||
deletePackageVersion(input: {packageVersionId: $packageVersionId}) {
|
||||
success
|
||||
}
|
||||
}`
|
||||
|
||||
export function deletePackageVersion(
|
||||
packageVersionId: string,
|
||||
token: string
|
||||
): Observable<boolean> {
|
||||
return from(
|
||||
graphql(mutation, {
|
||||
packageVersionId,
|
||||
headers: {
|
||||
authorization: `token ${token}`,
|
||||
Accept: 'application/vnd.github.package-deletes-preview+json'
|
||||
}
|
||||
}) as Promise<DeletePackageVersionMutationResponse>
|
||||
).pipe(
|
||||
catchError((err: GraphQlQueryResponse) => {
|
||||
const msg = 'delete version mutation failed.'
|
||||
return throwError(
|
||||
err.errors && err.errors.length > 0
|
||||
? `${msg} ${err.errors[0].message}`
|
||||
: `${msg} verify input parameters are correct`
|
||||
)
|
||||
}),
|
||||
map(response => response.deletePackageVersion.success)
|
||||
)
|
||||
}
|
||||
|
||||
export function deletePackageVersions(
|
||||
packageVersionIds: string[],
|
||||
token: string
|
||||
): Observable<boolean> {
|
||||
if (packageVersionIds.length === 0) {
|
||||
console.log('no package version ids found, no versions will be deleted')
|
||||
return of(true)
|
||||
}
|
||||
|
||||
const deletes = packageVersionIds.map(id =>
|
||||
deletePackageVersion(id, token).pipe(
|
||||
tap(result => {
|
||||
if (result) {
|
||||
console.log(`version with id: ${id}, deleted`)
|
||||
} else {
|
||||
console.log(`version with id: ${id}, not deleted`)
|
||||
}
|
||||
})
|
||||
)
|
||||
)
|
||||
|
||||
return merge(...deletes)
|
||||
}
|
||||
Reference in New Issue
Block a user