Apply Code review fixes
This commit is contained in:
@@ -144,7 +144,7 @@ export async function createRouter(
|
||||
router.post('/analyze-location', async (req, res) => {
|
||||
const input = await validateRequestBody(req, analyzeLocationSchema);
|
||||
const output = await locationAnalyzer.generateConfig(input);
|
||||
res.status(201).send(output);
|
||||
res.status(200).send(output);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@backstage/plugin-catalog-import",
|
||||
"version": "0.1.1-alpha.26",
|
||||
"version": "0.2.0",
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
"license": "Apache-2.0",
|
||||
@@ -21,11 +21,11 @@
|
||||
"clean": "backstage-cli clean"
|
||||
},
|
||||
"dependencies": {
|
||||
"@backstage/catalog-model": "^0.1.1-alpha.26",
|
||||
"@backstage/core": "^0.1.1-alpha.26",
|
||||
"@backstage/plugin-catalog": "^0.1.1-alpha.26",
|
||||
"@backstage/plugin-catalog-backend": "^0.1.1-alpha.26",
|
||||
"@backstage/theme": "^0.1.1-alpha.26",
|
||||
"@backstage/catalog-model": "^0.2.0",
|
||||
"@backstage/core": "^0.2.0",
|
||||
"@backstage/plugin-catalog": "^0.2.0",
|
||||
"@backstage/plugin-catalog-backend": "^0.2.0",
|
||||
"@backstage/theme": "^0.2.0",
|
||||
"@material-ui/core": "^4.11.0",
|
||||
"@material-ui/icons": "^4.9.1",
|
||||
"@material-ui/lab": "4.0.0-alpha.45",
|
||||
|
||||
@@ -24,7 +24,6 @@ export const catalogImportApiRef = createApiRef<CatalogImportApi>({
|
||||
|
||||
export interface CatalogImportApi {
|
||||
submitPrToRepo(options: {
|
||||
oAuthToken: string;
|
||||
owner: string;
|
||||
repo: string;
|
||||
fileContent: string;
|
||||
|
||||
@@ -15,16 +15,26 @@
|
||||
*/
|
||||
|
||||
import { Octokit } from '@octokit/rest';
|
||||
import { DiscoveryApi } from '@backstage/core';
|
||||
import {
|
||||
DiscoveryApi,
|
||||
githubAuthApiRef,
|
||||
OAuthApi,
|
||||
useApi,
|
||||
} from '@backstage/core';
|
||||
import { CatalogImportApi } from './CatalogImportApi';
|
||||
import { AnalyzeLocationResponse } from '@backstage/plugin-catalog-backend';
|
||||
import { PartialEntity } from '../util/types';
|
||||
|
||||
export class CatalogImportClient implements CatalogImportApi {
|
||||
private readonly discoveryApi: DiscoveryApi;
|
||||
private readonly githubAuthApi: OAuthApi;
|
||||
|
||||
constructor(options: { discoveryApi: DiscoveryApi }) {
|
||||
constructor(options: {
|
||||
discoveryApi: DiscoveryApi;
|
||||
githubAuthApi: OAuthApi;
|
||||
}) {
|
||||
this.discoveryApi = options.discoveryApi;
|
||||
this.githubAuthApi = options.githubAuthApi;
|
||||
}
|
||||
|
||||
async generateEntityDefinitions({
|
||||
@@ -83,18 +93,18 @@ export class CatalogImportClient implements CatalogImportApi {
|
||||
}
|
||||
|
||||
async submitPrToRepo({
|
||||
oAuthToken,
|
||||
owner,
|
||||
repo,
|
||||
fileContent,
|
||||
}: {
|
||||
oAuthToken: string;
|
||||
owner: string;
|
||||
repo: string;
|
||||
fileContent: string;
|
||||
}): Promise<{ link: string; location: string }> {
|
||||
const token = await this.githubAuthApi.getAccessToken(['repo']);
|
||||
|
||||
const octo = new Octokit({
|
||||
auth: oAuthToken,
|
||||
auth: token,
|
||||
});
|
||||
|
||||
const branchName = 'backstage-integration';
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
createPlugin,
|
||||
createRouteRef,
|
||||
discoveryApiRef,
|
||||
githubAuthApiRef,
|
||||
} from '@backstage/core';
|
||||
import { catalogImportApiRef } from './api/CatalogImportApi';
|
||||
import { CatalogImportClient } from './api/CatalogImportClient';
|
||||
@@ -33,8 +34,9 @@ export const plugin = createPlugin({
|
||||
apis: [
|
||||
createApiFactory({
|
||||
api: catalogImportApiRef,
|
||||
deps: { discoveryApi: discoveryApiRef },
|
||||
factory: ({ discoveryApi }) => new CatalogImportClient({ discoveryApi }),
|
||||
deps: { discoveryApi: discoveryApiRef, githubAuthApi: githubAuthApiRef },
|
||||
factory: ({ discoveryApi, githubAuthApi }) =>
|
||||
new CatalogImportClient({ discoveryApi, githubAuthApi }),
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
@@ -15,21 +15,17 @@
|
||||
*/
|
||||
|
||||
import * as YAML from 'yaml';
|
||||
import { useApi, githubAuthApiRef } from '@backstage/core';
|
||||
import { useApi } from '@backstage/core';
|
||||
import { catalogImportApiRef } from '../api/CatalogImportApi';
|
||||
import { ConfigSpec } from '../components/ImportComponentPage';
|
||||
|
||||
export function useGithubRepos() {
|
||||
const api = useApi(catalogImportApiRef);
|
||||
const auth = useApi(githubAuthApiRef);
|
||||
|
||||
const submitPrToRepo = async (selectedRepo: ConfigSpec) => {
|
||||
const token = await auth.getAccessToken(['repo']);
|
||||
|
||||
const [ownerName, repoName] = selectedRepo.location.split('/').slice(-2);
|
||||
const submitPRResponse = await api
|
||||
.submitPrToRepo({
|
||||
oAuthToken: token,
|
||||
owner: ownerName,
|
||||
repo: repoName,
|
||||
fileContent: selectedRepo.config
|
||||
|
||||
Reference in New Issue
Block a user