|
|
@@ -0,0 +1,505 @@
|
|
|
+package com.nju.edu.gitlab;
|
|
|
+
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.nju.edu.gitlab.dto.*;
|
|
|
+import com.nju.edu.gitlab.dto.commit.CommitActionForm;
|
|
|
+import com.nju.edu.gitlab.dto.commit.CommitDTO;
|
|
|
+import com.nju.edu.gitlab.dto.member.AccessLevelForm;
|
|
|
+import com.nju.edu.gitlab.dto.member.GroupMemberDTO;
|
|
|
+import com.nju.edu.gitlab.dto.project.ProjectDTO;
|
|
|
+import com.nju.edu.gitlab.dto.project.VisibilityForm;
|
|
|
+import com.nju.edu.gitlab.vo.BranchVO;
|
|
|
+import com.nju.edu.gitlab.vo.DiffVO;
|
|
|
+import com.nju.edu.gitlab.vo.GitlabGroup;
|
|
|
+import com.nju.edu.gitlab.vo.GitlabUser;
|
|
|
+import com.nju.edu.gitlab.vo.commit.CommitVO;
|
|
|
+import com.sun.org.slf4j.internal.Logger;
|
|
|
+import com.sun.org.slf4j.internal.LoggerFactory;
|
|
|
+import okhttp3.*;
|
|
|
+import org.gitlab4j.api.models.AccessLevel;
|
|
|
+import org.gitlab4j.api.models.CommitAction;
|
|
|
+import org.gitlab4j.api.models.Visibility;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import static com.nju.edu.gitlab.SeecoderGitlabException.BIZ_ERROR_CODE;
|
|
|
+
|
|
|
+public class SeecoderGitlabClient implements SeecoderGitlabApi{
|
|
|
+
|
|
|
+ private final Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
+
|
|
|
+ private OkHttpClient client;
|
|
|
+ private String host;
|
|
|
+ private String token;
|
|
|
+
|
|
|
+ public SeecoderGitlabClient(String host,String token){
|
|
|
+ this.token=token;
|
|
|
+ this.host=host;
|
|
|
+ this.client=new OkHttpClient.Builder()
|
|
|
+ .connectTimeout(60, TimeUnit.SECONDS)
|
|
|
+ .writeTimeout(60,TimeUnit.SECONDS)
|
|
|
+ .retryOnConnectionFailure(true)
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+ private <T> T processResponse(ObjectMapper objectMapper, Response response, Class<T> clazz) throws SeecoderGitlabException {
|
|
|
+ try {
|
|
|
+ validateResponseStatus(response);
|
|
|
+ String body = response.body().string();
|
|
|
+ JsonNode node = objectMapper.readTree(body);
|
|
|
+ Integer code = Integer.parseInt(node.get("code").asText());
|
|
|
+ String msg = node.get("msg").asText();
|
|
|
+ if (code != 0) {
|
|
|
+ throw new SeecoderGitlabException(BIZ_ERROR_CODE, msg);
|
|
|
+ }
|
|
|
+ if (clazz == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (node.get("result")!=null)
|
|
|
+ return objectMapper.treeToValue(node.get("result"), clazz);
|
|
|
+ else
|
|
|
+ throw SeecoderGitlabException.NOT_FOUND_ERROR;
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("IOException", e);
|
|
|
+ throw SeecoderGitlabException.IO_ERROR;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void validateResponseStatus(Response response) throws SeecoderGitlabException {
|
|
|
+ if (response.code() == 403) {
|
|
|
+ throw SeecoderGitlabException.UNAHTORIZATION_ERROR;
|
|
|
+ } else if (response.code() == 500) {
|
|
|
+ throw SeecoderGitlabException.INTERNAL_SERVER_ERROR;
|
|
|
+ } else if (response.code() != 200) {
|
|
|
+ throw SeecoderGitlabException.UNKNOWN_ERROR;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public GitlabUser createGitlabUser(String username, String password, String email) throws SeecoderGitlabException {
|
|
|
+ try {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ Request.Builder builder = new Request.Builder()
|
|
|
+ .addHeader("Authorization", token);
|
|
|
+ GitlabUserDTO gitlabUserDTO=GitlabUserDTO.builder()
|
|
|
+ .email(email)
|
|
|
+ .password(password)
|
|
|
+ .username(username)
|
|
|
+ .build();
|
|
|
+ builder = builder
|
|
|
+ .url(host + "/api/user")
|
|
|
+ .post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), objectMapper.writeValueAsString(gitlabUserDTO)));
|
|
|
+ Request request = builder.build();
|
|
|
+ final Call call = client.newCall(request);
|
|
|
+ Response response = call.execute();
|
|
|
+ GitlabUser gitlabUser = processResponse(objectMapper, response, GitlabUser.class);
|
|
|
+ return gitlabUser;
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ logger.error("JSON writeValueAsString error", e);
|
|
|
+ throw SeecoderGitlabException.JSON_ERROR;
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("IOException", e);
|
|
|
+ throw SeecoderGitlabException.IO_ERROR;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean changePassword(int userId, String password) throws SeecoderGitlabException {
|
|
|
+ try {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ Request.Builder builder = new Request.Builder()
|
|
|
+ .addHeader("Authorization", token);
|
|
|
+ ChangePasswordDTO changePasswordDTO=ChangePasswordDTO.builder()
|
|
|
+ .password(password)
|
|
|
+ .userId(userId)
|
|
|
+ .build();
|
|
|
+ builder = builder
|
|
|
+ .url(host + "/api/user/changePassword")
|
|
|
+ .post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), objectMapper.writeValueAsString(changePasswordDTO)));
|
|
|
+ Request request = builder.build();
|
|
|
+ final Call call = client.newCall(request);
|
|
|
+ Response response = call.execute();
|
|
|
+ boolean isChanged = processResponse(objectMapper, response, boolean.class);
|
|
|
+ return isChanged;
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ logger.error("JSON writeValueAsString error", e);
|
|
|
+ throw SeecoderGitlabException.JSON_ERROR;
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("IOException", e);
|
|
|
+ throw SeecoderGitlabException.IO_ERROR;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean deleteUser(int userId) throws SeecoderGitlabException {
|
|
|
+ try {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ Request.Builder builder = new Request.Builder()
|
|
|
+ .addHeader("Authorization", token);
|
|
|
+ builder = builder
|
|
|
+ .url(host + "/api/user/"+userId)
|
|
|
+ .delete();
|
|
|
+ Request request = builder.build();
|
|
|
+ final Call call = client.newCall(request);
|
|
|
+ Response response = call.execute();
|
|
|
+ boolean isDeleted = processResponse(objectMapper, response, boolean.class);
|
|
|
+ return isDeleted;
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ logger.error("JSON writeValueAsString error", e);
|
|
|
+ throw SeecoderGitlabException.JSON_ERROR;
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("IOException", e);
|
|
|
+ throw SeecoderGitlabException.IO_ERROR;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public GitlabGroup createGroup(String groupName) throws SeecoderGitlabException {
|
|
|
+ try {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ Request.Builder builder = new Request.Builder()
|
|
|
+ .addHeader("Authorization", token);
|
|
|
+ builder = builder
|
|
|
+ .url(host + "/api/user")
|
|
|
+ .post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), groupName));
|
|
|
+ Request request = builder.build();
|
|
|
+ final Call call = client.newCall(request);
|
|
|
+ Response response = call.execute();
|
|
|
+ GitlabGroup gitlabGroup = processResponse(objectMapper, response, GitlabGroup.class);
|
|
|
+ return gitlabGroup;
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ logger.error("JSON writeValueAsString error", e);
|
|
|
+ throw SeecoderGitlabException.JSON_ERROR;
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("IOException", e);
|
|
|
+ throw SeecoderGitlabException.IO_ERROR;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean addMember(int groupId, int userId, AccessLevelForm accessLevelForm) throws SeecoderGitlabException {
|
|
|
+ try {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ Request.Builder builder = new Request.Builder()
|
|
|
+ .addHeader("Authorization", token);
|
|
|
+ AccessLevel accessLevel=AccessLevel.forValue(accessLevelForm.value);
|
|
|
+ GroupMemberDTO groupMemberDTO=GroupMemberDTO.builder()
|
|
|
+ .accessLevel(accessLevel)
|
|
|
+ .userId(userId)
|
|
|
+ .groupId(groupId)
|
|
|
+ .build();
|
|
|
+ builder = builder
|
|
|
+ .url(host + "/api/group/addMember")
|
|
|
+ .post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), objectMapper.writeValueAsString(groupMemberDTO)));
|
|
|
+ Request request = builder.build();
|
|
|
+ final Call call = client.newCall(request);
|
|
|
+ Response response = call.execute();
|
|
|
+ boolean isAdded = processResponse(objectMapper, response, boolean.class);
|
|
|
+ return isAdded;
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ logger.error("JSON writeValueAsString error", e);
|
|
|
+ throw SeecoderGitlabException.JSON_ERROR;
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("IOException", e);
|
|
|
+ throw SeecoderGitlabException.IO_ERROR;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer createProject(String projectName, VisibilityForm visibilityForm) throws SeecoderGitlabException {
|
|
|
+ try {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ Request.Builder builder = new Request.Builder()
|
|
|
+ .addHeader("Authorization", token);
|
|
|
+ Visibility visibility=Visibility.forValue(visibilityForm.toString());
|
|
|
+ ProjectDTO projectDTO= ProjectDTO.builder()
|
|
|
+ .projectName(projectName)
|
|
|
+ .visibility(visibility)
|
|
|
+ .build();
|
|
|
+ builder = builder
|
|
|
+ .url(host + "/api/project")
|
|
|
+ .post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), objectMapper.writeValueAsString(projectDTO)));
|
|
|
+ Request request = builder.build();
|
|
|
+ final Call call = client.newCall(request);
|
|
|
+ Response response = call.execute();
|
|
|
+ return processResponse(objectMapper, response, Integer.class);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ logger.error("JSON writeValueAsString error", e);
|
|
|
+ throw SeecoderGitlabException.JSON_ERROR;
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("IOException", e);
|
|
|
+ throw SeecoderGitlabException.IO_ERROR;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer forkProject(int projectId, int userId) throws SeecoderGitlabException {
|
|
|
+ try {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ Request.Builder builder = new Request.Builder()
|
|
|
+ .addHeader("Authorization", token);
|
|
|
+ UserForkDTO userForkDTO= UserForkDTO.builder()
|
|
|
+ .projectId(projectId)
|
|
|
+ .userId(userId)
|
|
|
+ .build();
|
|
|
+ builder = builder
|
|
|
+ .url(host + "/api/project/userFork")
|
|
|
+ .post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), objectMapper.writeValueAsString(userForkDTO)));
|
|
|
+ Request request = builder.build();
|
|
|
+ final Call call = client.newCall(request);
|
|
|
+ Response response = call.execute();
|
|
|
+ projectId = processResponse(objectMapper, response, Integer.class);
|
|
|
+ return projectId;
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ logger.error("JSON writeValueAsString error", e);
|
|
|
+ throw SeecoderGitlabException.JSON_ERROR;
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("IOException", e);
|
|
|
+ throw SeecoderGitlabException.IO_ERROR;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer forkGroupProject(int projectId, int groupId) throws SeecoderGitlabException {
|
|
|
+ try {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ Request.Builder builder = new Request.Builder()
|
|
|
+ .addHeader("Authorization", token);
|
|
|
+ GroupForkDTO groupForkDTO= GroupForkDTO.builder()
|
|
|
+ .projectId(projectId)
|
|
|
+ .groupId(groupId)
|
|
|
+ .build();
|
|
|
+ builder = builder
|
|
|
+ .url(host + "/api/project/groupFork")
|
|
|
+ .post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), objectMapper.writeValueAsString(groupForkDTO)));
|
|
|
+ Request request = builder.build();
|
|
|
+ final Call call = client.newCall(request);
|
|
|
+ Response response = call.execute();
|
|
|
+ projectId = processResponse(objectMapper, response, Integer.class);
|
|
|
+ return projectId;
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ logger.error("JSON writeValueAsString error", e);
|
|
|
+ throw SeecoderGitlabException.JSON_ERROR;
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("IOException", e);
|
|
|
+ throw SeecoderGitlabException.IO_ERROR;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Set<DiffVO> compare(int projectId, String fromBash, String toBash) throws SeecoderGitlabException {
|
|
|
+ try {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ Request.Builder builder = new Request.Builder()
|
|
|
+ .addHeader("Authorization", token);
|
|
|
+ builder = builder
|
|
|
+ .url(host + "/api/project/compare?projectId="+projectId+"&fromBash="+fromBash+"&toBash="+toBash)
|
|
|
+ .get();
|
|
|
+ Request request = builder.build();
|
|
|
+ final Call call = client.newCall(request);
|
|
|
+ Response response = call.execute();
|
|
|
+ Set<DiffVO> diffVOSet= new HashSet<>();
|
|
|
+ diffVOSet=processResponse(objectMapper, response, diffVOSet.getClass());
|
|
|
+ return diffVOSet;
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ logger.error("JSON writeValueAsString error", e);
|
|
|
+ throw SeecoderGitlabException.JSON_ERROR;
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("IOException", e);
|
|
|
+ throw SeecoderGitlabException.IO_ERROR;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean addWebHook(int projectId, String url, boolean doPushEvents, boolean doIssueEvents, boolean doMergeRequestsEvents) throws SeecoderGitlabException {
|
|
|
+ try {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ Request.Builder builder = new Request.Builder()
|
|
|
+ .addHeader("Authorization", token);
|
|
|
+ WebHookDTO webHookDTO= WebHookDTO.builder()
|
|
|
+ .projectId(projectId)
|
|
|
+ .url(url)
|
|
|
+ .doIssueEvents(doIssueEvents)
|
|
|
+ .doPushEvents(doPushEvents)
|
|
|
+ .doMergeRequestsEvents(doMergeRequestsEvents)
|
|
|
+ .build();
|
|
|
+ builder = builder
|
|
|
+ .url(host + "/api/project/webhook")
|
|
|
+ .post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), objectMapper.writeValueAsString(webHookDTO)));
|
|
|
+ Request request = builder.build();
|
|
|
+ final Call call = client.newCall(request);
|
|
|
+ Response response = call.execute();
|
|
|
+ return processResponse(objectMapper, response, boolean.class);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ logger.error("JSON writeValueAsString error", e);
|
|
|
+ throw SeecoderGitlabException.JSON_ERROR;
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("IOException", e);
|
|
|
+ throw SeecoderGitlabException.IO_ERROR;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean archiveProject(int projectId) throws SeecoderGitlabException {
|
|
|
+ try {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ Request.Builder builder = new Request.Builder()
|
|
|
+ .addHeader("Authorization", token);
|
|
|
+ builder = builder
|
|
|
+ .url(host + "/api/project/archive")
|
|
|
+ .post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), objectMapper.writeValueAsString(projectId)));
|
|
|
+ Request request = builder.build();
|
|
|
+ final Call call = client.newCall(request);
|
|
|
+ Response response = call.execute();
|
|
|
+ return processResponse(objectMapper, response, boolean.class);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ logger.error("JSON writeValueAsString error", e);
|
|
|
+ throw SeecoderGitlabException.JSON_ERROR;
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("IOException", e);
|
|
|
+ throw SeecoderGitlabException.IO_ERROR;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getProjectFile(int projectId, String branch, String path) throws SeecoderGitlabException {
|
|
|
+ try {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ Request.Builder builder = new Request.Builder()
|
|
|
+ .addHeader("Authorization", token);
|
|
|
+ ProjectFileDTO projectFileDTO=ProjectFileDTO.builder()
|
|
|
+ .path(path)
|
|
|
+ .branch(branch)
|
|
|
+ .build();
|
|
|
+ builder = builder
|
|
|
+ .url(host + "/api/project/"+projectId+"/getFile")
|
|
|
+ .post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), objectMapper.writeValueAsString(projectFileDTO)));
|
|
|
+ Request request = builder.build();
|
|
|
+ final Call call = client.newCall(request);
|
|
|
+ Response response = call.execute();
|
|
|
+ return processResponse(objectMapper, response, String.class);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ logger.error("JSON writeValueAsString error", e);
|
|
|
+ throw SeecoderGitlabException.JSON_ERROR;
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("IOException", e);
|
|
|
+ throw SeecoderGitlabException.IO_ERROR;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getProjectRawFile(int projectId, String commitOrBranchName, String path) throws SeecoderGitlabException {
|
|
|
+ try {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ Request.Builder builder = new Request.Builder()
|
|
|
+ .addHeader("Authorization", token);
|
|
|
+ ProjectRawFileDTO projectFileDTO=ProjectRawFileDTO.builder()
|
|
|
+ .commitOrBranchName(commitOrBranchName)
|
|
|
+ .path(path)
|
|
|
+ .build();
|
|
|
+ builder = builder
|
|
|
+ .url(host + "/api/project/"+projectId+"/getRawFile")
|
|
|
+ .post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), objectMapper.writeValueAsString(projectFileDTO)));
|
|
|
+ Request request = builder.build();
|
|
|
+ final Call call = client.newCall(request);
|
|
|
+ Response response = call.execute();
|
|
|
+ return processResponse(objectMapper, response, String.class);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ logger.error("JSON writeValueAsString error", e);
|
|
|
+ throw SeecoderGitlabException.JSON_ERROR;
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("IOException", e);
|
|
|
+ throw SeecoderGitlabException.IO_ERROR;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommitVO createCommit(int projectId, String branch, String commitMessage, String email, String username, List<CommitActionForm> actions) throws SeecoderGitlabException {
|
|
|
+ try {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ Request.Builder builder = new Request.Builder()
|
|
|
+ .addHeader("Authorization", token);
|
|
|
+ List<CommitAction> actionList=actions.stream().map(action-> new CommitAction()
|
|
|
+ .withAction(CommitAction.Action.forValue(action.getAction().toString()))
|
|
|
+ .withEncoding(CommitAction.Encoding.forValue(action.getEncoding().toString()))
|
|
|
+ .withFilePath(action.getFilepath())
|
|
|
+ .withContent(action.getContent())).collect(Collectors.toList());
|
|
|
+ CommitDTO commitDTO=CommitDTO.builder()
|
|
|
+ .branch(branch)
|
|
|
+ .commitMessage(commitMessage)
|
|
|
+ .email(email)
|
|
|
+ .username(username)
|
|
|
+ .actions(actionList)
|
|
|
+ .build();
|
|
|
+ builder = builder
|
|
|
+ .url(host + "/api/project/"+projectId+"/commit")
|
|
|
+ .post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), objectMapper.writeValueAsString(commitDTO)));
|
|
|
+ Request request = builder.build();
|
|
|
+ final Call call = client.newCall(request);
|
|
|
+ Response response = call.execute();
|
|
|
+ return processResponse(objectMapper, response, CommitVO.class);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ logger.error("JSON writeValueAsString error", e);
|
|
|
+ throw SeecoderGitlabException.JSON_ERROR;
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("IOException", e);
|
|
|
+ throw SeecoderGitlabException.IO_ERROR;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CommitVO> getAllCommitMessage(int projectId, String commitHash) throws SeecoderGitlabException {
|
|
|
+ try {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ Request.Builder builder = new Request.Builder()
|
|
|
+ .addHeader("Authorization", token);
|
|
|
+ builder = builder
|
|
|
+ .url(host + "/api/project/"+projectId+"/commit/"+commitHash)
|
|
|
+ .get();
|
|
|
+ Request request = builder.build();
|
|
|
+ final Call call = client.newCall(request);
|
|
|
+ Response response = call.execute();
|
|
|
+ List<CommitVO> commitVOList=new ArrayList<>();
|
|
|
+ commitVOList=processResponse(objectMapper, response, commitVOList.getClass());
|
|
|
+ return commitVOList;
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ logger.error("JSON writeValueAsString error", e);
|
|
|
+ throw SeecoderGitlabException.JSON_ERROR;
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("IOException", e);
|
|
|
+ throw SeecoderGitlabException.IO_ERROR;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<BranchVO> getProjectBranches(int projectId) throws SeecoderGitlabException {
|
|
|
+ try {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ Request.Builder builder = new Request.Builder()
|
|
|
+ .addHeader("Authorization", token);
|
|
|
+ builder = builder
|
|
|
+ .url(host + "/api/project/"+projectId+"/branches")
|
|
|
+ .get();
|
|
|
+ Request request = builder.build();
|
|
|
+ final Call call = client.newCall(request);
|
|
|
+ Response response = call.execute();
|
|
|
+ List<BranchVO> branchVOList=new ArrayList<>();
|
|
|
+ branchVOList=processResponse(objectMapper, response, branchVOList.getClass());
|
|
|
+ return branchVOList;
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ logger.error("JSON writeValueAsString error", e);
|
|
|
+ throw SeecoderGitlabException.JSON_ERROR;
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("IOException", e);
|
|
|
+ throw SeecoderGitlabException.IO_ERROR;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|