Skip to content

Commit 4ce24a1

Browse files
author
guqiankun
committed
feat: 更新gitlink blame接口
1 parent c6dd4fa commit 4ce24a1

3 files changed

Lines changed: 64 additions & 28 deletions

File tree

packages/code-api/src/gitlink/gitlink.service.ts

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -269,32 +269,49 @@ export class GitLinkAPIService implements ICodeAPIService {
269269
}
270270

271271
async getFileBlame(repo: IRepositoryModel, path: string) {
272-
// const blames = await this.request<API.ResponseFileBlame>(
273-
// `/api/v1/${this.getProjectPath(repo)}/blame?sha=${repo.commit}&filepath=${path}`,
274-
// {
275-
// responseType: 'json',
276-
// }
277-
// );
278-
// blames.blame_parts.map((blame) => {
279-
// const commit = blame.commit;
280-
281-
// return {
282-
// commit: {
283-
// id: commit.sha,
284-
// auther_name: commit.committer.name,
285-
// auther_email: commit.committer?.email,
286-
// authored_date: commit.authored_time,
287-
// committed_date: commit.commited_time,
288-
// message: commit.commit_message,
289-
// author: {
290-
// avatar_url: commit.committer.image_url,
291-
// },
292-
// },
293-
// lines: [],
294-
// };
295-
// });
296-
297-
return Uint8Array.from([]);
272+
const blames = await this.request<API.ResponseFileBlame>(
273+
`/api/v1/${this.getProjectPath(repo)}/blame?sha=${repo.commit}&filepath=${path}`,
274+
{
275+
responseType: 'json',
276+
}
277+
);
278+
const blameHash = {};
279+
const blamePart: API.gitlensBlame[] = [];
280+
281+
blames.blame_parts.forEach((blame) => {
282+
const commit = blame.commit;
283+
if (blameHash[commit.sha]) {
284+
const bla = blamePart.find((b) => b.commit.id === blame.commit.sha) as API.gitlensBlame;
285+
bla.lines.push({
286+
current_number: blame.current_number,
287+
effect_line: blame.effect_line,
288+
previous_number: blame.previous_number,
289+
});
290+
} else {
291+
blameHash[commit.sha] = true;
292+
blamePart.push({
293+
commit: {
294+
id: commit.sha,
295+
author_name: commit.committer.name,
296+
author_email: commit.committer?.email,
297+
authored_date: commit.authored_time,
298+
committed_date: commit.commited_time,
299+
message: commit.commit_message,
300+
author: {
301+
avatar_url: commit.committer.image_url,
302+
},
303+
},
304+
lines: [
305+
{
306+
current_number: blame.current_number,
307+
effect_line: blame.effect_line,
308+
previous_number: blame.previous_number,
309+
},
310+
],
311+
});
312+
}
313+
});
314+
return new TextEncoder().encode(JSON.stringify(blamePart));
298315
}
299316

300317
async getCommits(repo: IRepositoryModel, params: CommitParams) {

packages/code-api/src/gitlink/types.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,29 @@ export namespace API {
7171
commit: ResponseCommit;
7272
current_number: number;
7373
effect_line: number;
74+
previous_number: number;
7475
lines: string[];
7576
}
77+
78+
export interface gitlensBlame {
79+
commit: {
80+
id: string;
81+
author_name: string;
82+
author_email?: string;
83+
authored_date: string;
84+
committed_date: string;
85+
message: string;
86+
author: {
87+
avatar_url: string;
88+
};
89+
};
90+
lines: Array<{
91+
current_number: number;
92+
effect_line: number;
93+
previous_number: number;
94+
}>;
95+
}
96+
7697
export interface ResponseCommit {
7798
sha: string;
7899
author: {

packages/toolkit/webpack/config.dev.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ module.exports = () => {
4242
target: process.env.CODE_SERVICE_HOST || 'https://code.alipay.com',
4343
headers: {
4444
'PRIVATE-TOKEN': process.env.PRIVATE_TOKEN,
45-
Cookie:
46-
'autologin_trustie=ebdf7bf2e3a7b7e38db85cbfb052a4f5639b480b;user_id=BAhpA3p1AQ%3D%3D--016cfd4d2c67651b141d9ea39b418fff55bd859c;states=%7B%22select_params%22%3A%7B%22page%22%3A1%2C%22limit%22%3A15%2C%22fixed_version_id%22%3A%222031%22%7D%2C%22assigned_to_ids%22%3A%22%E8%B4%9F%E8%B4%A3%E4%BA%BA%22%2C%22status_type%22%3A%221%22%2C%22issue_tag_ids%22%3A%22%E6%A0%87%E8%AE%B0%22%2C%22tracker_ids%22%3A%22%E7%B1%BB%E5%9E%8B%22%2C%22author_ids%22%3A%22%E5%8F%91%E5%B8%83%E4%BA%BA%22%2C%22fixed_version_ids%22%3A%22CloudIDE%22%2C%22status_ids%22%3A%22%E7%8A%B6%E6%80%81%22%2C%22done_ratios%22%3A%22%E5%AE%8C%E6%88%90%E5%BA%A6%22%2C%22paix%22%3A%22%E6%8E%92%E5%BA%8F%22%2C%22update_author_ids%22%3A%22%E6%9B%B4%E6%8D%A2%E8%B4%9F%E8%B4%A3%E4%BA%BA%22%2C%22update_status_ids%22%3A%22%E4%BF%AE%E6%94%B9%E7%8A%B6%E6%80%81%22%2C%22begin%22%3A%22%22%2C%22end%22%3A%22%22%7D;_educoder_session=bd5f5284909f8e080964f649497d837b',
4745
},
4846
secure: false,
4947
changeOrigin: true,

0 commit comments

Comments
 (0)