Skip to content

Commit 1dfa6ec

Browse files
committed
feat: Added exceptions feature
1 parent ebab3e2 commit 1dfa6ec

File tree

7 files changed

+69
-2
lines changed

7 files changed

+69
-2
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ A table of maintainers for pages.
5252
- Maintainer: The users that should receive all notifications for pages matching this pattern (separated by ,). You can
5353
use `_lastauthor` to reference the last author of the page)
5454

55+
### Panel "Exceptions"
56+
57+
A list of regular expressions that are matched against all document paths. If a pattern matches, that document will be
58+
excluded from notifications.
59+
5560
### Panel "Notification Template"
5661

5762
This panel includes two child panels which hold [Handlebars](https://handlebarsjs.com/guide/) templates for the

lib/api/Configuration.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ export class Configuration {
5757
/**
5858
* A list of checks for outdated documents
5959
*/
60-
public checks: Array<Check>
60+
public checks: Array<Check> = []
61+
62+
/**
63+
* An array of regular expressions for document paths that should not be notified
64+
*/
65+
public exceptions: Array<RegExp> = []
6166

6267
/**
6368
* A list of page maintainers
@@ -89,7 +94,6 @@ export class Configuration {
8994
this.confluenceUser = confluenceUser
9095
this.confluencePassword = confluencePassword
9196
this.configurationDocumentId = configurationDocumentId
92-
this.checks = []
9397
this._loaded = false
9498

9599
this._log = log.getLogger('Configuration')
@@ -172,6 +176,10 @@ export class Configuration {
172176
}
173177
})
174178

179+
// Load exceptions
180+
181+
this.exceptions = this._getConfigurationFromPanel($, 'Exceptions').map<RegExp>((value) => new RegExp(value.regularexpression))
182+
175183
this.notificationSubjectTemplate = $(
176184
'ac\\:parameter:contains("Notification Template") + ac\\:rich-text-body ac\\:parameter:contains("Subject") + ac\\:rich-text-body'
177185
).text()

lib/api/Notification.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Logger } from 'loglevel'
88
import { Moment } from 'moment'
99
import log = require('loglevel')
1010
import moment = require('moment')
11+
import doc = Mocha.reporters.doc
1112

1213
export class Notification {
1314
private _configuration: Configuration
@@ -26,6 +27,13 @@ export class Notification {
2627
}
2728

2829
public async notify(documentInfo: DocumentInfo): Promise<void> {
30+
for (const exception of this._configuration.exceptions) {
31+
if (documentInfo.matchesPath(exception)) {
32+
this._log.info(`Skipping ${documentInfo.title} because it matches the exception ${exception}`)
33+
return
34+
}
35+
}
36+
2937
Handlebars.registerHelper('moment', (text, format) => {
3038
return moment(text).format(format)
3139
})

resources/configurationDocument.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,26 @@
6767
</table>
6868
</ac:rich-text-body>
6969
</ac:structured-macro>
70+
<ac:structured-macro ac:name="panel" ac:schema-version="1" ac:macro-id="1d192d60-7e69-4af8-8dd6-4006a7bfc952">
71+
<ac:parameter ac:name="title">Exceptions</ac:parameter>
72+
<ac:rich-text-body>
73+
<i>This table holds a list of RegExp patterns. A document which path matches one of this pattern will be excluded from notifications.</i>
74+
<table class="wrapped">
75+
<colgroup>
76+
<col/>
77+
<col/>
78+
</colgroup>
79+
<tbody>
80+
<tr>
81+
<th>RegularException</th>
82+
</tr>
83+
<tr>
84+
<td></td>
85+
</tr>
86+
</tbody>
87+
</table>
88+
</ac:rich-text-body>
89+
</ac:structured-macro>
7090
<ac:structured-macro ac:name="panel" ac:schema-version="1" ac:macro-id="93f1d981-c841-4cb4-b6e2-5940dfe69132">
7191
<ac:parameter ac:name="title">Notification Template</ac:parameter>
7292
<ac:rich-text-body>

test/ConfigurationTest.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ describe('The Configuration API', (): void => {
2121

2222
chai.expect(configuration.maintainer).to.have.lengthOf(1)
2323

24+
chai.expect(configuration.exceptions).to.have.lengthOf(1)
25+
2426
chai.expect(configuration.notificationBodyTemplate).to.eq(MockServer.NOTIFICATION_BODY)
2527
chai.expect(configuration.notificationSubjectTemplate).to.eq(MockServer.NOTIFICATION_SUBJECT)
2628

test/MockServer.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,24 @@ export class MockServer {
124124
</table>
125125
</ac:rich-text-body>
126126
</ac:structured-macro>
127+
<ac:structured-macro ac:name='panel' ac:schema-version='1' ac:macro-id='1d192d60-7e69-4af8-8dd6-4006a7bfc952'>
128+
<ac:parameter ac:name='title'>Exceptions</ac:parameter>
129+
<ac:rich-text-body>
130+
<table class='wrapped'>
131+
<colgroup>
132+
<col/>
133+
</colgroup>
134+
<tbody>
135+
<tr>
136+
<th>RegularExpression</th>
137+
</tr>
138+
<tr>
139+
<td>main/Test/NOT</td>
140+
</tr>
141+
</tbody>
142+
</table>
143+
</ac:rich-text-body>
144+
</ac:structured-macro>
127145
<ac:structured-macro ac:name='panel' ac:schema-version='1' ac:macro-id='93f1d981-c841-4cb4-b6e2-5940dfe69132'>
128146
<ac:parameter ac:name='title'>Notification Template</ac:parameter>
129147
<ac:rich-text-body>

test/NotificationTest.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,10 @@ describe('The Notification API', (): void => {
6464
await notification.notify(documentInfo)
6565
chai.expect((transportStub as unknown as SinonStubbedInstance<Mail>).sendMail.notCalled).to.be.true
6666
})
67+
it('should not send notifications for an excluded document', async (): Promise<void> => {
68+
const notification = new Notification(configuration, '', confluence, transportStub)
69+
const documentInfo = new DocumentInfo(0, 'author2', moment(), 'message', 'NOT', ['main', 'Test'], 'http://example.com')
70+
await notification.notify(documentInfo)
71+
chai.expect((transportStub as unknown as SinonStubbedInstance<Mail>).sendMail.calledOnce).to.be.false
72+
})
6773
})

0 commit comments

Comments
 (0)