|
@@ -100,6 +100,9 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
Integer namespaceId=gitlabUser.getNamespaceId();
|
|
Integer namespaceId=gitlabUser.getNamespaceId();
|
|
|
Project project;
|
|
Project project;
|
|
|
log.info("trying to fork project {} to user {} (whose gitlab id is {})", projectId, userId, gitlabUser.getGitlabUserId());
|
|
log.info("trying to fork project {} to user {} (whose gitlab id is {})", projectId, userId, gitlabUser.getGitlabUserId());
|
|
|
|
|
+ Integer existProjectId=searchForkedProject(namespaceId, projectId);
|
|
|
|
|
+ if(existProjectId!=-1)
|
|
|
|
|
+ return existProjectId;
|
|
|
try{
|
|
try{
|
|
|
gitlabApi.setSudoAsId((long) gitlabUser.getGitlabUserId());
|
|
gitlabApi.setSudoAsId((long) gitlabUser.getGitlabUserId());
|
|
|
project=gitlabApi.getProjectApi().forkProject(new Long(projectId), String.valueOf(namespaceId));
|
|
project=gitlabApi.getProjectApi().forkProject(new Long(projectId), String.valueOf(namespaceId));
|
|
@@ -108,10 +111,21 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
}finally {
|
|
}finally {
|
|
|
gitlabApi.unsudo();
|
|
gitlabApi.unsudo();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return Math.toIntExact(project != null ? project.getId() : null);
|
|
return Math.toIntExact(project != null ? project.getId() : null);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public Integer searchForkedProject(int namespaceId, int projectId) throws GitLabApiException {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Project forkedProject = gitlabApi.getProjectApi().getProject(new Long(projectId));
|
|
|
|
|
+ Project project=gitlabApi.getProjectApi().getProject(String.valueOf(namespaceId),forkedProject.getName());
|
|
|
|
|
+ return Math.toIntExact(project.getId());
|
|
|
|
|
+ } catch (GitLabApiException e){
|
|
|
|
|
+ // 404 project not found
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public Integer forkGroupProject(GroupForkDTO groupForkDTO) throws GitLabApiException {
|
|
public Integer forkGroupProject(GroupForkDTO groupForkDTO) throws GitLabApiException {
|
|
|
int groupId=groupForkDTO.getGroupId();
|
|
int groupId=groupForkDTO.getGroupId();
|