Search in sources :

Example 1 with IssuesApi

use of org.gitlab4j.api.IssuesApi 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);
    }
}
Also used : Comment(de.catma.document.comment.Comment) IssuesApi(org.gitlab4j.api.IssuesApi) Issue(org.gitlab4j.api.models.Issue) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException)

Example 2 with IssuesApi

use of org.gitlab4j.api.IssuesApi 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);
    }
}
Also used : Comment(de.catma.document.comment.Comment) IssuesApi(org.gitlab4j.api.IssuesApi) Issue(org.gitlab4j.api.models.Issue) ArrayList(java.util.ArrayList) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) IssueFilter(org.gitlab4j.api.models.IssueFilter) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException) Author(org.gitlab4j.api.models.Author)

Example 3 with IssuesApi

use of org.gitlab4j.api.IssuesApi 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);
    }
}
Also used : IssuesApi(org.gitlab4j.api.IssuesApi) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException)

Example 4 with IssuesApi

use of org.gitlab4j.api.IssuesApi in project catma by forTEXT.

the class GitlabManagerRestricted method updateComment.

@Override
public void updateComment(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);
        issuesApi.updateIssue(projectPath, comment.getIid(), title, description, null, null, null, CATMA_COMMENT_LABEL, null, null, null);
    } catch (GitLabApiException e) {
        throw new IOException(String.format("Failed to update Comment %1$s %2$d for resource %3$s in group %4$s!", comment.getUuid(), comment.getIid(), resourceId, projectId), e);
    }
}
Also used : Comment(de.catma.document.comment.Comment) IssuesApi(org.gitlab4j.api.IssuesApi) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)4 GitLabApiException (org.gitlab4j.api.GitLabApiException)4 IssuesApi (org.gitlab4j.api.IssuesApi)4 Comment (de.catma.document.comment.Comment)3 Issue (org.gitlab4j.api.models.Issue)2 ArrayList (java.util.ArrayList)1 Author (org.gitlab4j.api.models.Author)1 IssueFilter (org.gitlab4j.api.models.IssueFilter)1