Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5e1443a

Browse files
feat(mr): show/post diff comments (#2)
1 parent becd456 commit 5e1443a

File tree

12 files changed

+552
-52
lines changed

12 files changed

+552
-52
lines changed

‎package.json

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "coding-plugin",
33
"displayName": "CODING Merge Requests & Releases",
44
"description": "CODING plugin for VS Code.",
5-
"version": "0.3.0",
5+
"version": "0.3.1",
66
"publisher": "coding-net",
77
"license": "MIT",
88
"engines": {
@@ -60,9 +60,34 @@
6060
"command": "codingPlugin.switchRepo",
6161
"title": "Switch repo",
6262
"category": "Coding plugin"
63+
},
64+
{
65+
"command": "codingPlugin.diff.createComment",
66+
"title": "Post comment",
67+
"enablement": "!commentIsEmpty"
68+
},
69+
{
70+
"command": "codingPlugin.diff.replyComment",
71+
"title": "Reply",
72+
"enablement": "!commentIsEmpty"
73+
},
74+
{
75+
"command": "extension.diff.deleteComment",
76+
"title": "Delete comment",
77+
"#enablement": "!commentIsEmpty"
6378
}
6479
],
6580
"menus": {
81+
"commandPalette": [
82+
{
83+
"command": "codingPlugin.diff.createComment",
84+
"when": "false"
85+
},
86+
{
87+
"command": "codingPlugin.diff.replyComment",
88+
"when": "false"
89+
}
90+
],
6691
"view/title": [
6792
{
6893
"command": "codingPlugin.newMrDesc",
@@ -74,6 +99,24 @@
7499
"when": "view == mrTreeView",
75100
"group": "navigation"
76101
}
102+
],
103+
"comments/commentThread/context": [
104+
{
105+
"command": "codingPlugin.diff.createComment",
106+
"group": "inline",
107+
"when": "commentThreadIsEmpty"
108+
},
109+
{
110+
"command": "codingPlugin.diff.replyComment",
111+
"group": "inline",
112+
"when": "!commentThreadIsEmpty"
113+
}
114+
],
115+
"comments/comment/title": [
116+
{
117+
"command": "extension.diff.deleteComment",
118+
"when": "comment == editable"
119+
}
77120
]
78121
},
79122
"viewsWelcome": [
@@ -128,7 +171,7 @@
128171
"watch:webviews": "webpack --watch --mode development",
129172
"lint": "eslint . --ext .ts,.tsx",
130173
"clean": "rm -rf node_modules/ && yarn install --prod=true --force && rm -rf node_modules/@babel node_modules/@types node_modules/react*",
131-
"package": "npx vsce package",
174+
"pk": "npx vsce package",
132175
"release": "npx vsce publish"
133176
},
134177
"babel": {
@@ -148,12 +191,14 @@
148191
"nanoid": "^3.1.20",
149192
"react": "^17.0.0",
150193
"react-dom": "^17.0.0",
151-
"styled-components": "^5.2.1"
194+
"styled-components": "^5.2.1",
195+
"turndown": "^7.0.0"
152196
},
153197
"devDependencies": {
154198
"@svgr/webpack": "^5.5.0",
155199
"@types/react": "^16.9.53",
156200
"@types/react-dom": "^16.9.8",
201+
"@types/turndown": "^5.0.0",
157202
"@typescript-eslint/eslint-plugin": "^3.0.2",
158203
"@typescript-eslint/parser": "^3.0.2",
159204
"babel-plugin-styled-components": "^1.12.0",

‎src/codingServer.ts

Lines changed: 68 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import got from 'got';
55
import {
66
AuthFailResult,
77
AuthSuccessResult,
8-
CodingResponse,
8+
ICodingResponse,
99
IRepoListResponse,
1010
IMRDiffResponse,
1111
IMRDetailResponse,
@@ -18,14 +18,20 @@ import {
1818
IMRContentResp,
1919
ICreateCommentResp,
2020
IMRStatusResp,
21+
IMRCommentResp,
22+
IFileDiffParam,
23+
IFileDiffResp,
24+
ILineNoteResp,
25+
ILineNoteForm,
2126
} from 'src/typings/respResult';
27+
2228
import { PromiseAdapter, promiseFromEvent, parseQuery, parseCloneUrl } from 'src/common/utils';
2329
import { GitService } from 'src/common/gitService';
2430
import { IRepoInfo, ISessionData, TokenType } from 'src/typings/commonTypes';
2531
import { keychain } from 'src/common/keychain';
2632
import Logger from 'src/common/logger';
2733

28-
const AUTH_SERVER = `https://x5p7m.csb.app`;
34+
const AUTH_SERVER = `https://x5p7m.csb.app/`;
2935
const ClientId = `ff768664c96d04235b1cc4af1e3b37a8`;
3036
const ClientSecret = `d29ebb32cab8b5f0a643b5da7dcad8d1469312c7`;
3137

@@ -219,7 +225,7 @@ export class CodingServer {
219225

220226
public async getUserInfo(team: string, token: string = this._session?.accessToken || ``) {
221227
try {
222-
const result: CodingResponse = await got
228+
const result: ICodingResponse = await got
223229
.get(`https://${team || `codingcorp`}.coding.net/api/current_user`, {
224230
searchParams: {
225231
access_token: token,
@@ -266,10 +272,10 @@ export class CodingServer {
266272
};
267273
}
268274

269-
public async getMRList(repo?: string, status?: string): Promise<CodingResponse> {
275+
public async getMRList(repo?: string, status?: string): Promise<ICodingResponse> {
270276
try {
271277
const { repoApiPrefix } = await this.getApiPrefix();
272-
const result: CodingResponse = await got
278+
const result: ICodingResponse = await got
273279
.get(`${repoApiPrefix}/merges/query`, {
274280
searchParams: {
275281
status,
@@ -390,10 +396,10 @@ export class CodingServer {
390396
}
391397
}
392398

393-
public async getMRComments(iid: string) {
399+
public async getMRComments(iid: string|number) {
394400
try {
395401
const { repoApiPrefix } = await this.getApiPrefix();
396-
const result: CodingResponse = await got
402+
const result: IMRCommentResp = await got
397403
.get(`${repoApiPrefix}/merge/${iid}/comments`, {
398404
searchParams: {
399405
access_token: this._session?.accessToken,
@@ -413,7 +419,7 @@ export class CodingServer {
413419
public async closeMR(iid: string) {
414420
try {
415421
const { repoApiPrefix } = await this.getApiPrefix();
416-
const result: CodingResponse = await got
422+
const result: ICodingResponse = await got
417423
.post(`${repoApiPrefix}/merge/${iid}/refuse`, {
418424
searchParams: {
419425
access_token: this._session?.accessToken,
@@ -433,7 +439,7 @@ export class CodingServer {
433439
public async approveMR(iid: string) {
434440
try {
435441
const { repoApiPrefix } = await this.getApiPrefix();
436-
const result: CodingResponse = await got
442+
const result: ICodingResponse = await got
437443
.post(`${repoApiPrefix}/merge/${iid}/good`, {
438444
searchParams: {
439445
access_token: this._session?.accessToken,
@@ -453,7 +459,7 @@ export class CodingServer {
453459
public async disapproveMR(iid: string) {
454460
try {
455461
const { repoApiPrefix } = await this.getApiPrefix();
456-
const result: CodingResponse = await got
462+
const result: ICodingResponse = await got
457463
.delete(`${repoApiPrefix}/merge/${iid}/good`, {
458464
searchParams: {
459465
access_token: this._session?.accessToken,
@@ -473,7 +479,7 @@ export class CodingServer {
473479
public async mergeMR(iid: string) {
474480
try {
475481
const { repoApiPrefix } = await this.getApiPrefix();
476-
const result: CodingResponse = await got
482+
const result: ICodingResponse = await got
477483
.post(`${repoApiPrefix}/merge/${iid}/merge`, {
478484
searchParams: {
479485
access_token: this._session?.accessToken,
@@ -496,7 +502,7 @@ export class CodingServer {
496502
public async updateMRTitle(iid: string, title: string) {
497503
try {
498504
const { repoApiPrefix } = await this.getApiPrefix();
499-
const result: CodingResponse = await got
505+
const result: ICodingResponse = await got
500506
.put(`${repoApiPrefix}/merge/${iid}/update-title`, {
501507
searchParams: {
502508
access_token: this._session?.accessToken,
@@ -626,7 +632,7 @@ export class CodingServer {
626632

627633
public async addMRReviewers(iid: string, ids: number[]): Promise<number[]> {
628634
const { repoApiPrefix } = await this.getApiPrefix();
629-
const tasks: Promise<CodingResponse>[] = ids.map((id) => {
635+
const tasks: Promise<ICodingResponse>[] = ids.map((id) => {
630636
return got
631637
.post(`${repoApiPrefix}/merge/${iid}/reviewers`, {
632638
searchParams: {
@@ -636,7 +642,7 @@ export class CodingServer {
636642
})
637643
.json();
638644
});
639-
const result: PromiseSettledResult<CodingResponse>[] = await Promise.allSettled(tasks);
645+
const result: PromiseSettledResult<ICodingResponse>[] = await Promise.allSettled(tasks);
640646
const fulfilled = ids.reduce((res, cur, idx) => {
641647
if (result[idx].status === `fulfilled`) {
642648
res = res.concat(cur);
@@ -649,7 +655,7 @@ export class CodingServer {
649655

650656
public async removeMRReviewers(iid: string, ids: number[]): Promise<number[]> {
651657
const { repoApiPrefix } = await this.getApiPrefix();
652-
const tasks: Promise<CodingResponse>[] = ids.map((id) => {
658+
const tasks: Promise<ICodingResponse>[] = ids.map((id) => {
653659
return got
654660
.delete(`${repoApiPrefix}/merge/${iid}/reviewers`, {
655661
searchParams: {
@@ -659,7 +665,7 @@ export class CodingServer {
659665
})
660666
.json();
661667
});
662-
const result: PromiseSettledResult<CodingResponse>[] = await Promise.allSettled(tasks);
668+
const result: PromiseSettledResult<ICodingResponse>[] = await Promise.allSettled(tasks);
663669
const fulfilled = ids.reduce((res, cur, idx) => {
664670
if (result[idx].status === `fulfilled`) {
665671
res = res.concat(cur);
@@ -715,6 +721,52 @@ export class CodingServer {
715721
}
716722
}
717723

724+
public async fetchFileDiffs(param: IFileDiffParam) {
725+
try {
726+
const { repoApiPrefix } = await this.getApiPrefix();
727+
const resp: IFileDiffResp = await got
728+
.get(`${repoApiPrefix}/compare_with_path`, {
729+
searchParams: {
730+
access_token: this._session?.accessToken,
731+
base: param.base,
732+
compare: param.compare,
733+
path: encodeURIComponent(param.path),
734+
mergeRequestId: param.mergeRequestId,
735+
},
736+
})
737+
.json();
738+
739+
if (resp.code) {
740+
return Promise.reject(resp);
741+
}
742+
743+
return resp;
744+
} catch (e) {
745+
return Promise.reject(e);
746+
}
747+
}
748+
749+
public async postLineNote(data: ILineNoteForm) {
750+
try {
751+
const { repoApiPrefix } = await this.getApiPrefix();
752+
const resp: ILineNoteResp = await got.post(`${repoApiPrefix}/line_notes`, {
753+
resolveBodyOnly: true,
754+
responseType: `json`,
755+
searchParams: {
756+
access_token: this._session?.accessToken,
757+
},
758+
form: data,
759+
});
760+
761+
if (resp.code) {
762+
return Promise.reject(resp);
763+
}
764+
return resp;
765+
} catch (e) {
766+
return Promise.reject(e);
767+
}
768+
}
769+
718770
get loggedIn() {
719771
return this._loggedIn;
720772
}

‎src/common/contants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const MRUriScheme = `coding-mr`;
2+
3+
export const EmptyUserAvatar = `https://coding-net-production-static-ci.codehub.cn/7167f369-59ff-4196-bb76-a9959cf2b906.png`;

‎src/common/utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,15 @@ export function getNonce() {
6666
}
6767
return text;
6868
}
69+
70+
const HunkRegExp = /@@.+@@/g;
71+
export const isHunkLine = (hunk: string) => HunkRegExp.test(hunk);
72+
73+
export const getDiffLineNumber = (hunk: string) => {
74+
const matchedHunks = hunk.match(/[-+]\d+(,\d+)?/g) || [];
75+
return matchedHunks.map((i) => {
76+
const [start = 0, sum = 0] = i.match(/\d+/g)?.map((j) => +j) ?? [];
77+
const end = start + sum > 0 ? start + sum - 1 : 0;
78+
return [start, end];
79+
});
80+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /