Skip to content

Commit 0dfc1a9

Browse files
committed
feat: shortUrl and fixed missing author
1 parent 1a123b9 commit 0dfc1a9

File tree

6 files changed

+29
-10
lines changed

6 files changed

+29
-10
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@ excluded from notifications.
6262
This panel includes two child panels which hold [Handlebars](https://handlebarsjs.com/guide/) templates for the
6363
subject and the body of the notification mails.
6464

65-
They will get [this object](https://github.com/dodevops/confluence-outdated/blob/master/lib/api/DocumentInfo.ts#L6) as
66-
a context for the template.
65+
They will be provided with the following context:
66+
67+
* author: E-Mail address of the recipient
68+
* documentsCount: The number of documents that are outdated for this recipient
69+
* multipleDocuments: A boolean whether there are multiple documents or just one
70+
* documents: An array of [this object](https://github.com/dodevops/confluence-outdated/blob/master/lib/api/DocumentInfo.ts#L6)
6771

6872
## Usage
6973

lib/api/Confluence.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class Confluence {
120120

121121
const path = document.ancestors.map((ancestor) => ancestor.title)
122122

123-
const documentInfo = new DocumentInfo(documentId, author, lastVersionDate, lastVersionMessage, title, path, url)
123+
const documentInfo = new DocumentInfo(documentId, author, lastVersionDate, lastVersionMessage, title, path, url, document._links.webui)
124124

125125
return documentInfo
126126
}

lib/api/DocumentInfo.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export class DocumentInfo implements DocumentInfo {
4848
public title: string
4949
public path: Array<string>
5050
public url: string
51+
public shortUrl: string
5152

5253
constructor(
5354
id: number,
@@ -56,7 +57,8 @@ export class DocumentInfo implements DocumentInfo {
5657
lastVersionMessage: string,
5758
title: string,
5859
path: Array<string>,
59-
url: string
60+
url: string,
61+
shortUrl: string
6062
) {
6163
this.id = id
6264
this.author = author
@@ -65,6 +67,7 @@ export class DocumentInfo implements DocumentInfo {
6567
this.title = title
6668
this.path = path
6769
this.url = url
70+
this.shortUrl = shortUrl
6871
}
6972

7073
public matchesPath(regexp: RegExp): boolean {

lib/api/Notification.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ export class Notification {
6868
from: this._configuration.notificationFrom,
6969
to: recipient,
7070
subject: subjectTemplate({
71+
author: recipient,
7172
documentsCount: this._notificationBatch[recipient].length,
7273
multipleDocuments: this._notificationBatch[recipient].length > 1,
7374
documents: this._notificationBatch[recipient],
7475
}),
7576
html: bodyTemplate({
77+
author: recipient,
7678
documentsCount: this._notificationBatch[recipient].length,
7779
multipleDocuments: this._notificationBatch[recipient].length > 1,
7880
documents: this._notificationBatch[recipient],

test/ConfluenceTest.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ describe('The Confluence API', (): void => {
1616
const results = await confluence.findDocumentsOlderThan('', 1, 1)
1717
chai.expect(results).to.have.lengthOf(2)
1818
chai.expect(results[0].url).to.eq('https://example.com/display/SAMPLE/Test')
19+
chai.expect(results[0].shortUrl).to.eq('/display/SAMPLE/Test')
1920
chai.expect(results[0].author).to.eq('author')
2021
chai.expect(results[0].id).to.eq(123)
2122
chai.expect((results[0].lastVersionDate as Moment).toISOString()).to.eq('2019-12-31T22:00:00.000Z')
2223
chai.expect(results[0].lastVersionMessage).to.eq('Some change')
2324
chai.expect(results[0].title).to.eq('Test')
2425
chai.expect(results[1].url).to.eq('https://example.com/display/SAMPLE/Test2')
26+
chai.expect(results[1].shortUrl).to.eq('/display/SAMPLE/Test2')
2527
chai.expect(results[1].author).to.eq('author2')
2628
chai.expect(results[1].id).to.eq(234)
2729
chai.expect((results[1].lastVersionDate as Moment).toISOString()).to.eq('2020-01-31T22:00:00.000Z')

test/NotificationTest.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,21 @@ describe('The Notification API', (): void => {
3232

3333
it('should send notifications', async (): Promise<void> => {
3434
const notification = new Notification(configuration, '', confluence, transportStub)
35-
const documentInfo = new DocumentInfo(0, 'author', moment(), 'message', 'title', ['main'], 'http://example.com')
35+
const documentInfo = new DocumentInfo(0, 'author', moment(), 'message', 'title', ['main'], 'http://example.com', 'test')
3636
await notification.notify([documentInfo])
3737
chai.expect((transportStub as unknown as SinonStubbedInstance<Mail>).sendMail.calledOnce).to.be.true
3838
chai.expect(
3939
(transportStub as unknown as SinonStubbedInstance<Mail>).sendMail.calledWith({
4040
from: 'Notification <[email protected]>',
4141
4242
subject: Handlebars.compile(MockServer.NOTIFICATION_SUBJECT)({
43+
author: '[email protected]',
4344
documentsCount: 1,
4445
documents: [documentInfo],
4546
multipleDocuments: false,
4647
}),
4748
html: Handlebars.compile(MockServer.NOTIFICATION_BODY)({
49+
author: '[email protected]',
4850
documentsCount: 1,
4951
documents: [documentInfo],
5052
multipleDocuments: false,
@@ -54,19 +56,21 @@ describe('The Notification API', (): void => {
5456
})
5557
it('should use a maintainer when configured', async (): Promise<void> => {
5658
const notification = new Notification(configuration, '', confluence, transportStub)
57-
const documentInfo = new DocumentInfo(0, 'author2', moment(), 'message', 'Test2', ['main', 'Test'], 'http://example.com')
59+
const documentInfo = new DocumentInfo(0, 'author2', moment(), 'message', 'Test2', ['main', 'Test'], 'http://example.com', 'test')
5860
await notification.notify([documentInfo])
5961
chai.expect((transportStub as unknown as SinonStubbedInstance<Mail>).sendMail.calledTwice).to.be.true
6062
chai.expect(
6163
(transportStub as unknown as SinonStubbedInstance<Mail>).sendMail.calledWith({
6264
from: 'Notification <[email protected]>',
6365
6466
subject: Handlebars.compile(MockServer.NOTIFICATION_SUBJECT)({
67+
author: '[email protected]',
6568
documentsCount: 1,
6669
documents: [documentInfo],
6770
multipleDocuments: false,
6871
}),
6972
html: Handlebars.compile(MockServer.NOTIFICATION_BODY)({
73+
author: '[email protected]',
7074
documentsCount: 1,
7175
documents: [documentInfo],
7276
multipleDocuments: false,
@@ -78,11 +82,13 @@ describe('The Notification API', (): void => {
7882
from: 'Notification <[email protected]>',
7983
8084
subject: Handlebars.compile(MockServer.NOTIFICATION_SUBJECT)({
85+
author: '[email protected]',
8186
documentsCount: 1,
8287
documents: [documentInfo],
8388
multipleDocuments: false,
8489
}),
8590
html: Handlebars.compile(MockServer.NOTIFICATION_BODY)({
91+
author: '[email protected]',
8692
documentsCount: 1,
8793
documents: [documentInfo],
8894
multipleDocuments: false,
@@ -92,33 +98,35 @@ describe('The Notification API', (): void => {
9298
})
9399
it('should not send notifications on a dry run', async (): Promise<void> => {
94100
const notification = new Notification(configuration, '', confluence, transportStub, true)
95-
const documentInfo = new DocumentInfo(0, 'author', moment(), 'message', 'title', ['main'], 'http://example.com')
101+
const documentInfo = new DocumentInfo(0, 'author', moment(), 'message', 'title', ['main'], 'http://example.com', 'test')
96102
await notification.notify([documentInfo])
97103
chai.expect((transportStub as unknown as SinonStubbedInstance<Mail>).sendMail.notCalled).to.be.true
98104
})
99105
it('should not send notifications for an excluded document', async (): Promise<void> => {
100106
const notification = new Notification(configuration, '', confluence, transportStub)
101-
const documentInfo = new DocumentInfo(0, 'author2', moment(), 'message', 'NOT', ['main', 'Test'], 'http://example.com')
107+
const documentInfo = new DocumentInfo(0, 'author2', moment(), 'message', 'NOT', ['main', 'Test'], 'http://example.com', 'test')
102108
await notification.notify([documentInfo])
103109
chai.expect((transportStub as unknown as SinonStubbedInstance<Mail>).sendMail.calledOnce).to.be.false
104110
})
105111

106112
it('should send notifications in a batch if configured', async (): Promise<void> => {
107113
const notification = new Notification(configuration, '', confluence, transportStub)
108-
const documentInfo = new DocumentInfo(0, 'author', moment(), 'message', 'title1', ['main'], 'http://example.com')
109-
const documentInfo2 = new DocumentInfo(0, 'author', moment(), 'message', 'title2', ['main'], 'http://example.com')
114+
const documentInfo = new DocumentInfo(0, 'author', moment(), 'message', 'title1', ['main'], 'http://example.com', 'test')
115+
const documentInfo2 = new DocumentInfo(0, 'author', moment(), 'message', 'title2', ['main'], 'http://example.com', 'test')
110116
await notification.notify([documentInfo, documentInfo2])
111117
chai.expect((transportStub as unknown as SinonStubbedInstance<Mail>).sendMail.calledOnce).to.be.true
112118
chai.expect(
113119
(transportStub as unknown as SinonStubbedInstance<Mail>).sendMail.calledWith({
114120
from: 'Notification <[email protected]>',
115121
116122
subject: Handlebars.compile(MockServer.NOTIFICATION_SUBJECT)({
123+
author: '[email protected]',
117124
documentsCount: 2,
118125
documents: [documentInfo, documentInfo2],
119126
multipleDocuments: true,
120127
}),
121128
html: Handlebars.compile(MockServer.NOTIFICATION_BODY)({
129+
author: '[email protected]',
122130
documentsCount: 2,
123131
documents: [documentInfo, documentInfo2],
124132
multipleDocuments: true,

0 commit comments

Comments
 (0)