-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
Copy pathEvents.ts
53 lines (47 loc) · 1.37 KB
/
Events.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
import { BaseService, RequestHelper } from '../infrastructure';
import { RequestOptions } from '../infrastructure/RequestHelper';
const ACTION_TYPES = {
created: 'created',
updated: 'updated',
closed: 'closed',
reopened: 'reopened',
pushed: 'pushed',
commented: 'commented',
merged: 'merged',
joined: 'joined',
left: 'left',
destroyed: 'destroyed',
expired: 'expired',
};
const TARGET_TYPES = {
issue: 'issue',
milestone: 'milestone',
merge_request: 'merge_request',
note: 'note',
project: 'project',
snippet: 'snippet',
user: 'user',
};
function assertEventOptions(
action: keyof typeof ACTION_TYPES,
target: keyof typeof TARGET_TYPES,
) {
if (!action || !(action in ACTION_TYPES)) {
throw new Error(`This action is not supported. Pleased use one of following options: ${Object.keys(ACTION_TYPES)}`);
}
if (!target || !(target in TARGET_TYPES)) {
throw new Error(`This target is not supported. Pleased use one of following options: ${Object.keys(TARGET_TYPES)}`);
}
}
export interface EventOptions {
action: keyof typeof ACTION_TYPES;
targetType: keyof typeof TARGET_TYPES;
}
class Events extends BaseService {
all(options: RequestOptions & EventOptions) {
assertEventOptions(options.action, options.targetType);
return RequestHelper.get(this, 'events', options);
}
}
export default Events;
export { assertEventOptions };