forked from Gitlink/forgeplus-react
修改cloudIDE
This commit is contained in:
parent
886d7cf6cf
commit
250c19d1f0
|
@ -31,7 +31,7 @@
|
|||
<script src="%PUBLIC_URL%js/editormd/editormd.min.js"></script>
|
||||
<script src="%PUBLIC_URL%js/codemirror/merge/merge.js"></script>
|
||||
<script src="https://gw.alipayobjects.com/os/lib/moment/2.29.4/moment.js"></script>
|
||||
<script src="https://gw.alipayobjects.com/os/lib/alipay/alex/2.0.7/bundle/alex.all.global.min.js"></script>
|
||||
<script src="https://gw.alipayobjects.com/os/lib/alipay/alex/2.0.11/bundle/alex.all.global.js"></script>
|
||||
<%= htmlWebpackPlugin.tags.bodyTags %>
|
||||
</body>
|
||||
|
||||
|
|
|
@ -11,10 +11,10 @@ export function getImageUrl(path) {
|
|||
// https://www.educoder.net
|
||||
// https://testbdweb.trustie.net
|
||||
// const local = 'http://localhost:3000'
|
||||
path && !path.startsWith('/') && !path.startsWith('http') && (path = '/'.concat(path));
|
||||
path && !path.startsWith('/') && !path.startsWith('http') && (path = '/'.concat(path));
|
||||
const local = 'https://testforgeplus.trustie.net';
|
||||
if (isDev) {
|
||||
return `${local}/${path}`
|
||||
return `${local}${path}`
|
||||
}
|
||||
return `${path}`;
|
||||
}
|
||||
|
|
|
@ -27,23 +27,6 @@ import { lsifService } from './mock/lsif.service';
|
|||
import { useFileReadMarkChange$ } from './hooks';
|
||||
import { repoService } from './mock/repo.service';
|
||||
|
||||
function findKey(obj) {
|
||||
// console.log('...............')
|
||||
for (const key in obj) {
|
||||
if (key == 'path') {
|
||||
console.log('path');
|
||||
console.log(obj);
|
||||
}
|
||||
let type = Object.prototype.toString.call(obj[key]);
|
||||
if (type.includes('Array')) {
|
||||
for (const item of obj[key]) {
|
||||
findKey(obj[key]);
|
||||
}
|
||||
} else if (type.includes('Object')) {
|
||||
findKey(obj[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const CodeReview = (props) => {
|
||||
const { match: { params: { owner, projectsId, mergeId } }, projectDetail, current_user } = props;
|
||||
|
@ -85,6 +68,8 @@ const CodeReview = (props) => {
|
|||
);
|
||||
|
||||
console.log('fileReadMarkChange$');
|
||||
console.log(fileReadMarkChange$);
|
||||
console.log('readMarks');
|
||||
console.log(readMarks);
|
||||
// 插件激活
|
||||
const [pluginActivated, setPluginActivated] = useState(false);
|
||||
|
@ -237,7 +222,7 @@ const CodeReview = (props) => {
|
|||
console.log(propsIDE);
|
||||
return (
|
||||
|
||||
<div style={{ height: '100%' }}>
|
||||
<div style={{ height: '100%' ,lineHeight:'1.4'}}>
|
||||
{/* <div className="controller">
|
||||
{!IDEMode && (
|
||||
<>
|
||||
|
|
|
@ -25,6 +25,7 @@ import {
|
|||
// @ts-ignore
|
||||
import { usePersistFn } from "ahooks";
|
||||
import { getImageUrl } from "educoder";
|
||||
import { camelcaseToUnderscore } from '../utils/camelcase-convert';
|
||||
import "./style.module.less";
|
||||
import { useAcr, useNote, useGlobal } from "../../model";
|
||||
const AnnotationStatus = {
|
||||
|
@ -41,12 +42,14 @@ const noteType = {
|
|||
export const Commenting = (props) => {
|
||||
const { user } = useGlobal();
|
||||
const { addComment } = useNote();
|
||||
const { toVersion } = useAcr();
|
||||
const { toVersion,stDiff } = useAcr();
|
||||
console.log('Commenting--props');
|
||||
console.log(props);
|
||||
// console.log(stDiff);
|
||||
const submit = usePersistFn(async (note, type) => {
|
||||
try {
|
||||
console.log(note,type);
|
||||
debugger;
|
||||
await addComment({
|
||||
note,
|
||||
diffId: toVersion.id,
|
||||
|
@ -54,6 +57,7 @@ export const Commenting = (props) => {
|
|||
discussionId: props.discussionId,
|
||||
path: props.path,
|
||||
type,
|
||||
diff:stDiff,
|
||||
});
|
||||
props.onClose && props.onClose();
|
||||
} catch (e) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { apiService } from './api.service';
|
||||
import { message } from 'antd';
|
||||
import { getImageUrl } from "educoder";
|
||||
import { calcChangeLineNum } from './utils/calc-change-line-num';
|
||||
import { underscoreToCamelcase } from './utils/camelcase-convert';
|
||||
import axios from 'axios';
|
||||
|
@ -36,17 +37,11 @@ export const prService = {
|
|||
console.log('getPRByIid');
|
||||
console.log(newData);
|
||||
return newData;
|
||||
return (await apiService.get(
|
||||
`/webapi/projects/42422/get_pull_request_by_iid`,
|
||||
));
|
||||
},
|
||||
|
||||
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 (await apiService.get(
|
||||
`/api/v3/projects/42422/pull_requests/13055/diffs`
|
||||
))
|
||||
},
|
||||
|
||||
async getDiffs(
|
||||
|
@ -88,10 +83,6 @@ export const prService = {
|
|||
item.renamedFile = item.is_renamed;
|
||||
}
|
||||
return Array.isArray(res.data.files) ? underscoreToCamelcase(res.data.files) : []
|
||||
|
||||
return (await apiService.get(
|
||||
`/webapi/projects/42422/pull_requests/13055/diffs/31918/changes_overview`
|
||||
))
|
||||
},
|
||||
|
||||
async getCommentPack(projectsId, owner, mergeId,) {
|
||||
|
@ -101,86 +92,12 @@ export const prService = {
|
|||
let journals=underscoreToCamelcase(res.data.journals);
|
||||
for(const item of journals){
|
||||
item.author=item.user;
|
||||
item.author.avatarUrl=item.user.imageUrl;
|
||||
item.author.avatarUrl=item.user.imageUrl?getImageUrl(item.user.imageUrl):'';
|
||||
item.author.username=item.user.name;
|
||||
item.type='Common';
|
||||
|
||||
|
||||
item.stDiff=item.diff;
|
||||
}
|
||||
return journals;
|
||||
|
||||
let a={
|
||||
author: {
|
||||
avatar_url:
|
||||
'https://img.alicdn.com/imgextra/i4/O1CN01tPoJQo20M1TueWZet_!!6000000006834-0-tps-80-80.jpg',
|
||||
email: 'winjo.gwj@test.com',
|
||||
extern_uid: '190046',
|
||||
id: 15346,
|
||||
name: '彦熹',
|
||||
state: 'active',
|
||||
username: 'winjo.gwj',
|
||||
web_url: 'https://test.com.com/nwpipe/u/190046',
|
||||
},
|
||||
commit_id: null,
|
||||
created_at: '2021-07-22T17:21:21+0800',
|
||||
discussion_id: null,
|
||||
id: 200002,
|
||||
is_award: false,
|
||||
labels: [],
|
||||
latest_st_diff: {
|
||||
a_mode: '0',
|
||||
add_line_num: 12,
|
||||
b_mode: '100644',
|
||||
binary_file: false,
|
||||
charset_name: 'UTF-8',
|
||||
commit_sha: 'ab32441adfd6c3c381457717a42f19a7fdd6d59b',
|
||||
compare_diff_id: 31918,
|
||||
del_line_num: 0,
|
||||
deleted_file: false,
|
||||
diff: '@@ -0,0 +1,12 @@\n+{\n+ "name": "aaa",\n+ "version": "1.0.0",\n+ "description": "",\n+ "main": "index.js",\n',
|
||||
id: 1079,
|
||||
new_file: true,
|
||||
new_path: 'aaa/package.json',
|
||||
old_path: 'aaa/package.json',
|
||||
renamed_file: false,
|
||||
too_large: false,
|
||||
},
|
||||
line_code: 'a1cd6d42683feafb8bafa3c3c68369f59d3013e6_0_5',
|
||||
line_type: 'new',
|
||||
note: '测试下',
|
||||
noteable_id: 1759,
|
||||
noteable_type: 'ReviewComment',
|
||||
outdated: false,
|
||||
path: 'aaa/package.json',
|
||||
resolved_at: null,
|
||||
resolved_by: null,
|
||||
st_diff: {
|
||||
a_mode: '0',
|
||||
add_line_num: 12,
|
||||
b_mode: '100644',
|
||||
binary_file: false,
|
||||
charset_name: 'UTF-8',
|
||||
commit_sha: 'ab32441adfd6c3c381457717a42f19a7fdd6d59b',
|
||||
compare_diff_id: 31918,
|
||||
del_line_num: 0,
|
||||
deleted_file: false,
|
||||
diff: '@@ -0,0 +1,12 @@\n+{\n+ "name": "aaa",\n+ "version": "1.0.0",\n+ "description": "",\n+ "main": "index.js",\n',
|
||||
id: 1079,
|
||||
new_file: true,
|
||||
new_path: 'aaa/package.json',
|
||||
old_path: 'aaa/package.json',
|
||||
renamed_file: false,
|
||||
too_large: false,
|
||||
},
|
||||
state: null,
|
||||
system: false,
|
||||
type: 'Comment',
|
||||
updated_at: '2021-07-22T17:21:21+0800',
|
||||
};
|
||||
return (await apiService.get(
|
||||
'/webapi/projects/42422/pull_requests/13055/comments',
|
||||
{}
|
||||
))
|
||||
},
|
||||
|
||||
async editPRComment(projectsId, owner, mergeId, noteId, data) {
|
||||
|
@ -217,44 +134,34 @@ export const prService = {
|
|||
console.log(res.data);
|
||||
|
||||
return data;
|
||||
|
||||
return (await apiService.get(
|
||||
`/webapi/projects/42422/pull_requests/13055/diffs/31918/changes/1079`,
|
||||
options
|
||||
));
|
||||
},
|
||||
|
||||
async getFileReadMarks(projectsId, owner, mergeId,) {
|
||||
const res = await axios.get(`/${owner}/${projectsId}/pulls/${mergeId}/diffs/mark_files.json`,);
|
||||
const res = await axios.get(`/${owner}/${projectsId}/pulls/${mergeId}/diffs/mark_files.json`);
|
||||
let data=[];
|
||||
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)
|
||||
if(item.mark_as_read){
|
||||
item.newPath = item.name;
|
||||
item.file_path_sha2 = item.file_path_sha;
|
||||
item.file_path_sha = sha1(item.newPath);
|
||||
data.push(item);
|
||||
}
|
||||
}
|
||||
return underscoreToCamelcase(res.data.files);
|
||||
return underscoreToCamelcase(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) {
|
||||
const res = await axios.post(`/v1/${owner}/${projectsId}/pulls/${mergeId}/journals.json`, data);
|
||||
return res.data;
|
||||
// return (await apiService.post(
|
||||
// `/webapi/projects/42422/pull_requests/13055/comments`,
|
||||
// undefined,
|
||||
// data
|
||||
// ));
|
||||
},
|
||||
|
||||
async createReview(projectsId, owner, mergeId, data) {
|
||||
|
@ -265,9 +172,6 @@ export const prService = {
|
|||
} else {
|
||||
message.error(res.data && res.data.message);
|
||||
}
|
||||
// return (await apiService.post(
|
||||
// `/api/v3/projects/42422/pull_requests/13055/reviews`
|
||||
// ))
|
||||
},
|
||||
|
||||
async getReviews(projectsId, owner, mergeId,) {
|
||||
|
@ -277,13 +181,14 @@ export const prService = {
|
|||
let reviews=underscoreToCamelcase(res.data.reviews);
|
||||
for(const item of reviews){
|
||||
item.author=item.reviewer;
|
||||
item.author.avatarUrl=item.reviewer.imageUrl;
|
||||
item.author.avatarUrl=getImageUrl(item.reviewer.imageUrl);
|
||||
item.author.username=item.reviewer.name;
|
||||
item.author.webUrl='';
|
||||
item.body=item.content;
|
||||
// item.pending=false;
|
||||
item.pending=false;
|
||||
item.pullRequestId=mergeId;
|
||||
}
|
||||
return [reviews[0]];
|
||||
return reviews;
|
||||
// for (const item of res.data.files) {
|
||||
// item.newPath = item.name;
|
||||
// item.file_path_sha2 = item.file_path_sha;
|
||||
|
|
|
@ -19,30 +19,6 @@ export const projectService = {
|
|||
return res.data.entries.content;
|
||||
},
|
||||
|
||||
// async getFileBlob(
|
||||
// projectId,
|
||||
// sha,
|
||||
// filepath,
|
||||
// options= {}
|
||||
// ) {
|
||||
// return (await apiService.get(
|
||||
// `/api/v3/projects/42422/repository/blobs/ab32441adfd6c3c381457717a42f19a7fdd6d59b`,
|
||||
// {
|
||||
// filepath,
|
||||
// ...options,
|
||||
// }
|
||||
// ))
|
||||
|
||||
// // return (await apiService.get(
|
||||
// // `/api/v3/projects/42422/repository/blobs/${encodeURIComponent(
|
||||
// // sha
|
||||
// // )}`,
|
||||
// // {
|
||||
// // filepath,
|
||||
// // ...options,
|
||||
// // }
|
||||
// // ))
|
||||
// },
|
||||
|
||||
async getLanguages(
|
||||
projectId,
|
||||
|
@ -63,13 +39,5 @@ export const projectService = {
|
|||
const res = await axios.post(`/v1/${owner}/${projectsId}/contents/batch`,data);
|
||||
console.log('bulkChangeFiles--data');
|
||||
console.log(res);
|
||||
// return (await apiService.post(
|
||||
// `/api/v4/projects/42422/repository/files`,
|
||||
// undefined,
|
||||
// {
|
||||
// actions,
|
||||
// header,
|
||||
// }
|
||||
// ))
|
||||
},
|
||||
};
|
||||
|
|
|
@ -23,6 +23,7 @@ import { projectService } from './mock/project.service.js';
|
|||
import { mapGetSet } from './mock/utils/map-get-set.js';
|
||||
import { isApiError } from './mock/utils/api-error.js';
|
||||
import { mockService } from './mock/request/mock';
|
||||
import { Base64 } from 'js-base64';
|
||||
import './style.less';
|
||||
|
||||
|
||||
|
@ -179,16 +180,19 @@ const useCommentPack = (projectId, prId) => {
|
|||
// const pack = await prService.getCommentPack(projectsId, owner, mergeId);
|
||||
const commentPack = await prService.getCommentPack(projectsId, owner, mergeId);
|
||||
const reviews = await prService.getReviews(projectsId, owner, mergeId);
|
||||
// debugger
|
||||
for (const review of reviews) {
|
||||
review.reviewNotes = commentPack;
|
||||
}
|
||||
const pack = {
|
||||
committedReviews: reviews,
|
||||
notes: commentPack,
|
||||
notes: [],
|
||||
pendingReview: reviews[0],
|
||||
};
|
||||
// pack.pendingReview.reviewNotes=[];
|
||||
console.log('pack');
|
||||
console.log(pack);
|
||||
debugger
|
||||
lastFetchAtRef.current = pack.currentFetchedAt;
|
||||
let updated = false;
|
||||
if (force) {
|
||||
|
@ -385,26 +389,27 @@ const [ReadMarkProvider, useReadMark] = createContainer(() => {
|
|||
const map = new Map();
|
||||
if (!readMarks) return map;
|
||||
for (const mark of readMarks) {
|
||||
map.set(mark.filePathSha, mark);
|
||||
mark.markAsRead&& map.set(mark.filePathSha, mark);
|
||||
}
|
||||
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 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(
|
||||
projectsId, owner, mergeId,
|
||||
{ file_path_sha: readMarkMap2.get(filePath) }
|
||||
{ file_path_sha: Base64.encode(filePath) }
|
||||
// { file_path_sha: readMarkMap2.get(filePath) }
|
||||
);
|
||||
updateFlag({});
|
||||
return data;
|
||||
|
@ -413,7 +418,8 @@ const [ReadMarkProvider, useReadMark] = createContainer(() => {
|
|||
async function markFileAsUnread(filePath) {
|
||||
const data = await prService.markFileAsUnread(
|
||||
projectsId, owner, mergeId,
|
||||
{ file_path_sha: readMarkMap2.get(filePath) }
|
||||
{ file_path_sha: Base64.encode(filePath) }
|
||||
// { file_path_sha: readMarkMap2.get(filePath) }
|
||||
);
|
||||
updateFlag({});
|
||||
return data;
|
||||
|
@ -457,6 +463,7 @@ const [AcrProvider, useAcr] = createContainer(() => {
|
|||
setIDEMode((v) => !v);
|
||||
}, [setIDEMode]);
|
||||
|
||||
const [stDiff,setStDiff]=useState({});
|
||||
const [search, setSearch] = useState(window.location.search);
|
||||
const query = useMemo(() => {
|
||||
const searchParams = new URLSearchParams(search);
|
||||
|
@ -568,21 +575,24 @@ const [AcrProvider, useAcr] = createContainer(() => {
|
|||
commentPack.doRefresh();
|
||||
}, []);
|
||||
|
||||
function getDiffById(diffId) {
|
||||
return prService.getDiffById(projectsId, owner, mergeId, toVersion.id,
|
||||
async function getDiffById(diffId) {
|
||||
let thisStDiff= await prService.getDiffById(projectsId, owner, mergeId, toVersion.id,
|
||||
{
|
||||
filepath: diffId,
|
||||
});
|
||||
delete thisStDiff.sections
|
||||
setStDiff(thisStDiff);
|
||||
return thisStDiff;
|
||||
// prService.getDiffById(projectsId, owner, mergeId, toVersion.id,
|
||||
// {
|
||||
// filepath: diffId,
|
||||
// });
|
||||
// return prService.getDiffById(project.id, pr.id, toVersion.id, diffId, {
|
||||
// charsetName,
|
||||
// });
|
||||
}
|
||||
|
||||
async function getFileContent(path, sha, maxSize) {
|
||||
console.log('getFileContent--path');
|
||||
console.log(path);
|
||||
console.log('getFileContent--sha');
|
||||
console.log(sha);
|
||||
try {
|
||||
return await projectService.getFileBlob(projectsId, owner, {
|
||||
filepath: path,
|
||||
|
@ -628,6 +638,7 @@ const [AcrProvider, useAcr] = createContainer(() => {
|
|||
fromVersion,
|
||||
toVersion,
|
||||
getDiffById,
|
||||
stDiff,
|
||||
getFileContent,
|
||||
IDEMode,
|
||||
toggleViewerType,
|
||||
|
|
Loading…
Reference in New Issue