remove config baseUrl
Signed-off-by: Andrew Johnson <ajohnson@gocardless.com>
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { ConfigApi, createApiRef, OAuthApi } from '@backstage/core';
|
||||
import { createApiRef, OAuthApi } from '@backstage/core';
|
||||
import { graphql } from '@octokit/graphql';
|
||||
|
||||
export type GithubDeployment = {
|
||||
@@ -40,7 +40,6 @@ export const githubDeploymentsApiRef = createApiRef<GithubDeploymentsApi>({
|
||||
});
|
||||
|
||||
export type Options = {
|
||||
configApi: ConfigApi;
|
||||
githubAuthApi: OAuthApi;
|
||||
};
|
||||
|
||||
@@ -71,31 +70,20 @@ export type QueryResponse = {
|
||||
};
|
||||
|
||||
export class GithubDeploymentsApiClient implements GithubDeploymentsApi {
|
||||
private readonly configApi: ConfigApi;
|
||||
private readonly githubAuthApi: OAuthApi;
|
||||
|
||||
constructor(options: Options) {
|
||||
this.configApi = options.configApi;
|
||||
this.githubAuthApi = options.githubAuthApi;
|
||||
}
|
||||
|
||||
private getBaseUrl() {
|
||||
const providerConfigs =
|
||||
this.configApi.getOptionalConfigArray('integrations.github') ?? [];
|
||||
const targetProviderConfig = providerConfigs[0];
|
||||
return targetProviderConfig?.getOptionalString('apiBaseUrl');
|
||||
}
|
||||
|
||||
async listDeployments(options: {
|
||||
owner: string;
|
||||
repo: string;
|
||||
last: number;
|
||||
}): Promise<GithubDeployment[]> {
|
||||
const token = await this.githubAuthApi.getAccessToken(['repo']);
|
||||
const baseUrl = this.getBaseUrl() || 'https://api.github.com';
|
||||
|
||||
const graphQLWithAuth = graphql.defaults({
|
||||
baseUrl,
|
||||
headers: {
|
||||
authorization: `token ${token}`,
|
||||
},
|
||||
|
||||
@@ -50,10 +50,7 @@ const githubAuthApi: OAuthApi = {
|
||||
const apis = ApiRegistry.from([
|
||||
[configApiRef, configApi],
|
||||
[errorApiRef, errorApiMock],
|
||||
[
|
||||
githubDeploymentsApiRef,
|
||||
new GithubDeploymentsApiClient({ configApi, githubAuthApi }),
|
||||
],
|
||||
[githubDeploymentsApiRef, new GithubDeploymentsApiClient({ githubAuthApi })],
|
||||
]);
|
||||
|
||||
describe('github-deployments', () => {
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import {
|
||||
configApiRef,
|
||||
createApiFactory,
|
||||
createComponentExtension,
|
||||
createPlugin,
|
||||
@@ -27,9 +26,9 @@ export const githubDeploymentsPlugin = createPlugin({
|
||||
apis: [
|
||||
createApiFactory({
|
||||
api: githubDeploymentsApiRef,
|
||||
deps: { configApi: configApiRef, githubAuthApi: githubAuthApiRef },
|
||||
factory: ({ configApi, githubAuthApi }) =>
|
||||
new GithubDeploymentsApiClient({ configApi, githubAuthApi }),
|
||||
deps: { githubAuthApi: githubAuthApiRef },
|
||||
factory: ({ githubAuthApi }) =>
|
||||
new GithubDeploymentsApiClient({ githubAuthApi }),
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user