Use @actions/[email protected] to invoke GraphQL for GHES compatibility

This commit is contained in:
eric sciple
2020-05-13 20:24:25 -04:00
parent 9bf8ee6742
commit f4a606f9ac
5 changed files with 82 additions and 68 deletions
+2 -3
View File
@@ -1,7 +1,7 @@
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'
import {graphql} from './graphql'
export interface DeletePackageVersionMutationResponse {
deletePackageVersion: {
@@ -21,10 +21,9 @@ export function deletePackageVersion(
token: string
): Observable<boolean> {
return from(
graphql(mutation, {
graphql(token, mutation, {
packageVersionId,
headers: {
authorization: `token ${token}`,
Accept: 'application/vnd.github.package-deletes-preview+json'
}
}) as Promise<DeletePackageVersionMutationResponse>
+2 -3
View File
@@ -1,7 +1,7 @@
import {graphql} from '@octokit/graphql'
import {GraphQlQueryResponse} from '@octokit/graphql/dist-types/types'
import {Observable, from, throwError} from 'rxjs'
import {catchError, map} from 'rxjs/operators'
import {graphql} from './graphql'
export interface VersionInfo {
id: string
@@ -52,13 +52,12 @@ export function queryForOldestVersions(
token: string
): Observable<GetVersionsQueryResponse> {
return from(
graphql(query, {
graphql(token, query, {
owner,
repo,
package: packageName,
last: numVersions,
headers: {
authorization: `token ${token}`,
Accept: 'application/vnd.github.packages-preview+json'
}
}) as Promise<GetVersionsQueryResponse>
+19
View File
@@ -0,0 +1,19 @@
import {GitHub} from '@actions/github'
import {GraphQlQueryResponseData} from '@octokit/graphql/dist-types/types'
import {RequestParameters} from '@octokit/types/dist-types/RequestParameters'
/**
* Sends a GraphQL query request based on endpoint options
*
* @param {string} token Auth token
* @param {string} query GraphQL query. Example: `'query { viewer { login } }'`.
* @param {object} parameters URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`.
*/
export async function graphql(
token: string,
query: string,
parameters: RequestParameters
): Promise<GraphQlQueryResponseData> {
const github = new GitHub(token)
return await github.graphql(query, parameters)
}