mirror of
https://github.com/e1fueg0/intellij-gitea-plugin.git
synced 2024-10-27 20:34:04 +00:00
#9: - added offset/limit processing
This commit is contained in:
parent
ad26a2bb52
commit
01a7e1a17f
@ -97,7 +97,7 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Task[] getIssues(@Nullable String query, int offset, int limit, boolean withClosed, @NotNull ProgressIndicator cancelled) throws Exception {
|
public Task[] getIssues(@Nullable String query, int offset, int limit, boolean withClosed, @NotNull ProgressIndicator cancelled) throws Exception {
|
||||||
return getIssues();
|
return findIssues(query, offset, limit, withClosed, cancelled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -174,7 +174,7 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getFeatures() {
|
protected int getFeatures() {
|
||||||
return NATIVE_SEARCH | STATE_UPDATING;
|
return STATE_UPDATING;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTest() throws Exception {
|
private void doTest() throws Exception {
|
||||||
@ -245,15 +245,43 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Task[] getIssues() throws Exception {
|
private Task[] getIssues() throws Exception {
|
||||||
|
return findIssues(null, -1, -1, false, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task[] findIssues(String query, int offset, int limit, boolean withClosed, ProgressIndicator cancelled) throws Exception {
|
||||||
if (!ensureUserId())
|
if (!ensureUserId())
|
||||||
return new Task[]{};
|
return new Task[]{};
|
||||||
List<GiteaTaskImpl> result = new ArrayList<>();
|
|
||||||
|
|
||||||
final String url = getApiUrl() + Consts.EndPoint.REPOS + getProject() + Consts.EndPoint.ISSUES;
|
StringBuilder qu = new StringBuilder();
|
||||||
final JsonElement response = executeMethod(new GetMethod(url));
|
if (query != null)
|
||||||
|
qu.append("?q=").append(query);
|
||||||
|
if (withClosed)
|
||||||
|
qu.append("&state=closed");
|
||||||
|
qu.append("&page=");
|
||||||
|
if (qu.length() > 0)
|
||||||
|
qu.setCharAt(0, '?');
|
||||||
|
List<GiteaTaskImpl> result = new ArrayList<>();
|
||||||
|
final String url = getApiUrl() + Consts.EndPoint.REPOS + getProject() + Consts.EndPoint.ISSUES + qu.toString();
|
||||||
|
|
||||||
|
int firstPage = offset / 10;
|
||||||
|
int lastPage = (offset + limit) / 10;
|
||||||
|
|
||||||
|
for (int p = firstPage + 1; p <= lastPage; p++) {
|
||||||
|
if (!loadPage(url, result, p))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(result);
|
||||||
|
return result.toArray(new Task[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean loadPage(String url, List<GiteaTaskImpl> result, int page) throws Exception {
|
||||||
|
final JsonElement response = executeMethod(new GetMethod(url + page));
|
||||||
if (response == null)
|
if (response == null)
|
||||||
return new Task[]{};
|
return false;
|
||||||
JsonArray tasks = getArray(response);
|
JsonArray tasks = getArray(response);
|
||||||
|
if (tasks.size() < 1)
|
||||||
|
return false;
|
||||||
for (int i = 0; i < tasks.size(); i++) {
|
for (int i = 0; i < tasks.size(); i++) {
|
||||||
JsonObject current = tasks.get(i).getAsJsonObject();
|
JsonObject current = tasks.get(i).getAsJsonObject();
|
||||||
GiteaTask raw = new GiteaTask(getProject(), current);
|
GiteaTask raw = new GiteaTask(getProject(), current);
|
||||||
@ -263,9 +291,7 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|||||||
GiteaTaskImpl mapped = new GiteaTaskImpl(this, raw);
|
GiteaTaskImpl mapped = new GiteaTaskImpl(this, raw);
|
||||||
result.add(mapped);
|
result.add(mapped);
|
||||||
}
|
}
|
||||||
Collections.sort(result);
|
return true;
|
||||||
Task[] primArray = new Task[result.size()];
|
|
||||||
return result.toArray(primArray);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getProject() {
|
private String getProject() {
|
||||||
|
Loading…
Reference in New Issue
Block a user