1
1
import * as vscode from 'vscode' ;
2
- import { ISessionData } from 'src/typings/commonTypes' ;
3
- import { EmptyUserAvatar } from 'src/common/contants' ;
4
2
5
- let commentIdx = 1 ;
3
+ import { ISessionData , IDiffFileData } from 'src/typings/commonTypes' ;
4
+ import { EmptyUserAvatar } from 'src/common/contants' ;
5
+ import { CodingServer } from 'src/codingServer' ;
6
6
7
+ let commentIdx = 0 ;
7
8
export class ReviewComment implements vscode . Comment {
8
9
id : number ;
9
10
label : string | undefined ;
@@ -19,29 +20,62 @@ export class ReviewComment implements vscode.Comment {
19
20
}
20
21
}
21
22
22
- export function replyNote ( reply : vscode . CommentReply , context : vscode . ExtensionContext ) {
23
- const curUser = context . workspaceState . get < ISessionData > ( `session` ) ;
24
- const commentAuthor : vscode . CommentAuthorInformation = curUser ?. user
25
- ? {
26
- name : `${ curUser . user . name } (${ curUser . user . global_key } )` ,
27
- iconPath : vscode . Uri . parse ( curUser . user . avatar , false ) ,
28
- }
29
- : {
30
- name : `vscode user` ,
31
- iconPath : vscode . Uri . parse ( EmptyUserAvatar , false ) ,
32
- } ;
33
- const thread = reply . thread ;
34
- thread . contextValue = `editable` ;
35
- const newComment = new ReviewComment (
36
- reply . text ,
37
- vscode . CommentMode . Preview ,
38
- commentAuthor ,
39
- thread ,
40
- thread . comments . length ? 'canDelete' : undefined ,
41
- ) ;
42
- // if (thread.contextValue === 'draft') {
43
- // newComment.label = 'pending';
44
- // }
23
+ export async function replyNote (
24
+ reply : vscode . CommentReply ,
25
+ context : vscode . ExtensionContext ,
26
+ codingSrv : CodingServer ,
27
+ diffFileData : IDiffFileData ,
28
+ ) {
29
+ const params = new URLSearchParams ( decodeURIComponent ( reply . thread . uri . query ) ) ;
30
+ const isRight = params . get ( 'right' ) === `true` ;
31
+ const ident = `${ params . get ( `mr` ) } /${ params . get ( `path` ) } ` ;
32
+ const diffFile = diffFileData [ ident ] ;
33
+
34
+ const noteable_id = params . get ( 'id' ) ?? `` ; // mr index id
35
+ const commitId = isRight ? params . get ( 'rightSha' ) : params . get ( 'leftSha' ) ;
36
+ const content = reply . text ;
37
+ const noteable_type = `MergeRequestBean` ;
38
+ const change_type = isRight ? 1 : 2 ;
39
+ const line = reply . thread . range . start . line + 1 ;
40
+ const path = encodeURIComponent ( params . get ( `path` ) || `` ) ;
41
+ const targetPos = diffFile . diffLines . find ( ( i ) => {
42
+ return i [ isRight ? `rightNo` : `leftNo` ] === line ;
43
+ } ) ;
44
+ const position = targetPos ?. index ?? 0 ;
45
+
46
+ try {
47
+ const resp = await codingSrv . postLineNote ( {
48
+ noteable_id,
49
+ commitId : commitId ?? `` ,
50
+ content,
51
+ noteable_type,
52
+ change_type,
53
+ line,
54
+ path,
55
+ position,
56
+ } ) ;
57
+
58
+ const curUser = context . workspaceState . get < ISessionData > ( `session` ) ;
59
+ const commentAuthor : vscode . CommentAuthorInformation = curUser ?. user
60
+ ? {
61
+ name : `${ curUser . user . name } (${ curUser . user . global_key } )` ,
62
+ iconPath : vscode . Uri . parse ( curUser . user . avatar , false ) ,
63
+ }
64
+ : {
65
+ name : `vscode user` ,
66
+ iconPath : vscode . Uri . parse ( EmptyUserAvatar , false ) ,
67
+ } ;
68
+ const thread = reply . thread ;
69
+ thread . contextValue = `editable` ;
70
+ const newComment = new ReviewComment (
71
+ reply . text ,
72
+ vscode . CommentMode . Preview ,
73
+ commentAuthor ,
74
+ thread ,
75
+ thread . comments . length ? 'canDelete' : undefined ,
76
+ resp . data . id ,
77
+ ) ;
45
78
46
- thread . comments = [ ...thread . comments , newComment ] ;
79
+ thread . comments = [ ...thread . comments , newComment ] ;
80
+ } catch ( e ) { }
47
81
}
0 commit comments