合并请求需请求两次获取分支的接口

This commit is contained in:
caishi 2022-05-07 14:38:49 +08:00
parent dbadc3f1a0
commit 9f58eb1a5a
2 changed files with 26 additions and 20 deletions

View File

@ -25,7 +25,7 @@ if (isDev) {
}
debugType = window.location.search.indexOf('debug=t') !== -1 ? 'teacher' :
window.location.search.indexOf('debug=s') !== -1 ? 'student' :
window.location.search.indexOf('debug=a') !== -1 ? 'admin' : parsed.debug || 'student'
window.location.search.indexOf('debug=a') !== -1 ? 'admin' : parsed.debug || 'admin'
}
window._debugType = debugType;
export function initAxiosInterceptors(props) {

View File

@ -99,6 +99,7 @@ class CreateMerge extends Component {
// 再调用比较接口
const branchParams = getBranchParams(this.props.location.pathname);
this.getMergeInfo(branchParams,true);
this.checkBranch(branchParams);
};
componentDidUpdate = (preProps) => {
@ -108,6 +109,7 @@ class CreateMerge extends Component {
if (oldPathname !== newPathname) {
const branchParams = getBranchParams(newPathname);
this.getMergeInfo(branchParams);
this.checkBranch(branchParams);
}
};
@ -134,10 +136,9 @@ class CreateMerge extends Component {
merge: returnbar(mergeBranch),
pull: returnbar(pullBranch),
});
this.checkBranch(branchParams);
this.setState({
isSpin: false,isCompareSpin: false
});
// this.setState({
// isSpin: false,isCompareSpin: false
// });
}
})
.catch((error) => {
@ -148,10 +149,14 @@ class CreateMerge extends Component {
checkBranch=async(branchParams)=>{
const { mergeBranch , mergeOwner, projectId , pullBranch ,pullOwner} = branchParams;
let getbranch =await this.getBranchList(mergeOwner,projectId,pullBranch,mergeBranch);
// let checkpull =await this.getBranchList(pullOwner,projectId,pullBranch,"pull");
if(getbranch){
let getbranch =await this.getBranchList(mergeOwner,projectId,pullBranch,mergeBranch,"merge");
let checkpull =await this.getBranchList(pullOwner,projectId,pullBranch,mergeBranch,"pull");
if(getbranch && checkpull){
this.compareProject(mergeOwner === pullOwner, branchParams);
}else{
this.setState({
isSpin: false,isCompareSpin: false
});
}
}
@ -180,13 +185,9 @@ class CreateMerge extends Component {
}
this.setState({
comparesData: result.data,
isSpin: false,isCompareSpin: false
});
}
this.setState({
isFirstLoading: false,
isSpin: false,
isCompareSpin: false,
});
})
.catch((error) => {
this.setState({ isSpin: false, isCompareSpin: false });
@ -194,13 +195,22 @@ class CreateMerge extends Component {
};
// 根据所有者、仓库名,获取分支列表,目前仅涉及目标仓库分支查询
getBranchList =async(owner,identifier,branch,mergebranch) => {
getBranchList =async(owner,identifier,branch,mergebranch,type) => {
const url = `/${owner}/${identifier}/branches.json`;
let check = await axios.get(url).then((result) => {
if(result.data){
let pfilter = (result.data || []).filter(i => i.name === branch).length === 0;
let mfilter = (result.data || []).filter(i => i.name === mergebranch).length === 0;
if(pfilter){
if(type === "pull"){
this.setState({
pullBranches:result.data,
})
}else{
this.setState({
mergeBranches:result.data
})
}
if(type === "pull" && pfilter){
this.setState({
showMessage: branch,
defaultMessage: `源分支不存在`,
@ -208,7 +218,7 @@ class CreateMerge extends Component {
});
return false;
}
if(mfilter){
if(type === "merge" && mfilter){
this.setState({
showMessage: mergebranch,
defaultMessage: `目标分支不存在`,
@ -216,10 +226,6 @@ class CreateMerge extends Component {
});
return false;
}
this.setState({
pullBranches:result.data,
mergeBranches:result.data
})
return true;
}
})