-
-
Notifications
You must be signed in to change notification settings - Fork 301
/
Copy pathNotificationSettings.ts
98 lines (87 loc) · 2.68 KB
/
NotificationSettings.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
import { BaseResource } from '@gitbeaker/requester-utils';
import { RequestHelper, endpoint } from '../infrastructure';
import type { GitlabAPIResponse, OneOrNoneOf, ShowExpanded, Sudo } from '../infrastructure';
export type NotificationSettingLevel =
| 'disabled'
| 'participating'
| 'watch'
| 'global'
| 'mention'
| 'custom';
export type CustomSettingLevelEmailEvents =
| 'new_note'
| 'new_issue'
| 'reopen_issue'
| 'close_issue'
| 'reassign_issue'
| 'issue_due'
| 'new_merge_request'
| 'push_to_merge_request'
| 'reopen_merge_request'
| 'close_merge_request'
| 'reassign_merge_request'
| 'merge_merge_request'
| 'failed_pipeline'
| 'fixed_pipeline'
| 'success_pipeline'
| 'moved_project'
| 'merge_when_pipeline_succeeds'
| 'new_epic ';
export interface NotificationSettingSchema extends Record<string, unknown> {
level: NotificationSettingLevel;
notification_email?: string;
}
export type EditNotificationSettingsOptions = {
level?: string;
notificationEmail?: string;
newNote?: boolean;
newIssue?: boolean;
reopenIssue?: boolean;
closeIssue?: boolean;
reassignIssue?: boolean;
issueDue?: boolean;
newMergeRequest?: boolean;
pushToMergeRequest?: boolean;
reopenMergeRequest?: boolean;
closeMergeRequest?: boolean;
reassignMergeRequest?: boolean;
mergeMergeRequest?: boolean;
failedPipeline?: boolean;
fixedPipeline?: boolean;
successPipeline?: boolean;
movedProject?: boolean;
mergeWhenPipelineSucceeds?: boolean;
newEpic?: boolean;
};
function url({
projectId,
groupId,
}: { projectId?: string | number; groupId?: string | number } = {}): string {
let prefix = '';
if (projectId) prefix = endpoint`projects/${projectId}/`;
if (groupId) prefix = endpoint`groups/${groupId}/`;
return `${prefix}notification_settings`;
}
export class NotificationSettings<C extends boolean = false> extends BaseResource<C> {
edit<E extends boolean = false>({
groupId,
projectId,
...options
}: OneOrNoneOf<{ projectId: string | number; groupId: string | number }> &
EditNotificationSettingsOptions &
Sudo &
ShowExpanded<E> = {}): Promise<GitlabAPIResponse<NotificationSettingSchema, C, E, void>> {
const uri = url({ groupId, projectId });
return RequestHelper.put<NotificationSettingSchema>()(this, uri, options);
}
show<E extends boolean = false>({
groupId,
projectId,
...options
}: OneOrNoneOf<{ projectId: string | number; groupId: string | number }> &
Sudo &
ShowExpanded<E> = {}): Promise<GitlabAPIResponse<NotificationSettingSchema, C, E, void>> {
const uri = url({ groupId, projectId });
return RequestHelper.get<NotificationSettingSchema>()(this, uri, options);
}
}