Search in sources :

Example 1 with Issue

use of org.gitlab4j.api.models.Issue in project choerodon-starters by open-hand.

the class IssuesApi method openIssue.

/**
 * Open an existing project issue.
 * <p>
 * PUT /projects/:id/issues/:issue_iid
 *
 * @param projectId the ID of the project owned by the authenticated user, required
 * @param issueIid  the issue IID to update, required
 * @return an instance of the updated Issue
 * @throws GitLabApiException if any exception occurs
 */
public Issue openIssue(Integer projectId, Integer issueIid) throws GitLabApiException {
    if (projectId == null) {
        throw new RuntimeException("project ID cannot be null");
    }
    if (issueIid == null) {
        throw new RuntimeException("issue IID cannot be null");
    }
    GitLabApiForm formData = new GitLabApiForm().withParam("state_event", StateEvent.REOPEN);
    Response response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "issues", issueIid);
    return (response.readEntity(Issue.class));
}
Also used : Response(javax.ws.rs.core.Response) Issue(org.gitlab4j.api.models.Issue)

Example 2 with Issue

use of org.gitlab4j.api.models.Issue 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 3 with Issue

use of org.gitlab4j.api.models.Issue 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 4 with Issue

use of org.gitlab4j.api.models.Issue in project agile-architecture-documentation-system by Riduidel.

the class GitLabTicketsHandler method getTicketsTagged.

@Override
public Collection<Ticket> getTicketsTagged(String project, String label) {
    try {
        Object projectId = gitlab.getApi().getIssuesApi().getProjectIdOrPath(project);
        IssueFilter filter = new IssueFilter();
        filter.setLabels(Arrays.asList(label));
        Collection<Ticket> returned = new ArrayList<>();
        for (Issue issue : gitlab.getApi().getIssuesApi().getIssues(filter)) {
            returned.add(new GitLabTicket(issue, gitlab.getApi().getDiscussionsApi().getIssueDiscussions(projectId, issue.getId())));
        }
        return returned;
    } catch (GitLabApiException e) {
        throw new GitLabHandlerException(String.format("Unable to et project name of %s", project), e);
    }
}
Also used : Ticket(org.ndx.agile.architecture.base.enhancers.tickets.Ticket) Issue(org.gitlab4j.api.models.Issue) ArrayList(java.util.ArrayList) GitLabApiException(org.gitlab4j.api.GitLabApiException) IssueFilter(org.gitlab4j.api.models.IssueFilter)

Example 5 with Issue

use of org.gitlab4j.api.models.Issue in project dash-licenses by eclipse.

the class GitLabSupport method createReviews.

public void createReviews(List<LicenseData> needsReview, BiConsumer<IContentId, String> monitor) {
    execute(connection -> {
        var count = 0;
        for (LicenseData licenseData : needsReview) {
            if (count >= MAXIMUM_REVIEWS)
                break;
            count++;
            if (!licenseData.getId().isValid()) {
                logger.info("I don't know what to do with {}.", licenseData.getId().toString());
                continue;
            }
            logger.info("A review is required for {}.", licenseData.getId().toString());
            Stream<ExtendedContentData> extendedData = dataService.findFor(licenseData.getId());
            /*
				 * Ideally, we need a way to "create if does not already exist" feature in the
				 * GitLab API. But since we don't have that, we'll leverage the expectation that
				 * concurrent requests to review the same content will be relatively rare (there
				 * is some risk that between asking if we have an existing issue for a review
				 * for a particular bit of content and creating a new one, that somebody else
				 * might be doing the same). Our expectation is that the potential additional
				 * churn on the backend should require significantly less effort than that
				 * required to prevent rare duplication.
				 */
            try {
                GitLabReview review = new GitLabReview(settings.getProjectId(), licenseData, extendedData);
                Issue existing = connection.findIssue(review);
                if (existing != null) {
                    monitor.accept(licenseData.getId(), existing.getWebUrl());
                    logger.info("A review request already exists {}.", existing.getWebUrl());
                    continue;
                }
                Issue created = connection.createIssue(review);
                if (created == null) {
                    logger.error("An error occurred while attempting to create a review request. Aborting.");
                    // TODO If we break creating a review, then don't try to create any more.
                    break;
                }
                monitor.accept(licenseData.getId(), created.getWebUrl());
                logger.info("A review request was created {}.", created.getWebUrl());
            } catch (GitLabApiException e) {
                throw new RuntimeException(e);
            }
        }
        if (count < needsReview.size()) {
            logger.info("More content needs to be reviewed.");
            logger.info("For now, however, this experimental feature only submits the first {}.\n", count);
        }
    });
}
Also used : Issue(org.gitlab4j.api.models.Issue) LicenseData(org.eclipse.dash.licenses.LicenseData) GitLabApiException(org.gitlab4j.api.GitLabApiException) ExtendedContentData(org.eclipse.dash.licenses.extended.ExtendedContentData)

Aggregations

Issue (org.gitlab4j.api.models.Issue)9 GitLabApiException (org.gitlab4j.api.GitLabApiException)5 Response (javax.ws.rs.core.Response)4 Comment (de.catma.document.comment.Comment)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 LicenseData (org.eclipse.dash.licenses.LicenseData)2 ExtendedContentData (org.eclipse.dash.licenses.extended.ExtendedContentData)2 IssuesApi (org.gitlab4j.api.IssuesApi)2 IssueFilter (org.gitlab4j.api.models.IssueFilter)2 Author (org.gitlab4j.api.models.Author)1 Ticket (org.ndx.agile.architecture.base.enhancers.tickets.Ticket)1