mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Use new features of Gitlab REST API to improve search results (support 66401)
Utilize recently added optional parameters "state" and "order_by" when fetching issues from a server to limit query results and make updates in "Open Task" faster.
This commit is contained in:
@@ -101,7 +101,8 @@ public class GitlabRepository extends NewBaseRepositoryImpl {
|
||||
|
||||
@Override
|
||||
public Task[] getIssues(@Nullable String query, int offset, int limit, boolean withClosed) throws Exception {
|
||||
return ContainerUtil.map2Array(fetchIssues((offset / limit) + 1, limit), GitlabTask.class, new Function<GitlabIssue, GitlabTask>() {
|
||||
final List<GitlabIssue> issues = fetchIssues((offset / limit) + 1, limit, !withClosed);
|
||||
return ContainerUtil.map2Array(issues, GitlabTask.class, new Function<GitlabIssue, GitlabTask>() {
|
||||
@Override
|
||||
public GitlabTask fun(GitlabIssue issue) {
|
||||
return new GitlabTask(GitlabRepository.this, issue);
|
||||
@@ -159,14 +160,19 @@ public class GitlabRepository extends NewBaseRepositoryImpl {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<GitlabIssue> fetchIssues(int pageNumber, int pageSize) throws Exception {
|
||||
public List<GitlabIssue> fetchIssues(int pageNumber, int pageSize, boolean openedOnly) throws Exception {
|
||||
ensureProjectsDiscovered();
|
||||
final URI url = new URIBuilder(getIssuesUrl())
|
||||
final URIBuilder uriBuilder = new URIBuilder(getIssuesUrl())
|
||||
.addParameter("page", String.valueOf(pageNumber))
|
||||
.addParameter("per_page", String.valueOf(pageSize))
|
||||
.build();
|
||||
// Ordering was added in v7.8
|
||||
.addParameter("order_by", "updated_at");
|
||||
if (openedOnly) {
|
||||
// Filtering by state was added in v7.3
|
||||
uriBuilder.addParameter("state", "opened");
|
||||
}
|
||||
final ResponseHandler<List<GitlabIssue>> handler = new GsonMultipleObjectsDeserializer<GitlabIssue>(GSON, LIST_OF_ISSUES_TYPE);
|
||||
return getHttpClient().execute(new HttpGet(url), handler);
|
||||
return getHttpClient().execute(new HttpGet(uriBuilder.build()), handler);
|
||||
}
|
||||
|
||||
private String getIssuesUrl() {
|
||||
|
||||
+21
@@ -1,6 +1,7 @@
|
||||
package com.intellij.tasks.integration;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.intellij.tasks.Task;
|
||||
import com.intellij.tasks.TaskManagerTestCase;
|
||||
import com.intellij.tasks.gitlab.GitlabRepository;
|
||||
import com.intellij.tasks.gitlab.GitlabTask;
|
||||
@@ -9,6 +10,7 @@ import com.intellij.tasks.gitlab.model.GitlabProject;
|
||||
import com.intellij.tasks.impl.LocalTaskImpl;
|
||||
import com.intellij.tasks.impl.TaskUtil;
|
||||
import com.intellij.tasks.impl.gson.TaskGsonUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -18,6 +20,7 @@ import java.util.Collections;
|
||||
*/
|
||||
public class GitlabIntegrationTest extends TaskManagerTestCase {
|
||||
private static final Gson GSON = TaskGsonUtil.createDefaultBuilder().create();
|
||||
private static final String SERVER_URL = "http://trackers-tests.labs.intellij.net:8045";
|
||||
private GitlabRepository myRepository;
|
||||
|
||||
public void testCommitMessageFormat() throws Exception {
|
||||
@@ -55,9 +58,27 @@ public class GitlabIntegrationTest extends TaskManagerTestCase {
|
||||
|
||||
}
|
||||
|
||||
public void testIssueFilteringByState() throws Exception {
|
||||
final GitlabProject project = ContainerUtil.find(myRepository.getProjects(), p -> p.getName().equals("Issue Filtering Tests"));
|
||||
assertNotNull(project);
|
||||
myRepository.setCurrentProject(project);
|
||||
|
||||
final Task[] allIssues = myRepository.getIssues("", 0, 20, true);
|
||||
assertSize(2, allIssues);
|
||||
assertNotNull(ContainerUtil.find(allIssues, task -> task.isClosed() && task.getSummary().equals("Closed issue #1")));
|
||||
assertNotNull(ContainerUtil.find(allIssues, task -> !task.isClosed() && task.getSummary().equals("Opened issue #1")));
|
||||
|
||||
final Task[] openedIssues = myRepository.getIssues("", 0, 20, false);
|
||||
assertSize(1, openedIssues);
|
||||
assertFalse(openedIssues[0].isClosed());
|
||||
assertEquals("Opened issue #1", openedIssues[0].getSummary());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myRepository = new GitlabRepository();
|
||||
myRepository.setUrl(SERVER_URL);
|
||||
myRepository.setPassword("PqbBxWaqFxZijQXKPLLo"); // buildtest
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user