|
|
@@ -1,25 +1,27 @@
|
|
|
package com.nju.edu.gitlab.service.impl;
|
|
|
|
|
|
+import com.nju.edu.gitlab.dto.*;
|
|
|
import com.nju.edu.gitlab.dto.commit.CommitDTO;
|
|
|
import com.nju.edu.gitlab.dto.project.ProjectDTO;
|
|
|
import com.nju.edu.gitlab.entity.GitlabUser;
|
|
|
import com.nju.edu.gitlab.repository.GitlabUserRepository;
|
|
|
import com.nju.edu.gitlab.service.api.ProjectService;
|
|
|
import com.nju.edu.gitlab.util.ApplicationProperties;
|
|
|
-import com.nju.edu.gitlab.dto.*;
|
|
|
import com.nju.edu.gitlab.vo.BranchVO;
|
|
|
+import com.nju.edu.gitlab.vo.DiffVO;
|
|
|
import com.nju.edu.gitlab.vo.ProjectVO;
|
|
|
import com.nju.edu.gitlab.vo.VisibilityVO;
|
|
|
-import com.nju.edu.gitlab.vo.commit.CommitStatsVO;
|
|
|
import com.nju.edu.gitlab.vo.commit.CommitVO;
|
|
|
-import com.nju.edu.gitlab.vo.DiffVO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.gitlab4j.api.*;
|
|
|
import org.gitlab4j.api.models.*;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import java.io.*;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
import java.net.URLDecoder;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -49,7 +51,7 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
project.setVisibility(visibility);
|
|
|
project=gitlabApi.getProjectApi().createProject(project);
|
|
|
return ProjectVO.builder()
|
|
|
- .projectId(project.getId())
|
|
|
+ .projectId(Math.toIntExact(project.getId()))
|
|
|
.webUrl(project.getWebUrl())
|
|
|
.projectName(projectName)
|
|
|
.build();
|
|
|
@@ -62,11 +64,11 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
Project project=new Project();
|
|
|
project.setName(projectDTO.getProjectName());
|
|
|
project.setVisibility(projectDTO.getVisibility());
|
|
|
- gitlabApi.setSudoAsId(gitlabUser.getGitlabUserId());
|
|
|
+ gitlabApi.setSudoAsId((long) gitlabUser.getGitlabUserId());
|
|
|
project=gitlabApi.getProjectApi().createProject(project);
|
|
|
gitlabApi.unsudo();
|
|
|
return ProjectVO.builder()
|
|
|
- .projectId(project.getId())
|
|
|
+ .projectId(Math.toIntExact(project.getId()))
|
|
|
.webUrl(project.getWebUrl())
|
|
|
.projectName(project.getName())
|
|
|
.build();
|
|
|
@@ -87,15 +89,15 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
Project project;
|
|
|
log.info("trying to fork project {} to user {} (whose gitlab id is {})", projectId, userId, gitlabUser.getGitlabUserId());
|
|
|
try{
|
|
|
- gitlabApi.setSudoAsId(gitlabUser.getGitlabUserId());
|
|
|
- project=gitlabApi.getProjectApi().forkProject(projectId,namespaceId);
|
|
|
+ gitlabApi.setSudoAsId((long) gitlabUser.getGitlabUserId());
|
|
|
+ project=gitlabApi.getProjectApi().forkProject(projectId, String.valueOf(namespaceId));
|
|
|
project.setVisibility(Visibility.PRIVATE);
|
|
|
project=gitlabApi.getProjectApi().updateProject(project);
|
|
|
}finally {
|
|
|
gitlabApi.unsudo();
|
|
|
}
|
|
|
|
|
|
- return project!=null?project.getId():null;
|
|
|
+ return Math.toIntExact(project != null ? project.getId() : null);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -109,14 +111,14 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
Project project;
|
|
|
try{
|
|
|
gitlabApi.sudo("root");
|
|
|
- project=gitlabApi.getProjectApi().forkProject(projectId,namespaceId);
|
|
|
+ project=gitlabApi.getProjectApi().forkProject(projectId, String.valueOf(namespaceId));
|
|
|
project.setVisibility(Visibility.PRIVATE);
|
|
|
project=gitlabApi.getProjectApi().updateProject(project);
|
|
|
}finally {
|
|
|
gitlabApi.unsudo();
|
|
|
}
|
|
|
|
|
|
- return project!=null?project.getId():null;
|
|
|
+ return Math.toIntExact(project != null ? project.getId() : null);
|
|
|
}
|
|
|
|
|
|
private Integer fetchGroupNameSpaceId(String name) throws GitLabApiException {
|
|
|
@@ -126,7 +128,7 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
.filter(ns -> "group".equals(ns.getKind()))
|
|
|
.reduce((ns1, ns2) -> ns1.getId() > ns2.getId() ? ns1 : ns2)
|
|
|
.orElse(null);
|
|
|
- return namespace != null ? namespace.getId() : null;
|
|
|
+ return Math.toIntExact(namespace != null ? namespace.getId() : null);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -167,7 +169,7 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
public String getProjectFile(int projectId,ProjectFileDTO projectFileDTO) throws UnsupportedEncodingException, GitLabApiException {
|
|
|
String branch=projectFileDTO.getBranch();
|
|
|
String path=projectFileDTO.getPath();
|
|
|
- RepositoryFile repositoryFile = gitlabApi.getRepositoryFileApi().getFile(path,projectId,branch);
|
|
|
+ RepositoryFile repositoryFile = gitlabApi.getRepositoryFileApi().getFile(path, (long) projectId,branch);
|
|
|
if(repositoryFile!=null){
|
|
|
return new String(Base64.getDecoder().decode(repositoryFile.getContent()), "UTF-8");
|
|
|
}
|
|
|
@@ -302,22 +304,22 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
int userId = updateMemberDTO.getUserId();
|
|
|
GitlabUser gitlabUser = getGitlabUser(userId);
|
|
|
AccessLevel accessLevel = updateMemberDTO.getAccessLevel();
|
|
|
- gitlabApi.getProjectApi().addMember(projectId,gitlabUser.getGitlabUserId(),accessLevel);
|
|
|
+ gitlabApi.getProjectApi().addMember(projectId, Long.valueOf(gitlabUser.getGitlabUserId()),accessLevel);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<ProjectVO> getAllProjectByUserId(int userId) throws GitLabApiException {
|
|
|
GitlabUser gitlabUser = getGitlabUser(userId);
|
|
|
- gitlabApi.setSudoAsId(gitlabUser.getGitlabUserId());
|
|
|
- List<ProjectVO> projectVOS = gitlabApi.getProjectApi().getMemberProjects().stream().map(project->ProjectVO.builder().projectId(project.getId()).webUrl(project.getWebUrl()).projectName(project.getName()).build()).collect(Collectors.toList());
|
|
|
+ gitlabApi.setSudoAsId((long) gitlabUser.getGitlabUserId());
|
|
|
+ List<ProjectVO> projectVOS = gitlabApi.getProjectApi().getMemberProjects().stream().map(project->ProjectVO.builder().projectId(Math.toIntExact(project.getId())).webUrl(project.getWebUrl()).projectName(project.getName()).build()).collect(Collectors.toList());
|
|
|
gitlabApi.unsudo();
|
|
|
return projectVOS;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<Integer> getProjectJoinedUserId(int projectId) throws GitLabApiException {
|
|
|
- List<Integer> gitlabUserIds = gitlabApi.getProjectApi().getMembers(projectId).stream().map(Member::getId).collect(Collectors.toList());
|
|
|
+ List<Integer> gitlabUserIds = gitlabApi.getProjectApi().getMembers(projectId).stream().map(Member::getId).map(l -> Math.toIntExact(l)).collect(Collectors.toList());
|
|
|
return gitlabUserRepository.findAllByGitlabUserIdIn(gitlabUserIds).stream()
|
|
|
.map(GitlabUser::getUserId)
|
|
|
.collect(Collectors.toList());
|
|
|
@@ -350,7 +352,7 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
@Override
|
|
|
public MergeRequest mergeBranch(int projectId, String sourceBranch, String targetBranch, String title, String description, int reviewerId) throws GitLabApiException {
|
|
|
MergeRequestApi mergeRequestApi = gitlabApi.getMergeRequestApi();
|
|
|
- MergeRequest mergeRequest = mergeRequestApi.createMergeRequest(projectId, sourceBranch, targetBranch, title, description, reviewerId);
|
|
|
+ MergeRequest mergeRequest = mergeRequestApi.createMergeRequest(projectId, sourceBranch, targetBranch, title, description, Long.valueOf(reviewerId));
|
|
|
return mergeRequestApi.acceptMergeRequest(projectId, mergeRequest.getIid());
|
|
|
}
|
|
|
|