Skip to content

Commit

Permalink
feat: update repository content types (#149)
Browse files Browse the repository at this point in the history
This change updates the repository content types renaming Blueprints to Team Blueprints, adding Organizational Blueprints, and renaming Catalog Blueprints to External Blueprints.
  • Loading branch information
ChristopherFry committed Sep 22, 2022
1 parent d5dbfdc commit 4b6da05
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
getRepositoryOciDetails,
getRepositoryResource,
getSecretRef,
PackageContentSummaryOrder,
} from '../../utils/repository';
import { getBasicAuthSecret, isBasicAuthSecret } from '../../utils/secret';
import { Select } from '../Controls/Select';
Expand Down Expand Up @@ -224,7 +225,7 @@ export const RegisterRepositoryPage = () => {
}

for (const contentSummary of Object.values(ContentSummary)) {
if (repositoryUrl.includes(contentSummary.toLocaleLowerCase('en-US'))) {
if (repositoryUrl.includes(kebabCase(contentSummary))) {
toSet.contentSummary = contentSummary;
}
}
Expand Down Expand Up @@ -264,20 +265,12 @@ export const RegisterRepositoryPage = () => {
};

const repositoryContentSelectItems = useMemo(() => {
const selectItems: SelectItem[] = [
{
label: 'Catalog Blueprints',
value: ContentSummary.CATALOG_BLUEPRINT,
},
{
label: 'Blueprints',
value: ContentSummary.BLUEPRINT,
},
{
label: 'Deployments',
value: ContentSummary.DEPLOYMENT,
},
];
const selectItems: SelectItem[] = PackageContentSummaryOrder.map(
contentType => ({
label: `${contentType}s`,
value: contentType,
}),
);

if (allowFunctionRepositoryRegistration()) {
selectItems.push({
Expand Down
54 changes: 37 additions & 17 deletions plugins/cad/src/utils/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,26 @@ type ContentDetails = {
type ContentDetail = {
repositoryContent: RepositoryContent;
isDeployment?: boolean;
expectedLabel?: string;
repositoryContentLabelValue?: string;
notContent?: ContentSummary[];
cloneTo: ContentSummary[];
};

const CATALOG_BLUEPRINT_REPOSITORY_LABEL =
'kpt.dev/catalog-blueprint-repository';
const REPOSITORY_CONTENT_LABEL = 'kpt.dev/repository-content';

export enum ContentSummary {
CATALOG_BLUEPRINT = 'Catalog Blueprint',
BLUEPRINT = 'Blueprint',
EXTERNAL_BLUEPRINT = 'External Blueprint',
ORGANIZATIONAL_BLUEPRINT = 'Organizational Blueprint',
TEAM_BLUEPRINT = 'Team Blueprint',
DEPLOYMENT = 'Deployment',
FUNCTION = 'Function',
}

export const PackageContentSummaryOrder = [
ContentSummary.DEPLOYMENT,
ContentSummary.BLUEPRINT,
ContentSummary.CATALOG_BLUEPRINT,
ContentSummary.TEAM_BLUEPRINT,
ContentSummary.ORGANIZATIONAL_BLUEPRINT,
ContentSummary.EXTERNAL_BLUEPRINT,
];

export const isFunctionRepository = (repository: Repository): boolean => {
Expand All @@ -70,15 +71,32 @@ export const RepositoryContentDetails: ContentDetails = {
isDeployment: true,
cloneTo: [],
},
[ContentSummary.BLUEPRINT]: {
[ContentSummary.TEAM_BLUEPRINT]: {
repositoryContent: RepositoryContent.PACKAGE,
notContent: [ContentSummary.CATALOG_BLUEPRINT],
cloneTo: [ContentSummary.DEPLOYMENT],
notContent: [
ContentSummary.ORGANIZATIONAL_BLUEPRINT,
ContentSummary.EXTERNAL_BLUEPRINT,
],
cloneTo: [ContentSummary.DEPLOYMENT, ContentSummary.TEAM_BLUEPRINT],
},
[ContentSummary.CATALOG_BLUEPRINT]: {
[ContentSummary.ORGANIZATIONAL_BLUEPRINT]: {
repositoryContent: RepositoryContent.PACKAGE,
expectedLabel: CATALOG_BLUEPRINT_REPOSITORY_LABEL,
cloneTo: [ContentSummary.BLUEPRINT],
repositoryContentLabelValue: 'organizational-blueprints',
cloneTo: [
ContentSummary.DEPLOYMENT,
ContentSummary.TEAM_BLUEPRINT,
ContentSummary.ORGANIZATIONAL_BLUEPRINT,
],
},
[ContentSummary.EXTERNAL_BLUEPRINT]: {
repositoryContent: RepositoryContent.PACKAGE,
repositoryContentLabelValue: 'external-blueprints',
cloneTo: [
ContentSummary.DEPLOYMENT,
ContentSummary.TEAM_BLUEPRINT,
ContentSummary.ORGANIZATIONAL_BLUEPRINT,
ContentSummary.EXTERNAL_BLUEPRINT,
],
},
[ContentSummary.FUNCTION]: {
repositoryContent: RepositoryContent.FUNCTION,
Expand All @@ -97,8 +115,9 @@ const isRepositoryContent = (
const isDeploymentMatch =
!!repository.spec.deployment === !!repositoryDetails.isDeployment;
const isLabelMatch =
!repositoryDetails.expectedLabel ||
!!repository.metadata.labels?.[repositoryDetails.expectedLabel];
!repositoryDetails.repositoryContentLabelValue ||
repository.metadata.labels?.[REPOSITORY_CONTENT_LABEL] ===
repositoryDetails.repositoryContentLabelValue;

const notContent = repositoryDetails.notContent ?? [];
const noDisqualifiers = !notContent
Expand Down Expand Up @@ -170,8 +189,9 @@ export const getRepositoryResource = (

const labels: KubernetesKeyValueObject = {};

if (contentDetails.expectedLabel) {
labels[contentDetails.expectedLabel] = 'true';
if (contentDetails.repositoryContentLabelValue) {
labels[REPOSITORY_CONTENT_LABEL] =
contentDetails.repositoryContentLabelValue;
}

const resource: Repository = {
Expand Down

0 comments on commit 4b6da05

Please sign in to comment.