-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDocumentInfo.ts
132 lines (124 loc) · 3.08 KB
/
DocumentInfo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import { Maintainer } from './Maintainer'
/**
* Informations about a Confluence document
*/
export interface DocumentInfo {
/**
* Document ID
*/
id: number
/**
* Document author
*/
author: string
/**
* Document title
*/
title: string
/**
* Path to document
*/
path: Array<string>
/**
* The date of the last version
*/
lastVersionDate: string
/**
* The edit message of the last version
*/
lastVersionMessage: string
/**
* The document URL
*/
url: string
/**
* Check whether the complete path to this document matches the given regexp
* @param regexp
*/
matchesPath(regexp: RegExp): boolean
/**
* Get the notification recipients for this document info. Usually contains of the last author and the
* maintainers
* @param maintainers
*/
getRecipients(maintainers: Maintainer[], domain?: string): string[]
}
export class DocumentInfo implements DocumentInfo {
public id: number
public author: string
public creator: string
public lastVersionDate: string
public lastVersionMessage: string
public title: string
public path: Array<string>
public url: string
public shortUrl: string
public labels: Array<string>
constructor(
id: number,
author: string,
creator: string,
lastVersionDate: string,
lastVersionMessage: string,
title: string,
path: Array<string>,
url: string,
shortUrl: string,
labels: Array<string>
) {
this.id = id
this.author = author
this.creator = creator
this.lastVersionDate = lastVersionDate
this.lastVersionMessage = lastVersionMessage
this.title = title
this.path = path
this.url = url
this.shortUrl = shortUrl
this.labels = labels
}
public matchesPath(regexp: RegExp): boolean {
return regexp.test(this.path.concat([this.title]).join('/'))
}
public static fromDocumentInfo(documentInfo: DocumentInfo): DocumentInfo {
return new DocumentInfo(
documentInfo.id,
documentInfo.author,
documentInfo.creator,
documentInfo.lastVersionDate,
documentInfo.lastVersionMessage,
documentInfo.title,
documentInfo.path,
documentInfo.url,
documentInfo.shortUrl,
documentInfo.labels
)
}
public getRecipients(maintainers: Maintainer[], domain?: string): string[] {
const retval = []
let addLastAuthor = maintainers.length > 0 ? false : true
let addCreator = false
for (const maintainer of maintainers) {
if (this.matchesPath(maintainer.pagePattern)) {
const maintainers = maintainer.maintainer.split(/,/)
if (maintainers.indexOf('_lastauthor') > 0) {
addLastAuthor = true
}
if (maintainers.indexOf('_creator') > 0) {
addCreator = true
}
retval.push(...maintainers.filter((entry) => ['_lastauthor', '_creator'].indexOf(entry) == -1))
}
}
if (addLastAuthor) {
retval.push(this.author)
}
if (addCreator) {
retval.push(this.creator)
}
if (domain) {
return retval.map((target) => `${target}@${domain}`)
}
return retval
}
}