Skip to content

Commit aaf9962

Browse files
committed
šŸ› fix(triggers): suppress duplicate server name in notification prefix and suffix (#283)
- getNotificationWatcherSuffix now accepts the resolved prefix and server name; when a prefix is present and the watcher matches that server identity (case-insensitive), the suffix is suppressed - Extract getNotificationServerName helper to derive identity once - Distinct watcher names still render: [prod-server] Container nginx (servicevault) - 🧪 Regression tests for duplicated agent case and duplicated controller case
1 parent 2f511d3 commit aaf9962

File tree

2 files changed

+61
-6
lines changed

2 files changed

+61
-6
lines changed

ā€Žapp/triggers/providers/Trigger.test.tsā€Ž

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,6 +2123,43 @@ test('renderSimpleBody should combine agent prefix and watcher suffix', () => {
21232123
);
21242124
});
21252125

2126+
test('renderSimpleBody should omit watcher suffix when it matches the agent prefix', () => {
2127+
const { simplebody, ...rest } = configurationValid;
2128+
trigger.configuration = trigger.validateConfiguration(rest);
2129+
expect(
2130+
trigger.renderSimpleBody({
2131+
name: 'nginx',
2132+
agent: 'mediavault',
2133+
watcher: 'mediavault',
2134+
updateKind: {
2135+
kind: 'tag',
2136+
localValue: '1.0.0',
2137+
remoteValue: '2.0.0',
2138+
},
2139+
}),
2140+
).toBe('[mediavault] Container nginx running with tag 1.0.0 can be updated to tag 2.0.0');
2141+
});
2142+
2143+
test('renderSimpleBody should omit watcher suffix when it matches the controller prefix', () => {
2144+
const { simplebody, ...rest } = configurationValid;
2145+
trigger.configuration = trigger.validateConfiguration(rest);
2146+
mockGetAgents.mockReturnValue([{ name: 'remote-1' }]);
2147+
2148+
expect(
2149+
trigger.renderSimpleBody({
2150+
name: 'nginx',
2151+
watcher: 'controller-host',
2152+
updateKind: {
2153+
kind: 'tag',
2154+
localValue: '1.0.0',
2155+
remoteValue: '2.0.0',
2156+
},
2157+
}),
2158+
).toBe('[controller-host] Container nginx running with tag 1.0.0 can be updated to tag 2.0.0');
2159+
2160+
mockGetAgents.mockReturnValue([]);
2161+
});
2162+
21262163
test('renderBatchBody should include agent prefix per container in batch', () => {
21272164
const { simplebody, ...rest } = configurationValid;
21282165
trigger.configuration = trigger.validateConfiguration(rest);

ā€Žapp/triggers/providers/Trigger.tsā€Ž

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,11 +1602,28 @@ class Trigger extends Component {
16021602
* Build the container template context used by trigger body/title rendering.
16031603
* Release notes bodies are shortened for notifications to avoid excessively long payloads.
16041604
*/
1605-
private getNotificationWatcherSuffix(container: Container): string {
1605+
private getNotificationServerName(container: Container): string {
1606+
const agent = typeof container.agent === 'string' ? container.agent.trim() : '';
1607+
return agent || getServerName();
1608+
}
1609+
1610+
private getNotificationWatcherSuffix(
1611+
container: Container,
1612+
notificationAgentPrefix: string,
1613+
notificationServerName: string,
1614+
): string {
16061615
const watcher = typeof container.watcher === 'string' ? container.watcher.trim() : '';
16071616
if (!watcher || watcher === 'local' || watcher === 'agent') {
16081617
return '';
16091618
}
1619+
1620+
if (
1621+
notificationAgentPrefix &&
1622+
watcher.toLowerCase() === notificationServerName.trim().toLowerCase()
1623+
) {
1624+
return '';
1625+
}
1626+
16101627
return ` (${watcher})`;
16111628
}
16121629

@@ -1622,12 +1639,13 @@ class Trigger extends Component {
16221639
}
16231640

16241641
private getTemplateContainer(container: Container): TriggerTemplateContainer {
1625-
const notificationWatcherSuffix = this.getNotificationWatcherSuffix(container);
16261642
const notificationAgentPrefix = this.getNotificationAgentPrefix(container);
1627-
const notificationServerName =
1628-
typeof container.agent === 'string' && container.agent.trim()
1629-
? container.agent.trim()
1630-
: getServerName();
1643+
const notificationServerName = this.getNotificationServerName(container);
1644+
const notificationWatcherSuffix = this.getNotificationWatcherSuffix(
1645+
container,
1646+
notificationAgentPrefix,
1647+
notificationServerName,
1648+
);
16311649
const releaseNotes = container.result?.releaseNotes;
16321650
if (!releaseNotes || typeof releaseNotes.body !== 'string') {
16331651
return {

0 commit comments

Comments
Ā (0)