Skip to content

Commit 34361ce

Browse files
committed
Lists changed custom object labels.
1 parent 97cdded commit 34361ce

File tree

2 files changed

+69
-11
lines changed

2 files changed

+69
-11
lines changed

src/core/changelog/__test__/processing-changelog.spec.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@ function apexTypeFromRawString(raw: string): Type {
1212
}
1313

1414
class CustomObjectMetadataBuilder {
15+
label: string = 'MyObject';
16+
17+
withLabel(label: string): CustomObjectMetadataBuilder {
18+
this.label = label;
19+
return this;
20+
}
21+
1522
build(): CustomObjectMetadata {
1623
return {
1724
type_name: 'customobject',
1825
deploymentStatus: 'Deployed',
1926
visibility: 'Public',
20-
label: 'MyObject',
27+
label: this.label,
2128
name: 'MyObject',
2229
description: null,
2330
fields: [],
@@ -133,7 +140,27 @@ describe('when generating a changelog', () => {
133140
expect(changeLog.removedCustomObjects).toEqual([oldObject.name]);
134141
});
135142

136-
// [] - Lists changed object labels
143+
it('lists changed custom object labels', () => {
144+
const oldObject = new CustomObjectMetadataBuilder().withLabel('OldLabel').build();
145+
const newObject = new CustomObjectMetadataBuilder().withLabel('NewLabel').build();
146+
const oldVersion = { types: [oldObject] };
147+
const newVersion = { types: [newObject] };
148+
149+
const changeLog = processChangelog(oldVersion, newVersion);
150+
151+
expect(changeLog.customObjectModifications).toEqual([
152+
{
153+
typeName: oldObject.name,
154+
modifications: [
155+
{
156+
__typename: 'LabelChanged',
157+
name: 'NewLabel',
158+
},
159+
],
160+
},
161+
]);
162+
});
163+
137164
// [] - Lists all new fields of an object
138165
// [] - Lists all removed fields of an object
139166
// [] - Lists changed field labels

src/core/changelog/process-changelog.ts

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ type ModificationTypes =
1717
| 'NewProperty'
1818
| 'RemovedProperty'
1919
| 'NewField'
20-
| 'RemovedField';
20+
| 'RemovedField'
21+
| 'LabelChanged';
2122

2223
export type MemberModificationType = {
2324
__typename: ModificationTypes;
@@ -35,6 +36,7 @@ export type Changelog = {
3536
newOrModifiedApexMembers: NewOrModifiedMember[];
3637
newCustomObjects: string[];
3738
removedCustomObjects: string[];
39+
customObjectModifications: NewOrModifiedMember[];
3840
};
3941

4042
export function hasChanges(changelog: Changelog): boolean {
@@ -52,6 +54,7 @@ export function processChangelog(oldVersion: VersionManifest, newVersion: Versio
5254
newOrModifiedApexMembers: getNewOrModifiedApexMembers(oldVersion, newVersion),
5355
newCustomObjects: getNewCustomObjects(oldVersion, newVersion),
5456
removedCustomObjects: getRemovedCustomObjects(oldVersion, newVersion),
57+
customObjectModifications: getModifiedCustomObjectLabels(oldVersion, newVersion),
5558
};
5659
}
5760

@@ -95,7 +98,21 @@ function getNewOrModifiedApexMembers(oldVersion: VersionManifest, newVersion: Ve
9598
);
9699
}
97100

98-
function getNewOrModifiedEnumValues(typesInBoth: TypeInBoth[]): NewOrModifiedMember[] {
101+
function getModifiedCustomObjectLabels(
102+
oldVersion: VersionManifest,
103+
newVersion: VersionManifest,
104+
): NewOrModifiedMember[] {
105+
return pipe(getCustomObjectsInBothVersions(oldVersion, newVersion), (customObjectsInBoth) =>
106+
customObjectsInBoth
107+
.filter(({ oldType, newType }) => oldType.label.toLowerCase() !== newType.label.toLowerCase())
108+
.map(({ newType }) => ({
109+
typeName: newType.name,
110+
modifications: [{ __typename: 'LabelChanged', name: newType.label }],
111+
})),
112+
);
113+
}
114+
115+
function getNewOrModifiedEnumValues(typesInBoth: TypeInBoth<Type>[]): NewOrModifiedMember[] {
99116
return pipe(
100117
typesInBoth.filter((typeInBoth) => typeInBoth.oldType.type_name === 'enum'),
101118
(enumsInBoth) =>
@@ -113,7 +130,7 @@ function getNewOrModifiedEnumValues(typesInBoth: TypeInBoth[]): NewOrModifiedMem
113130
);
114131
}
115132

116-
function getNewOrModifiedMethods(typesInBoth: TypeInBoth[]): NewOrModifiedMember[] {
133+
function getNewOrModifiedMethods(typesInBoth: TypeInBoth<Type>[]): NewOrModifiedMember[] {
117134
return pipe(
118135
typesInBoth.filter(
119136
(typeInBoth) => typeInBoth.oldType.type_name === 'class' || typeInBoth.oldType.type_name === 'interface',
@@ -146,7 +163,7 @@ function getNewOrModifiedMethods(typesInBoth: TypeInBoth[]): NewOrModifiedMember
146163
);
147164
}
148165

149-
function getNewOrModifiedClassMembers(typesInBoth: TypeInBoth[]): NewOrModifiedMember[] {
166+
function getNewOrModifiedClassMembers(typesInBoth: TypeInBoth<Type>[]): NewOrModifiedMember[] {
150167
return pipe(
151168
typesInBoth.filter((typeInBoth) => typeInBoth.oldType.type_name === 'class'),
152169
(classesInBoth) =>
@@ -173,26 +190,40 @@ function getNewOrModifiedClassMembers(typesInBoth: TypeInBoth[]): NewOrModifiedM
173190
);
174191
}
175192

176-
type TypeInBoth = {
177-
oldType: Type;
178-
newType: Type;
193+
type TypeInBoth<T extends Type | CustomObjectMetadata> = {
194+
oldType: T;
195+
newType: T;
179196
};
180197

181-
function getApexTypesInBothVersions(oldVersion: VersionManifest, newVersion: VersionManifest): TypeInBoth[] {
198+
function getApexTypesInBothVersions(oldVersion: VersionManifest, newVersion: VersionManifest): TypeInBoth<Type>[] {
182199
return oldVersion.types
183200
.filter((newType): newType is Type => newType.type_name !== 'customobject')
184201
.map((oldType) => ({
185202
oldType,
186203
newType: newVersion.types.find((newType) => newType.name.toLowerCase() === oldType.name.toLowerCase()),
187204
}))
188-
.filter((type) => type.newType !== undefined) as TypeInBoth[];
205+
.filter((type): type is TypeInBoth<Type> => type.newType !== undefined);
206+
}
207+
208+
function getCustomObjectsInBothVersions(
209+
oldVersion: VersionManifest,
210+
newVersion: VersionManifest,
211+
): TypeInBoth<CustomObjectMetadata>[] {
212+
return oldVersion.types
213+
.filter((newType): newType is CustomObjectMetadata => newType.type_name === 'customobject')
214+
.map((oldType) => ({
215+
oldType,
216+
newType: newVersion.types.find((newType) => newType.name.toLowerCase() === oldType.name.toLowerCase()),
217+
}))
218+
.filter((type): type is TypeInBoth<CustomObjectMetadata> => type.newType !== undefined);
189219
}
190220

191221
type NameAware = {
192222
name: string;
193223
};
194224

195225
type AreEqualFn<T> = (oldValue: T, newValue: T) => boolean;
226+
196227
function areEqualByName<T extends NameAware>(oldValue: T, newValue: T): boolean {
197228
return oldValue.name.toLowerCase() === newValue.name.toLowerCase();
198229
}

0 commit comments

Comments
 (0)