Merge pull request #4588 from andrewthauer/feat/catalog-import-codeowner

feat: support codeowners in catalog-import
This commit is contained in:
Fredrik Adelöw
2021-02-23 09:06:32 +01:00
committed by GitHub
3 changed files with 62 additions and 19 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-import': patch
---
Allows the CodeOwnersProcessor to set the owner automatically within the catalog-import plugin. This adds an additional checkbox that overrides the group selector and will omit the owner option in the generated catalog file yaml.
@@ -15,7 +15,15 @@
*/
import { ConfigApi } from '@backstage/core';
import { Box, StepLabel, TextField, Typography } from '@material-ui/core';
import {
Box,
Checkbox,
FormControlLabel,
FormHelperText,
StepLabel,
TextField,
Typography,
} from '@material-ui/core';
import React from 'react';
import { BackButton } from '../Buttons';
import { StepFinishImportLocation } from '../StepFinishImportLocation';
@@ -167,6 +175,7 @@ export function defaultGenerateStepper(
defaultTitle={title}
defaultBody={body}
renderFormFields={({
values,
control,
errors,
groupsLoading,
@@ -219,22 +228,47 @@ export function defaultGenerateStepper(
required
/>
<AutocompleteTextField
name="owner"
control={control}
errors={errors}
options={groups || []}
loading={groupsLoading}
loadingText="Loading groups…"
helperText="Select an owner from the list or enter a reference to a Group or a User"
errorHelperText="required value"
textFieldProps={{
label: 'Entity Owner',
placeholder: 'my-group',
}}
rules={{ required: true }}
required
{!values.useCodeowners && (
<AutocompleteTextField
name="owner"
control={control}
errors={errors}
options={groups || []}
loading={groupsLoading}
loadingText="Loading groups…"
helperText="Select an owner from the list or enter a reference to a Group or a User"
errorHelperText="required value"
textFieldProps={{
label: 'Entity Owner',
placeholder: 'my-group',
}}
rules={{ required: true }}
required
/>
)}
<FormControlLabel
control={
<Checkbox
name="useCodeowners"
inputRef={register}
onChange={(_, value) => {
if (value) {
control.setValue('owner', '');
}
}}
/>
}
label={
<>
Use <em>CODEOWNERS</em> file as Entity Owner
</>
}
/>
<FormHelperText>
WARNING: This may fail is no CODEOWNERS file is found at
the target location.
</FormHelperText>
</>
)}
/>
@@ -23,7 +23,7 @@ import {
import { Box, FormHelperText, Grid, Typography } from '@material-ui/core';
import { makeStyles } from '@material-ui/core/styles';
import React, { useCallback, useState } from 'react';
import { UseFormMethods } from 'react-hook-form';
import { UnpackNestedValue, UseFormMethods } from 'react-hook-form';
import { useAsync } from 'react-use';
import YAML from 'yaml';
import { AnalyzeResult, catalogImportApiRef } from '../../api';
@@ -48,6 +48,7 @@ type FormData = {
body: string;
componentName: string;
owner: string;
useCodeowners: boolean;
};
type Props = {
@@ -63,6 +64,7 @@ type Props = {
renderFormFields: (
props: Pick<UseFormMethods<FormData>, 'errors' | 'register' | 'control'> & {
values: UnpackNestedValue<FormData>;
groups: string[];
groupsLoading: boolean;
},
@@ -72,7 +74,7 @@ type Props = {
export function generateEntities(
entities: PartialEntity[],
componentName: string,
owner: string,
owner?: string,
): Entity[] {
return entities.map(e => ({
...e,
@@ -84,7 +86,7 @@ export function generateEntities(
},
spec: {
...e.spec,
owner,
...(owner ? { owner } : {}),
},
}));
}
@@ -189,10 +191,12 @@ export const StepPrepareCreatePullRequest = ({
(analyzeResult.generatedEntities[0]?.spec?.owner as string) || '',
componentName:
analyzeResult.generatedEntities[0]?.metadata?.name || '',
useCodeowners: false,
}}
render={({ values, errors, control, register }) => (
<>
{renderFormFields({
values,
errors,
register,
control,