use of org.gitlab4j.api.GitLabApiException in project catma by forTEXT.
the class GitlabManagerRestricted method updateGroup.
@Override
public void updateGroup(String name, String path, String description) throws IOException {
try {
GroupApi groupApi = restrictedGitLabApi.getGroupApi();
groupApi.updateGroup(path, name, path, description, null, null, null, null);
} catch (GitLabApiException e) {
throw new IOException("Failed to update name/description for group", e);
}
}
use of org.gitlab4j.api.GitLabApiException in project catma by forTEXT.
the class GitlabManagerRestricted method getComments.
@Override
public List<Comment> getComments(String projectId) throws IOException {
try {
List<Comment> result = new ArrayList<Comment>();
IssuesApi issuesApi = new IssuesApi(restrictedGitLabApi);
String projectPath = projectId;
List<Issue> issues = issuesApi.getGroupIssues(projectPath, new IssueFilter().withLabels(Collections.singletonList(CATMA_COMMENT_LABEL)).withState(IssueState.OPENED));
for (Issue issue : issues) {
String description = issue.getDescription();
int noteCount = issue.getUserNotesCount();
try {
Author author = issue.getAuthor();
Comment comment = new SerializationHelper<Comment>().deserialize(description, Comment.class);
comment.setId(issue.getId());
comment.setIid(issue.getIid());
comment.setUserId(author.getId());
comment.setUsername(author.getName());
comment.setReplyCount(noteCount);
result.add(comment);
} catch (Exception e) {
logger.log(Level.SEVERE, String.format("Error deserializing Comment #%1$d %2$s", issue.getId(), description), e);
}
}
return result;
} catch (GitLabApiException e) {
throw new IOException(String.format("Failed to retrieve Comments in group %1$s!", projectId), e);
}
}
use of org.gitlab4j.api.GitLabApiException in project catma by forTEXT.
the class GitlabManagerRestricted method removeComment.
@Override
public void removeComment(String projectId, Comment comment) throws IOException {
String resourceId = comment.getDocumentId();
try {
String projectPath = projectId + "/" + resourceId;
IssuesApi issuesApi = restrictedGitLabApi.getIssuesApi();
issuesApi.closeIssue(projectPath, comment.getIid());
} catch (GitLabApiException e) {
throw new IOException(String.format("Failed to remove 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 getResourceMembers.
@Override
public Set<de.catma.user.Member> getResourceMembers(String projectId, String resourceId) throws IOException {
try {
Project project = restrictedGitLabApi.getProjectApi().getProject(projectId, resourceId);
if (project != null) {
List<GitMember> allMembers = new ProjectApi(restrictedGitLabApi).getAllMembers(project.getId()).stream().map(member -> new GitMember(member)).collect(Collectors.toList());
Map<Integer, de.catma.user.Member> mergedList = new HashMap<>();
for (de.catma.user.Member m : allMembers) {
if (!mergedList.containsKey(m.getUserId()) || mergedList.get(m.getUserId()).getRole().getAccessLevel() < m.getRole().getAccessLevel()) {
mergedList.put(m.getUserId(), m);
}
}
return mergedList.values().stream().collect(Collectors.toSet());
} else {
throw new IOException("resource unknown");
}
} catch (GitLabApiException e) {
throw new IOException("resource unknown");
}
}
use of org.gitlab4j.api.GitLabApiException in project catma by forTEXT.
the class GitlabManagerCommon method assignDefaultAccessToRootProject.
private RBACSubject assignDefaultAccessToRootProject(RBACSubject subject, Integer groupId) throws IOException {
try {
Group group = getGitLabApi().getGroupApi().getGroup(groupId);
Project rootProject = getGitLabApi().getProjectApi().getProject(group.getName(), GitProjectManager.getProjectRootRepositoryName(group.getName()));
try {
Member member = getGitLabApi().getProjectApi().getMember(rootProject.getId(), subject.getUserId());
if (member.getAccessLevel().value < RBACRole.ASSISTANT.getAccessLevel()) {
return new GitMember(getGitLabApi().getProjectApi().updateMember(rootProject.getId(), subject.getUserId(), AccessLevel.forValue(RBACRole.ASSISTANT.getAccessLevel())));
} else {
// In both cases we refuse to update the role, and simply do nothing.
return subject;
}
} catch (GitLabApiException e) {
return new GitMember(getGitLabApi().getProjectApi().addMember(rootProject.getId(), subject.getUserId(), AccessLevel.forValue(RBACRole.ASSISTANT.getAccessLevel())));
}
} catch (GitLabApiException e) {
throw new IOException("error assigning default access to root project in group #" + groupId, e);
}
}
Aggregations