|
|
@@ -57,11 +57,11 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi{
|
|
|
JsonNode node = objectMapper.readTree(body);
|
|
|
//todo 注释的代码和ResourceResponse字段对应不上,我先改成能用的形式,后续在修改
|
|
|
// author: wph
|
|
|
-// Integer code = Integer.parseInt(node.get("code").asText());
|
|
|
-// String msg = node.get("msg").asText();
|
|
|
-// if (code != 0) {
|
|
|
-// throw new SeecoderGitlabException(BIZ_ERROR_CODE, msg);
|
|
|
-// }
|
|
|
+ Integer err = Integer.parseInt(node.get("err").asText());
|
|
|
+ if (err != 0) {
|
|
|
+ String msg = node.get("msg").asText();
|
|
|
+ throw new SeecoderGitlabException(BIZ_ERROR_CODE, msg);
|
|
|
+ }
|
|
|
if (typeReference == null) {
|
|
|
return null;
|
|
|
}
|
|
|
@@ -247,6 +247,36 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ProjectVO createPrivateProject(String projectName, VisibilityForm visibilityForm, Integer userId) throws SeecoderGitlabException {
|
|
|
+ try {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ Request.Builder builder = new Request.Builder()
|
|
|
+ .addHeader("Authorization", token);
|
|
|
+ Visibility visibility=Visibility.valueOf(visibilityForm.toString());
|
|
|
+ ProjectDTO projectDTO= ProjectDTO.builder()
|
|
|
+ .projectName(projectName)
|
|
|
+ .visibility(visibility)
|
|
|
+ .userId(userId)
|
|
|
+ .build();
|
|
|
+ builder = builder
|
|
|
+ .url(host + "/api/project/private")
|
|
|
+ .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, new TypeReference<ProjectVO>() {
|
|
|
+ });
|
|
|
+ } 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 {
|