remove config baseUrl

Signed-off-by: Andrew Johnson <ajohnson@gocardless.com>
This commit is contained in:
Andrew Johnson
2021-03-30 10:59:24 +01:00
parent 9286519051
commit f3f56dda8d
4 changed files with 8 additions and 33 deletions
+3 -12
View File
@@ -23,16 +23,7 @@ export AUTH_CLIENT_SECRET={{YOUR_CLIENT_SECRET}}
yarn add @backstage/plugin-github-deployments
```
3. If you use GitHub enterprise then set the host in `app-config.yaml`.
```yaml
# app-config.yaml
integrations:
github:
- host: { { YOUR_GITHUB_HOST_URL } }
```
4. Add the plugin to the app
3. Add the plugin to the app
```typescript
// packages/app/src/plugins.ts
@@ -40,7 +31,7 @@ integrations:
export { plugin as GithubDeployments } from '@backstage/plugin-github-deployments';
```
5. Add the `EntityGithubDeploymentsCard` to the EntityPage:
4. Add the `EntityGithubDeploymentsCard` to the EntityPage:
```typescript
// packages/app/src/components/catalog/EntityPage.tsx
@@ -58,7 +49,7 @@ const OverviewContent = () => (
);
```
6. Add the `github.com/project-slug` annotation to your `catalog-info.yaml` file:
5. Add the `github.com/project-slug` annotation to your `catalog-info.yaml` file:
```yaml
apiVersion: backstage.io/v1alpha1
+1 -13
View File
@@ -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', () => {
+3 -4
View File
@@ -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 }),
}),
],
});