修改代码评审
This commit is contained in:
parent
9cb3c7c3bd
commit
06c2466580
|
|
@ -1,13 +1,13 @@
|
|||
module.exports = {
|
||||
extension: {
|
||||
publisher: 'cloud-ide-ext',
|
||||
publisher: 'alex-ext-public',
|
||||
name: 'editor-plugin-blame',
|
||||
version: '0.2.5',
|
||||
version: '0.2.6',
|
||||
},
|
||||
packageJSON: {
|
||||
name: 'editor-plugin-blame',
|
||||
publisher: 'cloud-ide-ext',
|
||||
version: '0.2.5',
|
||||
publisher: 'alex-ext-public',
|
||||
version: '0.2.6',
|
||||
repository: {
|
||||
type: 'git',
|
||||
url: 'http://code.alipay.com/yxy167584/editor-plugin-blame.git',
|
||||
|
|
@ -52,4 +52,5 @@ module.exports = {
|
|||
nlsList: [],
|
||||
extendConfig: {},
|
||||
webAssets: ['package.json', 'out/worker/index.js'],
|
||||
mode: 'public',
|
||||
};
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ export function useFileReadMarkChange$(
|
|||
const filePathShaMap = useMemo(() => {
|
||||
const map = new Map();
|
||||
for (const diff of diffs) {
|
||||
map.set(sha1(diff.name||diff.newPath), diff.name||diff.newPath);
|
||||
map.set(sha1(diff.newPath), diff.newPath);
|
||||
}
|
||||
return map;
|
||||
}, [diffs]);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import React, { useEffect, useState, useMemo } from 'react';
|
||||
// import { default as AntcodeCR } from 'acr';
|
||||
import { ACR } from 'alex';
|
||||
import { Button, Switch } from 'antd';
|
||||
import { Button, Switch, Spin } from 'antd';
|
||||
// blame worker扩展
|
||||
import CodeBlame from './extensions/alex-ext-public.editor-plugin-blame.js';
|
||||
// 通过在plugin内调用扩展中的命令来进行外部交互
|
||||
|
|
@ -46,7 +46,7 @@ function findKey(obj) {
|
|||
}
|
||||
|
||||
const CodeReview = (props) => {
|
||||
const { match: { params: { owner, projectsId, mergeId } }, projectDetail,current_user } = props;
|
||||
const { match: { params: { owner, projectsId, mergeId } }, projectDetail, current_user } = props;
|
||||
const [visible, setVisible] = React.useState(true);
|
||||
const [count, setCount] = React.useState(0);
|
||||
const [isFullscreen, setFullscreen] = React.useState(false);
|
||||
|
|
@ -84,18 +84,22 @@ const CodeReview = (props) => {
|
|||
readMarks
|
||||
);
|
||||
|
||||
console.log('fileReadMarkChange$');
|
||||
console.log(readMarks);
|
||||
// 插件激活
|
||||
const [pluginActivated, setPluginActivated] = useState(false);
|
||||
const blamePlugin = useMemo(() => {
|
||||
return new CodeBlamePlugin(
|
||||
() => setPluginActivated(true),
|
||||
(commitId) =>
|
||||
(commitId) => {
|
||||
console.log(commitId);
|
||||
window.open(
|
||||
`/${owner}/${projectsId}/commit/${commitId}`
|
||||
),
|
||||
)
|
||||
},
|
||||
// 获取blame数据
|
||||
(projectId, commitId, path) =>
|
||||
repoService.getCodeBlame(projectId, commitId, path)
|
||||
(projectId, commitId, filepath) =>
|
||||
repoService.getCodeBlame(projectsId, owner, { sha: commitId, filepath })
|
||||
);
|
||||
}, []);
|
||||
|
||||
|
|
@ -115,11 +119,10 @@ const CodeReview = (props) => {
|
|||
}, [pluginActivated, diffsPack]);
|
||||
|
||||
if (!diffsPack) {
|
||||
return null;
|
||||
return <Spin style={{height:"100vh"}} spinning={true}></Spin>
|
||||
}
|
||||
|
||||
|
||||
const propsMock = {
|
||||
const propsIDE = {
|
||||
// 评审
|
||||
noteIdToReplyIdSet: commentPack.noteIdToReplyIdSet,
|
||||
// 增加的总行数
|
||||
|
|
@ -172,12 +175,10 @@ const CodeReview = (props) => {
|
|||
}
|
||||
let data = {
|
||||
files: files,
|
||||
// author_email: header.authorEmail,
|
||||
// author_name: header.authorName,
|
||||
// author_timeunix: 1658214400,
|
||||
committer_email: header.authorEmail,
|
||||
committer_name: header.authorName,
|
||||
// committer_timeunix: 1658214400,
|
||||
author_email: current_user.email,
|
||||
author_name: current_user.login,
|
||||
committer_email: current_user.email,
|
||||
committer_name: current_user.login,
|
||||
branch: header.branch,
|
||||
message: header.commitMessage,
|
||||
};
|
||||
|
|
@ -185,7 +186,11 @@ const CodeReview = (props) => {
|
|||
console.log(actions);
|
||||
console.log(header);
|
||||
console.log(data);
|
||||
projectService.bulkChangeFiles(projectsId, owner, data)
|
||||
if (pr && pr.forkProject) {
|
||||
projectService.bulkChangeFiles(pr.forkProject.identifier, pr.forkProject.login, data);
|
||||
} else {
|
||||
projectService.bulkChangeFiles(projectsId, owner, data);
|
||||
}
|
||||
},
|
||||
// 菜单栏
|
||||
Menubar: () => (
|
||||
|
|
@ -228,19 +233,19 @@ const CodeReview = (props) => {
|
|||
zIndex: 1100,
|
||||
};
|
||||
|
||||
console.log('propsMock:');
|
||||
console.log(propsMock);
|
||||
// findKey(propsMock);
|
||||
console.log('propsIDE:');
|
||||
console.log(propsIDE);
|
||||
return (
|
||||
<div style={{ height: '100%' }}>
|
||||
{/* <div className="controller">
|
||||
|
||||
<div style={{ height: '100%' }}>
|
||||
{/* <div className="controller">
|
||||
{!IDEMode && (
|
||||
<>
|
||||
IDE 模式: <Switch checked={IDEMode} onChange={toggleViewerType} />
|
||||
</>
|
||||
)}
|
||||
</div> */}
|
||||
{/* <div className="pr-head">
|
||||
{/* <div className="pr-head">
|
||||
<div>{pr.description}</div>
|
||||
<div>
|
||||
评审人:
|
||||
|
|
@ -253,12 +258,13 @@ const CodeReview = (props) => {
|
|||
合并人:{pr.assignee && pr.assignee.name}
|
||||
</div>
|
||||
</div> */}
|
||||
{IDEMode && (
|
||||
<div style={IDEContainerStyle}>
|
||||
{visible && <ACR {...propsMock} key={count} />}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{IDEMode && (
|
||||
<div style={IDEContainerStyle}>
|
||||
{visible && <ACR {...propsIDE} key={count} />}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -24,17 +24,18 @@ import {
|
|||
} from "antd";
|
||||
// @ts-ignore
|
||||
import { usePersistFn } from "ahooks";
|
||||
import { getImageUrl } from "educoder";
|
||||
import "./style.module.less";
|
||||
import { useAcr, useNote, useGlobal } from "../../model";
|
||||
const AnnotationStatus ={
|
||||
Init : 'Init',
|
||||
Ignore : 'Ignore',
|
||||
Confirm : 'Confirm',
|
||||
FalsePositive : 'FalsePositive',
|
||||
const AnnotationStatus = {
|
||||
Init: 'Init',
|
||||
Ignore: 'Ignore',
|
||||
Confirm: 'Confirm',
|
||||
FalsePositive: 'FalsePositive',
|
||||
}
|
||||
const noteType= {
|
||||
comment : 'Comment',
|
||||
problem : 'Problem',
|
||||
const noteType = {
|
||||
comment: 'Comment',
|
||||
problem: 'Problem',
|
||||
}
|
||||
|
||||
export const Commenting = (props) => {
|
||||
|
|
@ -45,15 +46,16 @@ export const Commenting = (props) => {
|
|||
console.log(props);
|
||||
const submit = usePersistFn(async (note, type) => {
|
||||
try {
|
||||
console.log(note,type);
|
||||
await addComment({
|
||||
note,
|
||||
diffId: toVersion.id,
|
||||
lineCode: props.lineCode,
|
||||
line_code: props.lineCode,
|
||||
discussionId: props.discussionId,
|
||||
path: props.path,
|
||||
type,
|
||||
});
|
||||
props.onClose&&props.onClose();
|
||||
props.onClose && props.onClose();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
|
@ -70,7 +72,7 @@ export const Commenting = (props) => {
|
|||
}, [note, replyNote, isProblem]);
|
||||
|
||||
function insertReplyNote(baseNote, replyNote) {
|
||||
if (replyNote&&replyNote.note) {
|
||||
if (replyNote && replyNote.note) {
|
||||
const replyLine = replyNote.note.split("\n");
|
||||
const blockquoteNote = [
|
||||
`<!-- reply id="${replyNote.id}" -->`,
|
||||
|
|
@ -92,7 +94,9 @@ export const Commenting = (props) => {
|
|||
>
|
||||
<div className="avatar">
|
||||
<Tooltip title={user.name}>
|
||||
<Avatar src={user.avatarUrl} size={24} />
|
||||
<Avatar src={ user && user.image_url
|
||||
? getImageUrl(`/${user.image_url}`)
|
||||
: "images/avatars/User/b"} size={24} />
|
||||
</Tooltip>
|
||||
</div>
|
||||
<Input.TextArea
|
||||
|
|
@ -163,7 +167,7 @@ export const DiscussionItem = memo((props) => {
|
|||
if (replyIds) {
|
||||
for (const replyId of replyIds) {
|
||||
const reviewId = commentPack.noteIdToReviewId.get(replyId);
|
||||
if (reviewId && commentPack.reviewIdToReview.get(reviewId)&&commentPack.reviewIdToReview.get(reviewId).pending) {
|
||||
if (reviewId && commentPack.reviewIdToReview.get(reviewId) && commentPack.reviewIdToReview.get(reviewId).pending) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -190,13 +194,13 @@ export const DiscussionItem = memo((props) => {
|
|||
return (
|
||||
<div className="arc-container">
|
||||
<div>
|
||||
{note.type === noteType.problem && (
|
||||
{/* {note.type === noteType.problem && (
|
||||
<Fragment>
|
||||
{note.state === "resolved" && !pending && "已解决"}
|
||||
{note.state === "opened" && !pending && "待解决"}
|
||||
{pending && "需要回应"}
|
||||
</Fragment>
|
||||
)}
|
||||
)} */}
|
||||
</div>
|
||||
<div style={{ paddingLeft: 16 }}>
|
||||
<div>{note.author.name} 发表评论</div>
|
||||
|
|
@ -246,18 +250,21 @@ export const Menubar = memo((props) => {
|
|||
|
||||
const idToVerbose = new Map();
|
||||
idToVerbose.set(0, "Base Version");
|
||||
|
||||
|
||||
versions.forEach((version, index) => {
|
||||
if (index === 0) {
|
||||
if (index === versions.length - 1) {
|
||||
idToVerbose.set(version.id, `Latest Version`);
|
||||
} else {
|
||||
idToVerbose.set(version.id, `Version ${versions.length - index}`);
|
||||
idToVerbose.set(version.id, `Version ${versions.length - index - 1}`);
|
||||
}
|
||||
});
|
||||
console.log('versions');
|
||||
console.log(versions);
|
||||
const fromId = fromVersion && fromVersion.id || 0;
|
||||
const toId = toVersion && toVersion.id || 0;
|
||||
|
||||
const fromId = fromVersion&&fromVersion.id || 0;
|
||||
const toId = toVersion&&toVersion.id || 0;
|
||||
|
||||
const filterCleared = fromId === 0 && toId === versions[0]&&versions[0].id;
|
||||
const filterCleared = fromId === 0 && toId === versions[0] && versions[0].id;
|
||||
|
||||
function renderMenuItem(version, selectedId) {
|
||||
const verbose = idToVerbose.get(version.id);
|
||||
|
|
@ -272,7 +279,7 @@ export const Menubar = memo((props) => {
|
|||
<span>{version.headCommitSha.slice(0, 8)}</span>
|
||||
</div>
|
||||
<div className='desc'>
|
||||
{ }提交,包含 {version.commitsCount},{version.filesCount} 份文件变更
|
||||
包含 {version.commitsCount}次提交,{version.filesCount} 份文件变更
|
||||
</div>
|
||||
</Menu.Item>
|
||||
);
|
||||
|
|
@ -292,7 +299,7 @@ export const Menubar = memo((props) => {
|
|||
key={0}
|
||||
className={`${'menuItem'} ${fromId === 0 ? 'selected' : ""}`}
|
||||
>
|
||||
Base
|
||||
Base Version
|
||||
</Menu.Item>
|
||||
</Menu>
|
||||
);
|
||||
|
|
@ -389,7 +396,7 @@ export const AnnotationEntry = memo((props) => {
|
|||
useEffect(() => {
|
||||
setTimeout(() => {
|
||||
if (hashActive) {
|
||||
anchorOffsetRef.current&&anchorOffsetRef.current.scrollIntoView(true);
|
||||
anchorOffsetRef.current && anchorOffsetRef.current.scrollIntoView(true);
|
||||
}
|
||||
}, 500);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import { apiService } from './api.service';
|
||||
|
||||
import { message } from 'antd';
|
||||
import { calcChangeLineNum } from './utils/calc-change-line-num';
|
||||
import { underscoreToCamelcase } from './utils/camelcase-convert';
|
||||
import axios from 'axios';
|
||||
import sha1 from 'sha1';
|
||||
|
||||
export const prService = {
|
||||
async getPRByIid(projectsId, owner, mergeId) {
|
||||
|
|
@ -12,7 +13,7 @@ export const prService = {
|
|||
...data,
|
||||
checkSuites: [],
|
||||
iid: data.index,
|
||||
sourceBranch: data.base,
|
||||
sourceBranch: data.head,
|
||||
sourceProjectId: projectsId,
|
||||
// state: "opened",
|
||||
// targetBranch: "master",
|
||||
|
|
@ -42,7 +43,7 @@ export const prService = {
|
|||
|
||||
async getDiffVersions(projectsId, owner, mergeId) {
|
||||
const res = await axios.get(`/v1/${owner}/${projectsId}/pulls/${mergeId}/versions.json`);
|
||||
return Array.isArray(res.data.versions) ? underscoreToCamelcase(res.data.versions) : []
|
||||
return Array.isArray(res.data.versions) ? underscoreToCamelcase(res.data.versions) : [];
|
||||
return (await apiService.get(
|
||||
`/api/v3/projects/42422/pull_requests/13055/diffs`
|
||||
))
|
||||
|
|
@ -93,25 +94,21 @@ export const prService = {
|
|||
))
|
||||
},
|
||||
|
||||
async getCommentPack(
|
||||
projectId,
|
||||
prId,
|
||||
lastFetchedAt
|
||||
) {
|
||||
async getCommentPack(projectsId, owner, mergeId,) {
|
||||
const res = await axios.get(`/v1/${owner}/${projectsId}/pulls/${mergeId}/journals.json`);
|
||||
console.log('getCommentPack');
|
||||
console.log(underscoreToCamelcase(res.data.journals));
|
||||
return underscoreToCamelcase(res.data.journals);
|
||||
return (await apiService.get(
|
||||
'/webapi/projects/42422/pull_requests/13055/comments',
|
||||
{
|
||||
lastFetchedAt,
|
||||
}
|
||||
{}
|
||||
))
|
||||
},
|
||||
|
||||
async editPRComment(
|
||||
projectId,
|
||||
prId,
|
||||
noteId,
|
||||
payload
|
||||
) {
|
||||
async editPRComment(projectsId, owner, mergeId, noteId, data) {
|
||||
const res = await axios.patch(`/v1/${owner}/${projectsId}/pulls/${mergeId}/journals/${noteId}.json`, data);
|
||||
console.log('editPRComment');
|
||||
console.log(res);
|
||||
return (await apiService.put(
|
||||
`/api/v3/projects/42422/pull_requests/13055/comments/${noteId}`,
|
||||
undefined,
|
||||
|
|
@ -124,57 +121,88 @@ export const prService = {
|
|||
options = {}
|
||||
) {
|
||||
const res = await axios.get(`/v1/${owner}/${projectsId}/pulls/${mergeId}/versions/${versionId}/diff.json`, { params: options });
|
||||
// console.log('getDiffById');
|
||||
// console.log(res.data);
|
||||
// return underscoreToCamelcase(res.data);
|
||||
|
||||
let data = res.data;
|
||||
data.compareDiffId = versionId;
|
||||
data.id = data.name;
|
||||
data.addLineNum = data.addition;
|
||||
data.binaryFile = data.is_bin;
|
||||
data.delLineNum = data.deletion;
|
||||
data.deletedFile = data.is_deleted;
|
||||
data.newFile = data.is_created;
|
||||
data.newPath = data.name;
|
||||
data.oldPath = data.oldname;
|
||||
data.renamedFile = data.is_renamed;
|
||||
|
||||
console.log('getDiffById');
|
||||
console.log(res.data);
|
||||
|
||||
return data;
|
||||
|
||||
return (await apiService.get(
|
||||
`/webapi/projects/42422/pull_requests/13055/diffs/31918/changes/1079`,
|
||||
options
|
||||
));
|
||||
// return (await apiService.get(
|
||||
// `/webapi/projects/42422/pull_requests/13055/diffs/${versionId}/changes/${diffId}`,
|
||||
// options
|
||||
// ))
|
||||
},
|
||||
|
||||
async getFileReadMarks(projectId, prId) {
|
||||
return (await apiService.get(
|
||||
`/api/v3/projects/42422/pull_requests/13055/diffs/mark_files`
|
||||
))
|
||||
},
|
||||
async markFileAsRead(projectId, prId, filePathSha) {
|
||||
return (await apiService.put(
|
||||
`/webapi/projects/42422/pull_requests/13055/diffs/mark_file_as_read`,
|
||||
{
|
||||
filePathSha,
|
||||
}
|
||||
))
|
||||
},
|
||||
async markFileAsUnread(projectId, prId, filePathSha) {
|
||||
return (await apiService.put(
|
||||
`/webapi/projects/42422/pull_requests/13055/diffs/mark_file_as_unread`,
|
||||
{
|
||||
filePathSha,
|
||||
}
|
||||
))
|
||||
async getFileReadMarks(projectsId, owner, mergeId,) {
|
||||
const res = await axios.get(`/${owner}/${projectsId}/pulls/${mergeId}/diffs/mark_files.json`,);
|
||||
for (const item of res.data.files) {
|
||||
item.newPath = item.name;
|
||||
item.file_path_sha2 = item.file_path_sha;
|
||||
item.file_path_sha = sha1(item.newPath)
|
||||
}
|
||||
return underscoreToCamelcase(res.data.files);
|
||||
},
|
||||
|
||||
async addComment(projectId, prId, data) {
|
||||
async markFileAsRead(projectsId, owner, mergeId, data) {
|
||||
const res = await axios.put(`/${owner}/${projectsId}/pulls/${mergeId}/diffs/mark_file_as_read.json`, data);
|
||||
return res.data;
|
||||
// console.log('markFileAsRead');
|
||||
// console.log(res);
|
||||
},
|
||||
async markFileAsUnread(projectsId, owner, mergeId, data) {
|
||||
const res = await axios.put(`/${owner}/${projectsId}/pulls/${mergeId}/diffs/mark_file_as_unread.json`, data);
|
||||
return res.data;
|
||||
// console.log('markFileAsRead');
|
||||
// console.log(res);
|
||||
},
|
||||
|
||||
async addComment(projectsId, owner, mergeId, data) {
|
||||
return (await apiService.post(
|
||||
`/webapi/projects/42422/pull_requests/13055/comments`,
|
||||
undefined,
|
||||
data
|
||||
))
|
||||
));
|
||||
},
|
||||
|
||||
async createReview(projectId, prId) {
|
||||
return (await apiService.post(
|
||||
`/api/v3/projects/42422/pull_requests/13055/reviews`
|
||||
))
|
||||
async createReview(projectsId, owner, mergeId, data) {
|
||||
const res = await axios.post(`/v1/${owner}/${projectsId}/pulls/${mergeId}/reviews.json`, data);
|
||||
console.log('createReview--data');
|
||||
if (res.data.id) {
|
||||
return res.data;
|
||||
} else {
|
||||
message.error(res.data && res.data.message);
|
||||
}
|
||||
// return (await apiService.post(
|
||||
// `/api/v3/projects/42422/pull_requests/13055/reviews`
|
||||
// ))
|
||||
},
|
||||
|
||||
async commitReview(projectId, prId, body) {
|
||||
async getReviews(projectsId, owner, mergeId,) {
|
||||
const res = await axios.get(`/v1/${owner}/${projectsId}/pulls/${mergeId}/reviews.json`,);
|
||||
console.log('getReviews');
|
||||
console.log(underscoreToCamelcase(res.data.reviews));
|
||||
return underscoreToCamelcase(res.data.reviews);
|
||||
// for (const item of res.data.files) {
|
||||
// item.newPath = item.name;
|
||||
// item.file_path_sha2 = item.file_path_sha;
|
||||
// item.file_path_sha = sha1(item.newPath)
|
||||
// }
|
||||
// return underscoreToCamelcase(res.data.files);
|
||||
},
|
||||
|
||||
async commitReview(projectsId, owner, mergeId, body) {
|
||||
return await apiService.put(
|
||||
`/api/v3/projects/42422/pull_requests/13055/reviews`,
|
||||
undefined,
|
||||
|
|
|
|||
|
|
@ -60,8 +60,7 @@ export const projectService = {
|
|||
async bulkChangeFiles(
|
||||
projectsId, owner,data
|
||||
) {
|
||||
|
||||
const res = await axios.post(`/v1/${owner}/${projectsId}/contents/batc`,data);
|
||||
const res = await axios.post(`/v1/${owner}/${projectsId}/contents/batch`,data);
|
||||
console.log('bulkChangeFiles--data');
|
||||
console.log(res);
|
||||
// return (await apiService.post(
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
import { apiService } from './api.service';
|
||||
import { underscoreToCamelcase } from './utils/camelcase-convert';
|
||||
import axios from 'axios';
|
||||
import moment from 'moment';
|
||||
|
||||
const format = "YYYY-MM-DD HH:mm:ss";
|
||||
|
||||
export const repoService = {
|
||||
async getFileList(
|
||||
|
|
@ -16,7 +19,7 @@ export const repoService = {
|
|||
path,
|
||||
withCommit,
|
||||
}
|
||||
))
|
||||
))
|
||||
},
|
||||
|
||||
async getTreeEntry(projectId, refName, path) {
|
||||
|
|
@ -26,7 +29,7 @@ export const repoService = {
|
|||
refName,
|
||||
path,
|
||||
}
|
||||
))
|
||||
))
|
||||
},
|
||||
|
||||
// async getFileDetail(
|
||||
|
|
@ -72,17 +75,44 @@ export const repoService = {
|
|||
);
|
||||
},
|
||||
|
||||
async getCodeBlame(projectId, sha, filePath) {
|
||||
const res = await axios.get(`/v1/${owner}/${projectsId}/blame.json`);
|
||||
console.log(res);
|
||||
// return res.
|
||||
async getCodeBlame(projectsId, owner, params) {
|
||||
const res = await axios.get(`/v1/${owner}/${projectsId}/blame.json`, { params });
|
||||
let blame_parts = underscoreToCamelcase(res.data.blame_parts);
|
||||
let blameParts = [];
|
||||
for (const item of blame_parts) {
|
||||
let blamePart = {
|
||||
commit: {
|
||||
author: item.commit.author,
|
||||
// authorEmail: "taian.lta@test.com",
|
||||
authorName: item.commit.author.name,
|
||||
authoredDate: moment(new Date(item.commit.authoredTime*1000)).format(format),
|
||||
committedDate: moment(new Date(item.commit.committedTime*1000)).format(format),
|
||||
committer: item.commit.committer,
|
||||
// committerEmail: "taian.lta@test.com",
|
||||
committerName: item.commit.committer.name,
|
||||
createdAt: moment(new Date(item.commit.createdTime*1000)).format(format),
|
||||
id: item.commit.sha,
|
||||
message: item.commit.commitMessage,
|
||||
// parentIds: null,
|
||||
// shortId: "7c501a19",
|
||||
title: item.commit.commitMessage,
|
||||
// treeHash: null,
|
||||
},
|
||||
lines:[{
|
||||
currentNumber:item.currentNumber,
|
||||
effectLine:item.effectLine,
|
||||
}]
|
||||
};
|
||||
blameParts.push(blamePart);
|
||||
}
|
||||
|
||||
return (await apiService.get(
|
||||
`/api/v3/projects/42422/repository/blame`,
|
||||
{
|
||||
sha,
|
||||
filePath,
|
||||
}
|
||||
))
|
||||
},
|
||||
// blame_parts.push();
|
||||
// console.log(blame_parts);
|
||||
|
||||
return blameParts;
|
||||
|
||||
return(await apiService.get(
|
||||
`/api/v3/projects/42422/repository/blame`,
|
||||
))
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6969,37 +6969,37 @@ export const mockService = {
|
|||
updated_after_read: false,
|
||||
},
|
||||
],
|
||||
'/webapi/projects/42422/repository/diffs': {
|
||||
diffs: [
|
||||
{
|
||||
a_mode: '0',
|
||||
b_mode: '100644',
|
||||
binary_file: false,
|
||||
charset_name: 'UTF-8',
|
||||
deleted_file: false,
|
||||
diff: '@@ -0,0 +1,3 @@\n+<2B><><EFBFBD><EFBFBD> <20><> 6 days ago <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n+<2B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n+123\n\\ No newline at end of file\n',
|
||||
new_file: true,
|
||||
new_path: 'gbk.ts',
|
||||
old_path: 'gbk.ts',
|
||||
renamed_file: false,
|
||||
too_large: false,
|
||||
},
|
||||
{
|
||||
a_mode: '0',
|
||||
b_mode: '100644',
|
||||
binary_file: false,
|
||||
charset_name: 'UTF-8',
|
||||
deleted_file: false,
|
||||
diff: '@@ -0,0 +1,12 @@\n+{\n+ "name": "aaa",\n+ "version": "1.0.0",\n+ "description": "",\n+ "main": "index.js",\n+ "scripts": {\n+ "test": "echo \\"Error: no test specified\\" && exit 1"\n+ },\n+ "keywords": [],\n+ "author": "",\n+ "license": "ISC"\n+}\n\\ No newline at end of file\n',
|
||||
new_file: true,
|
||||
new_path: 'hk-cdp_ALL_api#space#info#popUp.json',
|
||||
old_path: 'hk-cdp_ALL_api#space#info#popUp.json',
|
||||
renamed_file: false,
|
||||
too_large: false,
|
||||
},
|
||||
],
|
||||
overflow: false,
|
||||
},
|
||||
// '/webapi/projects/42422/repository/diffs': {
|
||||
// diffs: [
|
||||
// {
|
||||
// a_mode: '0',
|
||||
// b_mode: '100644',
|
||||
// binary_file: false,
|
||||
// charset_name: 'UTF-8',
|
||||
// deleted_file: false,
|
||||
// diff: '@@ -0,0 +1,3 @@\n+<2B><><EFBFBD><EFBFBD> <20><> 6 days ago <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n+<2B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n+123\n\\ No newline at end of file\n',
|
||||
// new_file: true,
|
||||
// new_path: 'gbk.ts',
|
||||
// old_path: 'gbk.ts',
|
||||
// renamed_file: false,
|
||||
// too_large: false,
|
||||
// },
|
||||
// {
|
||||
// a_mode: '0',
|
||||
// b_mode: '100644',
|
||||
// binary_file: false,
|
||||
// charset_name: 'UTF-8',
|
||||
// deleted_file: false,
|
||||
// diff: '@@ -0,0 +1,12 @@\n+{\n+ "name": "aaa",\n+ "version": "1.0.0",\n+ "description": "",\n+ "main": "index.js",\n+ "scripts": {\n+ "test": "echo \\"Error: no test specified\\" && exit 1"\n+ },\n+ "keywords": [],\n+ "author": "",\n+ "license": "ISC"\n+}\n\\ No newline at end of file\n',
|
||||
// new_file: true,
|
||||
// new_path: 'hk-cdp_ALL_api#space#info#popUp.json',
|
||||
// old_path: 'hk-cdp_ALL_api#space#info#popUp.json',
|
||||
// renamed_file: false,
|
||||
// too_large: false,
|
||||
// },
|
||||
// ],
|
||||
// overflow: false,
|
||||
// },
|
||||
// blame 插件提供的数据
|
||||
'/api/v3/projects/42422/repository/blame': [
|
||||
{
|
||||
|
|
@ -7022,5 +7022,25 @@ export const mockService = {
|
|||
},
|
||||
lines: [{ current_number: 1, effect_line: 12, previous_number: 1 }],
|
||||
},
|
||||
{
|
||||
commit: {
|
||||
author: null,
|
||||
author_email: 'taian.lta@test.com',
|
||||
author_name: 'taian.lta',
|
||||
authored_date: '2020-08-18T12:09:32+0800',
|
||||
committed_date: '2020-08-18T12:09:32+0800',
|
||||
committer: null,
|
||||
committer_email: 'taian.lta@test.com',
|
||||
committer_name: 'taian.lta',
|
||||
created_at: '2020-08-18T12:09:32+0800',
|
||||
id: '7c501a19ae4644814782622af41b72e0f65eaacd2',
|
||||
message: ' feat: 123',
|
||||
parent_ids: null,
|
||||
short_id: '7c501a19',
|
||||
title: ' feat: 123',
|
||||
tree_hash: null,
|
||||
},
|
||||
lines: [{ current_number: 15, effect_line: 10, previous_number: 1 }],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import sha1 from 'sha1';
|
|||
// @ts-ignore
|
||||
import memoize from 'lodash/memoize';
|
||||
import jCookie from 'js-cookie';
|
||||
import { Spin } from 'antd';
|
||||
import { useRequest } from './hooks';
|
||||
import { group, repo, prIid, project } from './meta';
|
||||
import { prService } from './mock/pr.service.js';
|
||||
|
|
@ -95,7 +96,7 @@ const useGlobal = () => React.useContext(ContextProps);
|
|||
|
||||
const [PrProvider, usePr] = createContainer(() => {
|
||||
const { params } = useGlobal();
|
||||
const { owner, projectsId ,mergeId} = params;
|
||||
const { projectsId, owner, mergeId } = params;
|
||||
const data = useRequest(async () => {
|
||||
const pr = await prService.getPRByIid(projectsId, owner, mergeId);
|
||||
console.log('getPRByIidpr');
|
||||
|
|
@ -160,6 +161,8 @@ const [SettingProvider, useSetting] = createContainer(() => {
|
|||
});
|
||||
|
||||
const useCommentPack = (projectId, prId) => {
|
||||
const { params } = useGlobal();
|
||||
const { projectsId, owner, mergeId } = params;
|
||||
const lineToNoteIdSet = useMemo(() => new Map(), []);
|
||||
const noteIdToNote = useMemo(() => new Map(), []);
|
||||
const noteIdToReviewId = useMemo(() => new Map(), []);
|
||||
|
|
@ -224,11 +227,16 @@ const useCommentPack = (projectId, prId) => {
|
|||
return;
|
||||
}
|
||||
fetchingRef.current = true;
|
||||
const pack = await prService.getCommentPack(
|
||||
projectId,
|
||||
prId,
|
||||
force ? undefined : lastFetchAtRef.current
|
||||
);
|
||||
// const pack = await prService.getCommentPack(projectsId, owner, mergeId);
|
||||
const commentPack = await prService.getCommentPack(projectsId, owner, mergeId);
|
||||
const reviews = await prService.getReviews(projectsId, owner, mergeId);
|
||||
for(const review of reviews){
|
||||
review.reviewNotes=commentPack;
|
||||
}
|
||||
const pack = {
|
||||
committedReviews:reviews,
|
||||
notes:commentPack,
|
||||
};
|
||||
console.log('pack');
|
||||
console.log(pack);
|
||||
lastFetchAtRef.current = pack.currentFetchedAt;
|
||||
|
|
@ -310,12 +318,9 @@ const useCommentPack = (projectId, prId) => {
|
|||
async function editNote(
|
||||
noteId, data
|
||||
) {
|
||||
const newNote = await prService.editPRComment(
|
||||
projectId,
|
||||
prId,
|
||||
noteId,
|
||||
data
|
||||
);
|
||||
console.log('editNote');
|
||||
console.log(data);
|
||||
const newNote = await prService.editPRComment(projectsId, owner, mergeId, noteId, data);
|
||||
manualUpdateNote(newNote);
|
||||
newNote.discussions && newNote.discussions.forEach((note) => manualUpdateNote(note));
|
||||
}
|
||||
|
|
@ -362,30 +367,39 @@ const useCommentPack = (projectId, prId) => {
|
|||
};
|
||||
|
||||
const [NoteProvider, useNote] = createContainer(() => {
|
||||
const {
|
||||
project: { id: projectId },
|
||||
// pr: { id: prId },
|
||||
} = useGlobal();
|
||||
|
||||
const { params } = useGlobal();
|
||||
const { projectsId, owner, mergeId } = params;
|
||||
const { pr: { id: prId } } = usePr();
|
||||
const commentPack = useCommentPack(projectId, prId);
|
||||
const commentPack = useCommentPack(projectsId, mergeId);
|
||||
useEffect(() => {
|
||||
commentPack.doRefresh();
|
||||
}, []);
|
||||
|
||||
async function addComment(data) {
|
||||
console.log('addComment----start');
|
||||
console.log(data);
|
||||
if (!commentPack.hasPendingReview) {
|
||||
const review = await prService.createReview(projectId, prId);
|
||||
let reviewData = {
|
||||
content: data.note,
|
||||
status: 'common',
|
||||
}
|
||||
const review = await prService.createReview(projectsId, owner, mergeId, reviewData);
|
||||
commentPack.manualUpdateReview(review);
|
||||
}
|
||||
const note = await prService.addComment(projectId, prId, data);
|
||||
const note = await prService.addComment(projectsId, owner, mergeId, data);
|
||||
commentPack.manualAddNote(note, commentPack.pendingReviewRef.current);
|
||||
}
|
||||
|
||||
async function commitReview(body) {
|
||||
if (!commentPack.hasPendingReview) {
|
||||
await prService.createReview(projectId, prId);
|
||||
let reviewData = {
|
||||
content: body.note,
|
||||
status: 'common',
|
||||
}
|
||||
await prService.createReview(projectsId, owner, mergeId, reviewData);
|
||||
}
|
||||
await prService.commitReview(projectId, prId, body);
|
||||
await prService.commitReview(projectsId, owner, mergeId, body);
|
||||
await commentPack.doRefresh(true);
|
||||
}
|
||||
|
||||
|
|
@ -402,18 +416,16 @@ const [NoteProvider, useNote] = createContainer(() => {
|
|||
});
|
||||
|
||||
const [ReadMarkProvider, useReadMark] = createContainer(() => {
|
||||
const {
|
||||
project: { id: projectId },
|
||||
// pr: { id: prId },
|
||||
} = useGlobal();
|
||||
const { params } = useGlobal();
|
||||
const { projectsId, owner, mergeId } = params;
|
||||
const { pr: { id: prId } } = usePr();
|
||||
|
||||
const [flag, updateFlag] = useState({});
|
||||
|
||||
const readMarks = useRequest(
|
||||
() => prService.getFileReadMarks(projectId, prId),
|
||||
() => prService.getFileReadMarks(projectsId, owner, mergeId,),
|
||||
{
|
||||
deps: [projectId, projectId, flag],
|
||||
deps: [projectsId, owner, mergeId, flag],
|
||||
}
|
||||
);
|
||||
|
||||
|
|
@ -426,13 +438,21 @@ const [ReadMarkProvider, useReadMark] = createContainer(() => {
|
|||
return map;
|
||||
}, [readMarks]);
|
||||
|
||||
const readMarkMap2 = useMemo(() => {
|
||||
const map = new Map();
|
||||
if (!readMarks) return map;
|
||||
for (const mark of readMarks) {
|
||||
map.set(mark.name, mark.filePathSha2);
|
||||
}
|
||||
return map;
|
||||
}, [readMarks]);
|
||||
|
||||
const memoizedSha1 = useMemo(() => memoize(sha1), []);
|
||||
|
||||
async function markFileAsRead(filePath) {
|
||||
const data = await prService.markFileAsRead(
|
||||
projectId,
|
||||
prId,
|
||||
memoizedSha1(filePath)
|
||||
projectsId, owner, mergeId,
|
||||
{ file_path_sha: readMarkMap2.get(filePath) }
|
||||
);
|
||||
updateFlag({});
|
||||
return data;
|
||||
|
|
@ -440,9 +460,8 @@ const [ReadMarkProvider, useReadMark] = createContainer(() => {
|
|||
|
||||
async function markFileAsUnread(filePath) {
|
||||
const data = await prService.markFileAsUnread(
|
||||
projectId,
|
||||
prId,
|
||||
memoizedSha1(filePath)
|
||||
projectsId, owner, mergeId,
|
||||
{ file_path_sha: readMarkMap2.get(filePath) }
|
||||
);
|
||||
updateFlag({});
|
||||
return data;
|
||||
|
|
@ -475,12 +494,12 @@ const [ReadMarkProvider, useReadMark] = createContainer(() => {
|
|||
});
|
||||
|
||||
const [AcrProvider, useAcr] = createContainer(() => {
|
||||
const { project,params } = useGlobal();
|
||||
const { project, params } = useGlobal();
|
||||
const { pr } = usePr();
|
||||
const { charsetName } = useSetting();
|
||||
const { commentPack } = useNote();
|
||||
|
||||
const { owner, projectsId ,mergeId} = params;
|
||||
const { projectsId, owner, mergeId } = params;
|
||||
const [IDEMode, setIDEMode] = useState(true);
|
||||
const toggleViewerType = useCallback(() => {
|
||||
setIDEMode((v) => !v);
|
||||
|
|
@ -517,10 +536,10 @@ const [AcrProvider, useAcr] = createContainer(() => {
|
|||
}
|
||||
|
||||
const versions = useRequest(
|
||||
async () => await prService.getDiffVersions(projectsId , owner, mergeId),
|
||||
async () => await prService.getDiffVersions(projectsId, owner, mergeId),
|
||||
{ initial: [] }
|
||||
);
|
||||
|
||||
|
||||
|
||||
const versionMap = useMemo(() => {
|
||||
const map = new Map();
|
||||
|
|
@ -529,7 +548,7 @@ const [AcrProvider, useAcr] = createContainer(() => {
|
|||
}
|
||||
return map;
|
||||
}, [versions]);
|
||||
const latestVersionId = versions[0] && versions[0].id || pr.diff.id;
|
||||
const latestVersionId = versions[0] && versions[versions.length - 1].id || pr.diff.id;
|
||||
|
||||
const from = query.from;
|
||||
const to = query.to || latestVersionId;
|
||||
|
|
@ -550,7 +569,7 @@ const [AcrProvider, useAcr] = createContainer(() => {
|
|||
let res;
|
||||
if (fromVersion) {
|
||||
res = await prService.getDiffs(
|
||||
projectsId,owner,
|
||||
projectsId, owner,
|
||||
fromVersion.headCommitSha,
|
||||
toVersion.headCommitSha,
|
||||
options
|
||||
|
|
@ -560,7 +579,7 @@ const [AcrProvider, useAcr] = createContainer(() => {
|
|||
} else {
|
||||
if (ignoreWhiteSpace) {
|
||||
res = await prService.getDiffs(
|
||||
projectsId,owner,
|
||||
projectsId, owner,
|
||||
toVersion.baseCommitSha,
|
||||
toVersion.headCommitSha,
|
||||
options
|
||||
|
|
@ -569,7 +588,7 @@ const [AcrProvider, useAcr] = createContainer(() => {
|
|||
console.log(res);
|
||||
} else {
|
||||
const diffs = await prService.getDiffOverviews(
|
||||
projectsId,owner,
|
||||
projectsId, owner,
|
||||
mergeId,
|
||||
toVersion.id
|
||||
);
|
||||
|
|
@ -597,19 +616,11 @@ const [AcrProvider, useAcr] = createContainer(() => {
|
|||
commentPack.doRefresh();
|
||||
}, []);
|
||||
|
||||
async function addComment(data) {
|
||||
console.log('>>>addComment', data);
|
||||
}
|
||||
|
||||
async function commitReview(body) {
|
||||
console.log('>>>commitReview', body);
|
||||
}
|
||||
|
||||
function getDiffById(diffId) {
|
||||
return prService.getDiffById(projectsId,owner,mergeId,toVersion.id,
|
||||
{
|
||||
filepath:diffId,
|
||||
});
|
||||
return prService.getDiffById(projectsId, owner, mergeId, toVersion.id,
|
||||
{
|
||||
filepath: diffId,
|
||||
});
|
||||
// return prService.getDiffById(project.id, pr.id, toVersion.id, diffId, {
|
||||
// charsetName,
|
||||
// });
|
||||
|
|
@ -622,8 +633,8 @@ const [AcrProvider, useAcr] = createContainer(() => {
|
|||
console.log(sha);
|
||||
try {
|
||||
return await projectService.getFileBlob(projectsId, owner, {
|
||||
filepath:path,
|
||||
ref:sha,
|
||||
filepath: path,
|
||||
ref: sha,
|
||||
});
|
||||
// return await projectService.getFileBlob(project.id, sha, path, {
|
||||
// maxSize: maxSize || 250000,
|
||||
|
|
@ -674,7 +685,7 @@ const [AcrProvider, useAcr] = createContainer(() => {
|
|||
});
|
||||
|
||||
export const Provider = (props) => {
|
||||
const match = props.match;
|
||||
const match = props.match;
|
||||
let project = {
|
||||
// "encoding": "UTF-8",
|
||||
"id": 42422,
|
||||
|
|
@ -718,13 +729,13 @@ export const Provider = (props) => {
|
|||
}
|
||||
if (props.current_user) {
|
||||
let current_user = props.current_user;
|
||||
user = {...user, ...current_user, avatar_url: current_user.image_url, name: current_user.username, };
|
||||
user = { ...user, ...current_user, avatar_url: current_user.image_url, name: current_user.username, };
|
||||
}
|
||||
console.log(user);
|
||||
console.log('user');
|
||||
return (
|
||||
<ContextProps.Provider value={{
|
||||
project, user,params:match.params
|
||||
project, user, params: match.params
|
||||
}}>
|
||||
{/* <GlobalProvider> */}
|
||||
<PrProvider>
|
||||
|
|
|
|||
Loading…
Reference in New Issue