Skip to content

Commit

Permalink
fix: handle potentially missing author org & email info
Browse files Browse the repository at this point in the history
  • Loading branch information
aripalo committed May 14, 2022
1 parent 1e480aa commit 65e6a59
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
8 changes: 5 additions & 3 deletions src/smartstack/tags/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Tags } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { excludeSpecials } from './exclude';
import { tagAccount, tagEnvironment, tagProject, tagAuthorInfo } from './taggers';
import { tagAccount, tagEnvironment, tagProject, tagAuthorEmail, tagAuthorName, tagAuthorOrganization } from './taggers';
import { resolveTagValues } from './values';

function getTags(scope: Construct): Tags {
Expand All @@ -15,6 +15,8 @@ export function addTags(scope: Construct): void {
tagAccount(scope, tags, values);
tagEnvironment(scope, tags, values);
tagProject(scope, tags, values);
tagAuthorInfo(scope, tags, values);
tagAuthorName(scope, tags, values);
tagAuthorOrganization(scope, tags, values);
tagAuthorEmail(scope, tags, values);
excludeSpecials(tags);
}
}
23 changes: 17 additions & 6 deletions src/smartstack/tags/taggers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Tags } from 'aws-cdk-lib';
import { capitalCase, pascalCase } from 'change-case';
import { Construct } from 'constructs';
import { isSet } from 'lodash';
import { hasAccount, hasEnvironment, useLegacyTags } from './checks';
import { tagKey, Values } from './values';

Expand All @@ -10,18 +11,18 @@ interface Tagger {

export const tagAccount: Tagger = (_: Construct, tags: Tags, values: Values) => {
if (hasAccount(values)) {
tags.add(tagKey.ACCOUNT, values.accountType);
tags.add(tagKey.ACCOUNT, values.accountType!);
}
};

export const tagEnvironment: Tagger = (scope: Construct, tags: Tags, values: Values) => {
if (hasEnvironment(values)) {
tags.add(tagKey.ENVIRONMENT, values.environmentType);
tags.add(tagKey.ENVIRONMENT, values.environmentType!);

if (useLegacyTags(scope)) {
tags.add(
tagKey.LEGACY_PROJECT_ENVIRONMENT,
`${pascalCase(values.projectName)}${pascalCase(values.environmentType)}`,
`${pascalCase(values.projectName)}${pascalCase(values.environmentType!)}`,
);
}
}
Expand All @@ -35,8 +36,18 @@ export const tagProject: Tagger = (scope: Construct, tags: Tags, values: Values)
tags.add(tagKey.PROJECT, value);
};

export const tagAuthorInfo: Tagger = (scope: Construct, tags: Tags, values: Values) => {
export const tagAuthorName: Tagger = (_: Construct, tags: Tags, values: Values) => {
tags.add(tagKey.AUTHOR_NAME, values.authorName);
tags.add(tagKey.AUTHOR_ORGANIZATION, values.authorOrganization);
tags.add(tagKey.AUTHOR_EMAIL, values.authorEmail);
};

export const tagAuthorOrganization: Tagger = (_: Construct, tags: Tags, values: Values) => {
if (isSet(values.authorOrganization)) {
tags.add(tagKey.AUTHOR_ORGANIZATION, values.authorOrganization);
}
};

export const tagAuthorEmail: Tagger = (_: Construct, tags: Tags, values: Values) => {
if (isSet(values.authorEmail)) {
tags.add(tagKey.AUTHOR_EMAIL, values.authorEmail);
}
};
4 changes: 2 additions & 2 deletions src/smartstack/tags/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export interface Values {
environmentType?: string;
projectName: string;
authorName: string;
authorOrganization: string;
authorEmail: string;
authorOrganization?: string;
authorEmail?: string;
}

export enum tagKey {
Expand Down

0 comments on commit 65e6a59

Please sign in to comment.