forked from DGouron/review-flow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreviewAction.gitlab.cli.gateway.ts
More file actions
73 lines (66 loc) · 2.66 KB
/
reviewAction.gitlab.cli.gateway.ts
File metadata and controls
73 lines (66 loc) · 2.66 KB
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
import type { ReviewAction } from '../../../entities/reviewAction/reviewAction.js'
import type { ReviewActionGateway, ExecutionContext } from '../../../entities/reviewAction/reviewAction.gateway.js'
import { ExecutionGatewayBase, type CommandInfo } from '../../../shared/foundation/executionGateway.base.js'
import { enrichCommentWithLinks } from '../../../services/commentLinkEnricher.js'
export class GitLabReviewActionCliGateway
extends ExecutionGatewayBase<ReviewAction, ExecutionContext>
implements ReviewActionGateway
{
protected buildCommand(action: ReviewAction, context: ExecutionContext): CommandInfo | null {
const encodedProject = context.projectPath.replace(/\//g, '%2F')
const baseUrl = `projects/${encodedProject}/merge_requests/${context.mrNumber}`
switch (action.type) {
case 'THREAD_RESOLVE':
return {
command: 'glab',
args: ['api', '--method', 'PUT', `${baseUrl}/discussions/${action.threadId}`, '--field', 'resolved=true'],
}
case 'POST_COMMENT': {
const enrichedBody = context.baseUrl && context.diffMetadata
? enrichCommentWithLinks(action.body, context.baseUrl, context.projectPath, context.diffMetadata.headSha)
: action.body
return {
command: 'glab',
args: ['api', '--method', 'POST', `${baseUrl}/notes`, '--field', `body=${enrichedBody}`],
}
}
case 'THREAD_REPLY':
return {
command: 'glab',
args: [
'api',
'--method',
'POST',
`${baseUrl}/discussions/${action.threadId}/notes`,
'--field',
`body=${action.message}`,
],
}
case 'ADD_LABEL':
return {
command: 'glab',
args: ['api', '--method', 'PUT', baseUrl, '--field', `add_labels=${action.label}`],
}
case 'POST_INLINE_COMMENT': {
if (!context.diffMetadata) return null
return {
command: 'glab',
args: [
'api', '--method', 'POST',
`${baseUrl}/discussions`,
'--field', `body=${action.body}`,
'--field', `position[base_sha]=${context.diffMetadata.baseSha}`,
'--field', `position[head_sha]=${context.diffMetadata.headSha}`,
'--field', `position[start_sha]=${context.diffMetadata.startSha}`,
'--field', 'position[position_type]=text',
'--field', `position[new_path]=${action.filePath}`,
'--field', `position[old_path]=${action.filePath}`,
'--field', `position[new_line]=${action.line}`,
],
}
}
case 'FETCH_THREADS':
return null
}
}
}