use of org.gitlab4j.api.GitLabApiException in project catma by forTEXT.
the class GitlabManagerRestricted method getCommentReplies.
@Override
public List<Reply> getCommentReplies(String projectId, Comment comment) throws IOException {
String resourceId = comment.getDocumentId();
String projectPath = projectId + "/" + resourceId;
NotesApi notesApi = restrictedGitLabApi.getNotesApi();
List<Reply> result = new ArrayList<Reply>();
try {
List<Note> notes = notesApi.getIssueNotes(projectPath, comment.getIid());
for (Note note : notes.stream().filter(n -> !n.getSystem()).collect(Collectors.toList())) {
// filter system notes
String noteBody = note.getBody();
Reply reply = null;
try {
reply = new SerializationHelper<Reply>().deserialize(noteBody, Reply.class);
reply.setCommentUuid(comment.getUuid());
reply.setId(note.getId());
reply.setUserId(note.getAuthor().getId());
reply.setUsername(note.getAuthor().getName());
} catch (Exception e) {
logger.log(Level.SEVERE, String.format("Error deserializing Reply #%1$d %2$s", note.getId(), noteBody), e);
IDGenerator idGenerator = new IDGenerator();
reply = new Reply(idGenerator.generate(), noteBody, note.getAuthor().getUsername(), note.getAuthor().getId(), comment.getUuid(), note.getId());
}
result.add(reply);
}
comment.setReplies(result);
return result;
} catch (GitLabApiException e) {
throw new IOException(String.format("Failed to retrieve Replies for Comment %1$s %2$d for resource %3$s in group %4$s!", comment.getUuid(), comment.getIid(), resourceId, projectId), e);
}
}
use of org.gitlab4j.api.GitLabApiException in project catma by forTEXT.
the class GitlabManagerRestricted method deleteGroup.
@Override
public void deleteGroup(String path) throws IOException {
GroupApi groupApi = restrictedGitLabApi.getGroupApi();
try {
// TODO: remove, deleteGroup can work with the path
Group group = groupApi.getGroup(path);
groupApi.deleteGroup(group);
} catch (GitLabApiException e) {
throw new IOException("Failed to delete remote group", e);
}
}
use of org.gitlab4j.api.GitLabApiException in project catma by forTEXT.
the class GitlabManagerRestricted method addComment.
@Override
public void addComment(String projectId, Comment comment) throws IOException {
String resourceId = comment.getDocumentId();
try {
String projectPath = projectId + "/" + resourceId;
IssuesApi issuesApi = restrictedGitLabApi.getIssuesApi();
String title = comment.getBody().substring(0, Math.min(100, comment.getBody().length()));
if (title.length() < comment.getBody().length()) {
title += "...";
}
String description = new SerializationHelper<Comment>().serialize(comment);
Issue issue = issuesApi.createIssue(projectPath, title, description, null, null, null, CATMA_COMMENT_LABEL, null, null, null, null);
comment.setId(issue.getId());
comment.setIid(issue.getIid());
} catch (GitLabApiException e) {
throw new IOException(String.format("Failed to add a new Comment for resource %1$s in group %2$s!", resourceId, projectId), e);
}
}
use of org.gitlab4j.api.GitLabApiException in project catma by forTEXT.
the class GitlabManagerRestricted method leaveGroup.
@Override
public void leaveGroup(String path) throws IOException {
GroupApi groupApi = restrictedGitLabApi.getGroupApi();
try {
Group group = groupApi.getGroup(path);
Member member = groupApi.getMember(group.getId(), user.getUserId());
if (member != null && member.getAccessLevel().value >= AccessLevel.GUEST.value && member.getAccessLevel().value < AccessLevel.OWNER.value) {
groupApi.removeMember(group.getId(), user.getUserId());
}
} catch (GitLabApiException ge) {
throw new IOException("Couldn't leave group", ge);
}
}
use of org.gitlab4j.api.GitLabApiException in project catma by forTEXT.
the class GitlabManagerRestricted method getRolesPerResource.
public Map<String, RBACRole> getRolesPerResource(String projectId) throws IOException {
try {
Group group = restrictedGitLabApi.getGroupApi().getGroup(projectId);
Map<String, AccessLevel> permMap = getResourcePermissions(group.getId());
return permMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> RBACRole.forValue(e.getValue().value)));
} catch (GitLabApiException e) {
throw new IOException("Permission retrieval failed!", e);
}
}
Aggregations