Skip to content

#912 Add field iteration into IssueFilter #913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 39 additions & 10 deletions src/main/java/org/gitlab4j/api/IssuesApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -422,17 +422,46 @@ public Issue createIssue(Object projectIdOrPath, String title, String descriptio
public Issue createIssue(Object projectIdOrPath, String title, String description, Boolean confidential, List<Long> assigneeIds, Long milestoneId, String labels,
Date createdAt, Date dueDate, Long mergeRequestToResolveId, Long discussionToResolveId) throws GitLabApiException {

return (createIssue(projectIdOrPath, title, description, confidential, assigneeIds, milestoneId, labels, createdAt, dueDate, mergeRequestToResolveId, discussionToResolveId, null));
}

/**
* Create an issue for the project.
*
* <pre><code>GitLab Endpoint: POST /projects/:id/issues</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param title the issue title of an issue, required
* @param description the description of an issue, optional
* @param confidential set the issue to be confidential, default is false, optional
* @param assigneeIds the IDs of the users to assign issue, optional
* @param milestoneId the ID of a milestone to assign issue, optional
* @param labels comma-separated label names for an issue, optional
* @param createdAt the date the issue was created at, optional
* @param dueDate the due date, optional
* @param mergeRequestToResolveId the IID of a merge request in which to resolve all issues. This will fill the issue with a default
* description and mark all discussions as resolved. When passing a description or title, these values will take precedence over the default values. Optional
* @param discussionToResolveId the ID of a discussion to resolve. This will fill in the issue with a default description and mark the discussion as resolved.
* Use in combination with merge_request_to_resolve_discussions_of. Optional
* @param iterationTitle the iteration title of an issue, optional
* @return an instance of Issue
* @throws GitLabApiException if any exception occurs
*/
public Issue createIssue(Object projectIdOrPath, String title, String description, Boolean confidential, List<Long> assigneeIds, Long milestoneId, String labels,
Date createdAt, Date dueDate, Long mergeRequestToResolveId, Long discussionToResolveId, String iterationTitle) throws GitLabApiException {

GitLabApiForm formData = new GitLabApiForm()
.withParam("title", title, true)
.withParam("description", description)
.withParam("confidential", confidential)
.withParam("assignee_ids", assigneeIds)
.withParam("milestone_id", milestoneId)
.withParam("labels", labels)
.withParam("created_at", createdAt)
.withParam("due_date", dueDate)
.withParam("merge_request_to_resolve_discussions_of", mergeRequestToResolveId)
.withParam("discussion_to_resolve", discussionToResolveId);
.withParam("title", title, true)
.withParam("description", description)
.withParam("confidential", confidential)
.withParam("assignee_ids", assigneeIds)
.withParam("milestone_id", milestoneId)
.withParam("labels", labels)
.withParam("created_at", createdAt)
.withParam("due_date", dueDate)
.withParam("merge_request_to_resolve_discussions_of", mergeRequestToResolveId)
.withParam("discussion_to_resolve", discussionToResolveId)
.withParam("iteration_title", iterationTitle);
Response response = post(Response.Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "issues");
return (response.readEntity(Issue.class));
}
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/org/gitlab4j/api/models/IssueFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public class IssueFilter {
*/
private Date updatedBefore;

/**
* Return issues in current iteration.
*/
private String iterationTitle;


/*- properties -*/
public List<String> getIids() {
Expand Down Expand Up @@ -213,6 +218,14 @@ public void setUpdatedBefore(Date updatedBefore) {
this.updatedBefore = updatedBefore;
}

public String getIterationTitle() {
return iterationTitle;
}

public void setIterationTitle(String iterationTitle) {
this.iterationTitle = iterationTitle;
}

/*- builder -*/
public IssueFilter withIids(List<String> iids) {
this.iids = iids;
Expand Down Expand Up @@ -289,6 +302,11 @@ public IssueFilter withUpdatedBefore(Date updatedBefore) {
return (this);
}

public IssueFilter withIterationTitle(String iterationTitle) {
this.iterationTitle = iterationTitle;
return (this);
}

/*- params generator -*/
@JsonIgnore
public GitLabApiForm getQueryParams(int page, int perPage) {
Expand All @@ -314,6 +332,7 @@ public GitLabApiForm getQueryParams() {
.withParam("created_after", ISO8601.toString(createdAfter, false))
.withParam("created_before", ISO8601.toString(createdBefore, false))
.withParam("updated_after", ISO8601.toString(updatedAfter, false))
.withParam("updated_before", ISO8601.toString(updatedBefore, false)));
.withParam("updated_before", ISO8601.toString(updatedBefore, false)))
.withParam("iteration_title", iterationTitle);
}
}
10 changes: 10 additions & 0 deletions src/test/java/org/gitlab4j/api/TestIssuesApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class TestIssuesApi extends AbstractIntegrationTest {

private static final String ISSUE_TITLE = "Test Issue Title";
private static final String ISSUE_DESCRIPTION = "This is a really nice description, not.";
private static final String ITERATION_TITLE = "iteration title";
private static final String TEST_GROUP = HelperUtils.getProperty(GROUP_KEY);
private static Random randomNumberGenerator = new Random();

Expand Down Expand Up @@ -320,8 +321,10 @@ public void testGetIssuesWithOptions() throws GitLabApiException {

Issue issueOpen = gitLabApi.getIssuesApi().createIssue(projectId, getUniqueTitle(), ISSUE_DESCRIPTION);
Issue issueClose = gitLabApi.getIssuesApi().createIssue(projectId, getUniqueTitle(), ISSUE_DESCRIPTION);
Issue issueInIteration = gitLabApi.getIssuesApi().createIssue(projectId, getUniqueTitle(), ISSUE_DESCRIPTION, null, null, null, null, null, null, null, null, ITERATION_TITLE);
issueClose = gitLabApi.getIssuesApi().closeIssue(projectId, issueClose.getIid());


final Long openIid = issueOpen.getIid();
IssueFilter openFilter = new IssueFilter().withState(IssueState.OPENED);
List<Issue> opens = gitLabApi.getIssuesApi().getIssues(projectId, openFilter);
Expand All @@ -333,5 +336,12 @@ public void testGetIssuesWithOptions() throws GitLabApiException {
List<Issue> closes = gitLabApi.getIssuesApi().getIssues(projectId, closeFilter);
assertNotNull(closes);
assertTrue(closes.stream().map(Issue::getIid).anyMatch(iid -> iid.equals(closedIid)));

final Long issueInIterationIid = issueInIteration.getIid();
IssueFilter issueInIterationFilter = new IssueFilter().withIterationTitle(ITERATION_TITLE);
List<Issue> issuesInIteration = gitLabApi.getIssuesApi().getIssues(projectId, issueInIterationFilter);
assertNotNull(issuesInIteration);
assertTrue(issuesInIteration.stream().map(Issue::getIid).anyMatch(iid -> iid.equals(issueInIterationIid)));

}
}