Skip to content

Commit 411b134

Browse files
committed
Custom Metadata Type records appear in the changelog
1 parent b162278 commit 411b134

File tree

9 files changed

+100
-21
lines changed

9 files changed

+100
-21
lines changed

examples/vitepress/docs/changelog.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,19 @@ Custom object for tracking sales orders.
7272
### Speaker__c
7373

7474
Represents a speaker at an event.
75-
### VisibleCMT__mdt
7675

7776
## New or Removed Fields to Custom Objects or Standard Objects
7877

7978
These custom fields have been added or removed.
8079

8180
### Contact
8281

83-
- New Field: PhotoUrl__c. URL of the contact's photo
82+
- New Field: PhotoUrl__c. URL of the contact's photo
83+
84+
## New or Removed Custom Metadata Type Records
85+
86+
These custom metadata type records have been added or removed.
87+
88+
### VisibleCMT__mdt
89+
90+
- New Custom Metadata Record: Some_Record_1
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<label>VisibleCMT</label>
4+
<pluralLabel>VisibleCMTs</pluralLabel>
5+
<visibility>Public</visibility>
6+
</CustomObject>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<fullName>Field1__c</fullName>
4+
<externalId>false</externalId>
5+
<fieldManageability>DeveloperControlled</fieldManageability>
6+
<label>Field1</label>
7+
<length>255</length>
8+
<required>true</required>
9+
<type>Text</type>
10+
<unique>false</unique>
11+
</CustomField>

src/application/Apexdocs.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,14 @@ async function processOpenApi(config: UserDefinedOpenApiConfig, logger: Logger)
7272
async function processChangeLog(config: UserDefinedChangelogConfig) {
7373
function loadFiles(): [UnparsedSourceBundle[], UnparsedSourceBundle[]] {
7474
return [
75-
readFiles(['ApexClass', 'CustomObject', 'CustomField'])(config.previousVersionDir, config.exclude),
76-
readFiles(['ApexClass', 'CustomObject', 'CustomField'])(config.currentVersionDir, config.exclude),
75+
readFiles(['ApexClass', 'CustomObject', 'CustomField', 'CustomMetadata'])(
76+
config.previousVersionDir,
77+
config.exclude,
78+
),
79+
readFiles(['ApexClass', 'CustomObject', 'CustomField', 'CustomMetadata'])(
80+
config.currentVersionDir,
81+
config.exclude,
82+
),
7783
];
7884
}
7985

src/core/changelog/generate-change-log.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { isInSource, isSkip, passThroughHook, skip, toFrontmatterString } from '
2121
import { reflectCustomFieldsAndObjectsAndMetadataRecords } from '../reflection/sobject/reflectCustomFieldsAndObjectsAndMetadataRecords';
2222
import { CustomObjectMetadata } from '../reflection/sobject/reflect-custom-object-sources';
2323
import { Type } from '@cparra/apex-reflection';
24-
import { filterApexSourceFiles, filterCustomObjectsAndFields } from '#utils/source-bundle-utils';
24+
import { filterApexSourceFiles, filterCustomObjectsFieldsAndMetadataRecords } from '#utils/source-bundle-utils';
2525
import { CustomFieldMetadata } from '../reflection/sobject/reflect-custom-field-source';
2626
import { hookableTemplate } from '../markdown/templates/hookable';
2727
import changelogToSourceChangelog from './helpers/changelog-to-source-changelog';
@@ -71,7 +71,7 @@ function reflect(bundles: UnparsedSourceBundle[], config: Omit<UserDefinedChange
7171
reflectApexFiles(filterApexSourceFiles(bundles)),
7272
TE.chain((parsedApexFiles) => {
7373
return pipe(
74-
reflectCustomFieldsAndObjectsAndMetadataRecords(filterCustomObjectsAndFields(bundles)),
74+
reflectCustomFieldsAndObjectsAndMetadataRecords(filterCustomObjectsFieldsAndMetadataRecords(bundles)),
7575
TE.map((parsedObjectFiles) => [...parsedApexFiles, ...parsedObjectFiles]),
7676
);
7777
}),

src/core/changelog/process-changelog.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ type ModificationTypes =
1919
| 'NewProperty'
2020
| 'RemovedProperty'
2121
| 'NewField'
22-
| 'RemovedField';
22+
| 'RemovedField'
23+
| 'NewCustomMetadataRecord'
24+
| 'RemovedCustomMetadataRecord';
2325

2426
export type MemberModificationType = {
2527
__typename: ModificationTypes;
@@ -106,7 +108,10 @@ function getNewOrModifiedApexMembers(oldVersion: VersionManifest, newVersion: Ve
106108
function getCustomObjectModifications(oldVersion: VersionManifest, newVersion: VersionManifest): NewOrModifiedMember[] {
107109
return pipe(
108110
getCustomObjectsInBothVersions(oldVersion, newVersion),
109-
(customObjectsInBoth) => getNewOrRemovedCustomFields(customObjectsInBoth),
111+
(customObjectsInBoth) => [
112+
...getNewOrRemovedCustomFields(customObjectsInBoth),
113+
...getNewOrRemovedCustomMetadataRecords(customObjectsInBoth),
114+
],
110115
(customObjectModifications) => customObjectModifications.filter((member) => member.modifications.length > 0),
111116
);
112117
}
@@ -180,6 +185,21 @@ function getNewOrRemovedCustomFields(typesInBoth: TypeInBoth<CustomObjectMetadat
180185
});
181186
}
182187

188+
function getNewOrRemovedCustomMetadataRecords(typesInBoth: TypeInBoth<CustomObjectMetadata>[]): NewOrModifiedMember[] {
189+
return typesInBoth.map(({ oldType, newType }) => {
190+
const oldCustomObject = oldType;
191+
const newCustomObject = newType;
192+
193+
return {
194+
typeName: newType.name,
195+
modifications: [
196+
...getNewValues(oldCustomObject, newCustomObject, 'metadataRecords', 'NewCustomMetadataRecord'),
197+
...getRemovedValues(oldCustomObject, newCustomObject, 'metadataRecords', 'RemovedCustomMetadataRecord'),
198+
],
199+
};
200+
});
201+
}
202+
183203
function getNewOrModifiedEnumValues(typesInBoth: TypeInBoth<Type>[]): NewOrModifiedMember[] {
184204
return pipe(
185205
typesInBoth.filter((typeInBoth): typeInBoth is TypeInBoth<EnumMirror> => typeInBoth.oldType.type_name === 'enum'),

src/core/changelog/renderable-changelog.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export type RenderableChangelog = {
4444
newCustomObjects: NewTypeSection<'customobject'> | null;
4545
removedCustomObjects: RemovedTypeSection | null;
4646
newOrRemovedCustomFields: NewOrModifiedMembersSection | null;
47+
newOrRemovedCustomMetadataTypeRecords: NewOrModifiedMembersSection | null;
4748
};
4849

4950
export function convertToRenderableChangelog(
@@ -60,6 +61,16 @@ export function convertToRenderableChangelog(
6061
const newCustomObjects = allNewTypes.filter(
6162
(type): type is CustomObjectMetadata => type.type_name === 'customobject',
6263
);
64+
const newOrModifiedCustomFields = changelog.customObjectModifications.filter(
65+
(modification): modification is NewOrModifiedMember =>
66+
modification.modifications.some((mod) => mod.__typename === 'NewField' || mod.__typename === 'RemovedField'),
67+
);
68+
const newOrModifiedCustomMetadataTypeRecords = changelog.customObjectModifications.filter(
69+
(modification): modification is NewOrModifiedMember =>
70+
modification.modifications.some(
71+
(mod) => mod.__typename === 'NewCustomMetadataRecord' || mod.__typename === 'RemovedCustomMetadataRecord',
72+
),
73+
);
6374

6475
return {
6576
newClasses:
@@ -122,11 +133,19 @@ export function convertToRenderableChangelog(
122133
}
123134
: null,
124135
newOrRemovedCustomFields:
125-
changelog.customObjectModifications.length > 0
136+
newOrModifiedCustomFields.length > 0
126137
? {
127138
heading: 'New or Removed Fields to Custom Objects or Standard Objects',
128139
description: 'These custom fields have been added or removed.',
129-
modifications: changelog.customObjectModifications.map(toRenderableModification),
140+
modifications: newOrModifiedCustomFields.map(toRenderableModification),
141+
}
142+
: null,
143+
newOrRemovedCustomMetadataTypeRecords:
144+
newOrModifiedCustomMetadataTypeRecords.length > 0
145+
? {
146+
heading: 'New or Removed Custom Metadata Type Records',
147+
description: 'These custom metadata type records have been added or removed.',
148+
modifications: newOrModifiedCustomMetadataTypeRecords.map(toRenderableModification),
130149
}
131150
: null,
132151
};
@@ -180,5 +199,9 @@ function toRenderableModificationDescription(memberModificationType: MemberModif
180199
return `New Type: ${withDescription(memberModificationType)}`;
181200
case 'RemovedType':
182201
return `Removed Type: ${memberModificationType.name}`;
202+
case 'NewCustomMetadataRecord':
203+
return `New Custom Metadata Record: ${withDescription(memberModificationType)}`;
204+
case 'RemovedCustomMetadataRecord':
205+
return `Removed Custom Metadata Record: ${memberModificationType.name}`;
183206
}
184207
}

src/core/changelog/templates/changelog-template.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,21 @@ export const changelogTemplate = `
9595
- {{this}}
9696
{{/each}}
9797
98+
{{/each}}
99+
{{/if}}
100+
101+
{{#if newOrRemovedCustomMetadataTypeRecords}}
102+
## {{newOrRemovedCustomMetadataTypeRecords.heading}}
103+
104+
{{newOrRemovedCustomMetadataTypeRecords.description}}
105+
106+
{{#each newOrRemovedCustomMetadataTypeRecords.modifications}}
107+
### {{this.typeName}}
108+
109+
{{#each this.modifications}}
110+
- {{this}}
111+
{{/each}}
112+
98113
{{/each}}
99114
{{/if}}
100115
`.trim();

src/util/source-bundle-utils.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
UnparsedApexBundle,
3-
UnparsedCustomFieldBundle, UnparsedCustomMetadataBundle,
3+
UnparsedCustomFieldBundle,
4+
UnparsedCustomMetadataBundle,
45
UnparsedCustomObjectBundle,
56
UnparsedSourceBundle,
67
} from '../core/shared/types';
@@ -9,16 +10,6 @@ export function filterApexSourceFiles(sourceFiles: UnparsedSourceBundle[]): Unpa
910
return sourceFiles.filter((sourceFile): sourceFile is UnparsedApexBundle => sourceFile.type === 'apex');
1011
}
1112

12-
// TODO: The changelog still uses this
13-
export function filterCustomObjectsAndFields(
14-
sourceFiles: UnparsedSourceBundle[],
15-
): (UnparsedCustomObjectBundle | UnparsedCustomFieldBundle)[] {
16-
return sourceFiles.filter(
17-
(sourceFile): sourceFile is UnparsedCustomObjectBundle =>
18-
sourceFile.type === 'customobject' || sourceFile.type === 'customfield',
19-
);
20-
}
21-
2213
export function filterCustomObjectsFieldsAndMetadataRecords(
2314
sourceFiles: UnparsedSourceBundle[],
2415
): (UnparsedCustomObjectBundle | UnparsedCustomFieldBundle | UnparsedCustomMetadataBundle)[] {

0 commit comments

Comments
 (0)