GitHub - refactor branch protection (#181880)

* GitHub - rewrite to use GraphQL instead of REST

* Add paging
This commit is contained in:
Ladislau Szomoru
2023-05-09 13:14:54 +02:00
committed by GitHub
parent 0c85b95c48
commit a54b497150
4 changed files with 164 additions and 157 deletions

View File

@@ -5,6 +5,7 @@
import { AuthenticationSession, authentication, window } from 'vscode';
import { Agent, globalAgent } from 'https';
import { graphql } from '@octokit/graphql/dist-types/types';
import { Octokit } from '@octokit/rest';
import { httpsOverHttp } from 'tunnel';
import { URL } from 'url';
@@ -53,3 +54,29 @@ export function getOctokit(): Promise<Octokit> {
return _octokit;
}
let _octokitGraphql: Promise<graphql> | undefined;
export function getOctokitGraphql(): Promise<graphql> {
if (!_octokitGraphql) {
_octokitGraphql = getSession()
.then(async session => {
const token = session.accessToken;
const { graphql } = await import('@octokit/graphql');
return graphql.defaults({
headers: {
authorization: `token ${token}`
},
request: {
agent: getAgent()
}
});
}).then(null, async err => {
_octokitGraphql = undefined;
throw err;
});
}
return _octokitGraphql;
}