mirror of
https://github.com/e1fueg0/intellij-gitea-plugin.git
synced 2025-06-07 18:04:06 +00:00
Compare commits
No commits in common. "master" and "1.1" have entirely different histories.
@ -7,7 +7,7 @@
|
|||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="IntelliJ IDEA IU-173.4674.60" jdkType="IDEA JDK" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
@ -1,11 +1,7 @@
|
|||||||
<!--
|
|
||||||
~ Copyright © 2020 by elfuego.biz
|
|
||||||
-->
|
|
||||||
|
|
||||||
<idea-plugin>
|
<idea-plugin>
|
||||||
<id>biz.elfuego.idea.issues.gitea</id>
|
<id>biz.elfuego.idea.issues.gitea</id>
|
||||||
<name>Gitea issues</name>
|
<name>Gitea issues plugin</name>
|
||||||
<version>1.6</version>
|
<version>1.1</version>
|
||||||
<vendor email="support@elfuego.biz" url="http://elfuego.biz">elfuego.biz</vendor>
|
<vendor email="support@elfuego.biz" url="http://elfuego.biz">elfuego.biz</vendor>
|
||||||
|
|
||||||
<description><![CDATA[
|
<description><![CDATA[
|
||||||
@ -13,8 +9,7 @@
|
|||||||
]]></description>
|
]]></description>
|
||||||
|
|
||||||
<change-notes><![CDATA[
|
<change-notes><![CDATA[
|
||||||
Fixes errors with loading issues without limits (contributed by billlhead).<br>
|
First implementation.<br>
|
||||||
Fixes searching for issues containing white spaces (contributed by billlhead).<br>
|
|
||||||
]]>
|
]]>
|
||||||
</change-notes>
|
</change-notes>
|
||||||
|
|
||||||
@ -29,4 +24,5 @@
|
|||||||
|
|
||||||
<actions>
|
<actions>
|
||||||
</actions>
|
</actions>
|
||||||
|
|
||||||
</idea-plugin>
|
</idea-plugin>
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2019 by elfuego.biz
|
* Copyright © 2018 by elfuego.biz
|
||||||
*/
|
*/
|
||||||
package biz.elfuego.idea.issues.gitea;
|
package biz.elfuego.idea.issues.gitea;
|
||||||
|
|
||||||
|
import biz.elfuego.idea.issues.gitea.model.GiteaProject;
|
||||||
import biz.elfuego.idea.issues.gitea.model.GiteaTask;
|
import biz.elfuego.idea.issues.gitea.model.GiteaTask;
|
||||||
import biz.elfuego.idea.issues.gitea.model.GiteaUser;
|
|
||||||
import biz.elfuego.idea.issues.gitea.util.Consts;
|
import biz.elfuego.idea.issues.gitea.util.Consts;
|
||||||
import biz.elfuego.idea.issues.gitea.util.Consts.CommentFields;
|
import biz.elfuego.idea.issues.gitea.util.Consts.CommentFields;
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import com.intellij.openapi.diagnostic.Logger;
|
|
||||||
import com.intellij.openapi.progress.ProgressIndicator;
|
import com.intellij.openapi.progress.ProgressIndicator;
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import com.intellij.tasks.Comment;
|
import com.intellij.tasks.Comment;
|
||||||
@ -19,9 +18,12 @@ import com.intellij.tasks.CustomTaskState;
|
|||||||
import com.intellij.tasks.Task;
|
import com.intellij.tasks.Task;
|
||||||
import com.intellij.tasks.impl.BaseRepositoryImpl;
|
import com.intellij.tasks.impl.BaseRepositoryImpl;
|
||||||
import com.intellij.tasks.impl.SimpleComment;
|
import com.intellij.tasks.impl.SimpleComment;
|
||||||
|
import com.intellij.util.xmlb.annotations.AbstractCollection;
|
||||||
import com.intellij.util.xmlb.annotations.Tag;
|
import com.intellij.util.xmlb.annotations.Tag;
|
||||||
|
import com.intellij.util.xmlb.annotations.Transient;
|
||||||
import org.apache.commons.httpclient.HttpMethod;
|
import org.apache.commons.httpclient.HttpMethod;
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
|
import org.apache.commons.httpclient.auth.AuthPolicy;
|
||||||
import org.apache.commons.httpclient.methods.GetMethod;
|
import org.apache.commons.httpclient.methods.GetMethod;
|
||||||
import org.apache.commons.httpclient.methods.PostMethod;
|
import org.apache.commons.httpclient.methods.PostMethod;
|
||||||
import org.apache.commons.httpclient.methods.StringRequestEntity;
|
import org.apache.commons.httpclient.methods.StringRequestEntity;
|
||||||
@ -30,10 +32,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -45,15 +44,9 @@ import static biz.elfuego.idea.issues.gitea.util.Utils.*;
|
|||||||
*/
|
*/
|
||||||
@Tag("Gitea")
|
@Tag("Gitea")
|
||||||
class GiteaRepository extends BaseRepositoryImpl {
|
class GiteaRepository extends BaseRepositoryImpl {
|
||||||
private static final Logger logger = Logger.getInstance(GiteaRepository.class);
|
|
||||||
private static final int DEFAULT_PAGE = 10;
|
|
||||||
|
|
||||||
private String userId = null;
|
private String userId = null;
|
||||||
private String userLogin = null;
|
private List<GiteaProject> projects = new ArrayList<>();
|
||||||
private String repoName = null;
|
private GiteaProject selectedProject = null;
|
||||||
private String projName = null;
|
|
||||||
private String token = null;
|
|
||||||
private boolean assigned = false;
|
|
||||||
|
|
||||||
@SuppressWarnings("UnusedDeclaration")
|
@SuppressWarnings("UnusedDeclaration")
|
||||||
public GiteaRepository() {
|
public GiteaRepository() {
|
||||||
@ -71,40 +64,20 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|||||||
public GiteaRepository(GiteaRepository other) {
|
public GiteaRepository(GiteaRepository other) {
|
||||||
super(other);
|
super(other);
|
||||||
userId = other.userId;
|
userId = other.userId;
|
||||||
userLogin = other.userLogin;
|
projects = other.projects;
|
||||||
repoName = other.repoName;
|
selectedProject = other.selectedProject;
|
||||||
projName = other.projName;
|
|
||||||
token = other.token;
|
|
||||||
assigned = other.assigned;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (!(o instanceof GiteaRepository))
|
|
||||||
return false;
|
|
||||||
GiteaRepository other = (GiteaRepository) o;
|
|
||||||
return equal(userId, other.userId) &&
|
|
||||||
equal(userLogin, other.userLogin) &&
|
|
||||||
equal(repoName, other.repoName) &&
|
|
||||||
equal(projName, other.projName) &&
|
|
||||||
equal(token, other.token) &&
|
|
||||||
equal(assigned, other.assigned);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean equal(Object o1, Object o2) {
|
|
||||||
return o1 == null && o2 == null || o1 != null && o1.equals(o2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Task findTask(@NotNull String s) /*throws Exception*/ {
|
public Task findTask(@NotNull String s) throws Exception {
|
||||||
// TODO
|
// TODO
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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 findIssues(query, offset, limit, withClosed, cancelled);
|
return getIssues();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -174,24 +147,20 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|||||||
"application/json",
|
"application/json",
|
||||||
"UTF-8"
|
"UTF-8"
|
||||||
);
|
);
|
||||||
HttpMethod patchTask = getPatchMethod(getApiUrl() + Consts.EndPoint.REPOS + getProject()
|
HttpMethod patchTask = getPatchMethod(getApiUrl() + Consts.EndPoint.REPOS + selectedProject.getName()
|
||||||
+ Consts.EndPoint.ISSUES + "/" + giteaTask.getId(), data);
|
+ Consts.EndPoint.ISSUES + "/" + giteaTask.getId(), data);
|
||||||
executeMethod(patchTask);
|
executeMethod(patchTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getFeatures() {
|
protected int getFeatures() {
|
||||||
return STATE_UPDATING;
|
return NATIVE_SEARCH | STATE_UPDATING;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTest() throws Exception {
|
private void doTest() throws Exception {
|
||||||
userId = null;
|
userId = null;
|
||||||
userLogin = null;
|
|
||||||
checkSetup();
|
checkSetup();
|
||||||
GetMethod method = new GetMethod(getApiUrl() + Consts.EndPoint.ME);
|
JsonElement response = executeMethod(new GetMethod(getApiUrl() + Consts.EndPoint.ME));
|
||||||
JsonElement response = executeMethod(method);
|
|
||||||
if (response == null)
|
|
||||||
throw new Exception(String.format("%s: %d, %s", Consts.ERROR, method.getStatusCode(), method.getStatusText()));
|
|
||||||
final JsonObject obj = getObject(response);
|
final JsonObject obj = getObject(response);
|
||||||
if (obj.has("id") && obj.has("login"))
|
if (obj.has("id") && obj.has("login"))
|
||||||
return;
|
return;
|
||||||
@ -212,13 +181,10 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|||||||
if (result && StringUtil.isEmpty(this.getUrl())) {
|
if (result && StringUtil.isEmpty(this.getUrl())) {
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
if (result && StringUtil.isEmpty(this.getRepoName())) {
|
if (result && StringUtil.isEmpty(this.getUsername())) {
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
if (result && StringUtil.isEmpty(this.getProjName())) {
|
if (result && StringUtil.isEmpty(this.getPassword())) {
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
if (result && StringUtil.isEmpty(this.getToken())) {
|
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@ -231,19 +197,14 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|||||||
result += "Server";
|
result += "Server";
|
||||||
errors++;
|
errors++;
|
||||||
}
|
}
|
||||||
if (StringUtil.isEmpty(getRepoName())) {
|
if (StringUtil.isEmpty(getUsername())) {
|
||||||
result += !StringUtils.isEmpty(result) ? " & " : "";
|
result += !StringUtils.isEmpty(result) ? " & " : "";
|
||||||
result += "Repo name";
|
result += "Username";
|
||||||
errors++;
|
errors++;
|
||||||
}
|
}
|
||||||
if (StringUtil.isEmpty(getProjName())) {
|
if (StringUtil.isEmpty(getPassword())) {
|
||||||
result += !StringUtils.isEmpty(result) ? " & " : "";
|
result += !StringUtils.isEmpty(result) ? " & " : "";
|
||||||
result += "Project name";
|
result += "Password";
|
||||||
errors++;
|
|
||||||
}
|
|
||||||
if (StringUtil.isEmpty(getToken())) {
|
|
||||||
result += !StringUtils.isEmpty(result) ? " & " : "";
|
|
||||||
result += "Token";
|
|
||||||
errors++;
|
errors++;
|
||||||
}
|
}
|
||||||
if (!result.isEmpty()) {
|
if (!result.isEmpty()) {
|
||||||
@ -252,85 +213,48 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Task[] getIssues() throws Exception {
|
private Task[] getIssues() throws Exception {
|
||||||
return findIssues(null, -1, -1, false, null);
|
if (ifNoSelectedProj()) return new Task[]{};
|
||||||
}
|
ensureUserId();
|
||||||
|
|
||||||
private Task[] findIssues(String query, int offset, int limit, boolean withClosed, @SuppressWarnings("unused") ProgressIndicator cancelled) throws Exception {
|
|
||||||
if (!ensureUserId())
|
|
||||||
return new Task[]{};
|
|
||||||
|
|
||||||
StringBuilder qu = new StringBuilder();
|
|
||||||
if (query != null)
|
|
||||||
qu.append("?q=").append(URLEncoder.encode(query, "UTF-8"));
|
|
||||||
if (withClosed)
|
|
||||||
qu.append("&state=closed");
|
|
||||||
qu.append("&page=");
|
|
||||||
if (qu.length() > 0)
|
|
||||||
qu.setCharAt(0, '?');
|
|
||||||
List<GiteaTaskImpl> result = new ArrayList<>();
|
List<GiteaTaskImpl> result = new ArrayList<>();
|
||||||
final String url = getApiUrl() + Consts.EndPoint.REPOS + getProject() + Consts.EndPoint.ISSUES + qu.toString();
|
|
||||||
|
|
||||||
int firstPage = offset / DEFAULT_PAGE;
|
final String url = getApiUrl() + Consts.EndPoint.REPOS + selectedProject.getName() + Consts.EndPoint.ISSUES;
|
||||||
for (int p = firstPage + 1; ; p++) {
|
final JsonElement response = executeMethod(new GetMethod(url));
|
||||||
if (!loadPage(url, result, p, limit - result.size(),
|
|
||||||
assigned ? ((task) -> task.isAssignedTo(userLogin)) : null))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Collections.sort(result);
|
|
||||||
return result.toArray(new Task[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean loadPage(String url, List<GiteaTaskImpl> result, int page, int limit, Function<GiteaTask, Boolean> val) throws Exception {
|
|
||||||
final JsonElement response = executeMethod(new GetMethod(url + page));
|
|
||||||
if (response == null)
|
|
||||||
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(selectedProject, current);
|
||||||
if (!raw.isValid())
|
if (!raw.isValid()) {
|
||||||
continue;
|
|
||||||
if (val != null && !val.apply(raw))
|
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
GiteaTaskImpl mapped = new GiteaTaskImpl(this, raw);
|
GiteaTaskImpl mapped = new GiteaTaskImpl(this, raw);
|
||||||
result.add(mapped);
|
result.add(mapped);
|
||||||
if (limit > -1) {
|
|
||||||
limit--;
|
|
||||||
if (limit < 1)
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
Collections.sort(result);
|
||||||
return true;
|
Task[] primArray = new Task[result.size()];
|
||||||
|
return result.toArray(primArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getProject() {
|
private boolean ifNoSelectedProj() {
|
||||||
return String.format("%s/%s", repoName, projName);
|
return selectedProject == null || selectedProject.getId().equals("-1");
|
||||||
}
|
}
|
||||||
|
|
||||||
Comment[] getComments(GiteaTaskImpl task) throws Exception {
|
public Comment[] getComments(GiteaTaskImpl task) throws Exception {
|
||||||
if (!ensureUserId())
|
if (ifNoSelectedProj()) return new Comment[]{};
|
||||||
return new Comment[]{};
|
ensureUserId();
|
||||||
List<SimpleComment> result = new ArrayList<>();
|
List<SimpleComment> result = new ArrayList<>();
|
||||||
|
|
||||||
final String url = getApiUrl() + Consts.EndPoint.REPOS + getProject() + Consts.EndPoint.ISSUES
|
final String url = getApiUrl() + Consts.EndPoint.REPOS + selectedProject.getName() + Consts.EndPoint.ISSUES
|
||||||
+ "/" + task.getId() + Consts.EndPoint.COMMENTS;
|
+ "/" + task.getId() + Consts.EndPoint.COMMENTS;
|
||||||
final JsonElement response = executeMethod(new GetMethod(url));
|
final JsonElement response = executeMethod(new GetMethod(url));
|
||||||
if (response == null)
|
|
||||||
return new Comment[]{};
|
|
||||||
JsonArray comments = getArray(response);
|
JsonArray comments = getArray(response);
|
||||||
for (int i = 0; i < comments.size(); i++) {
|
for (int i = 0; i < comments.size(); i++) {
|
||||||
JsonObject current = comments.get(i).getAsJsonObject();
|
JsonObject current = comments.get(i).getAsJsonObject();
|
||||||
Date date = getDate(current, CommentFields.DATE);
|
Date date = getDate(current, CommentFields.DATE);
|
||||||
String text = getString(current, CommentFields.TEXT, "");
|
String text = getString(current, CommentFields.TEXT, "");
|
||||||
JsonObject juser = getObject(current, CommentFields.USER);
|
JsonObject user = getObject(current, CommentFields.USER);
|
||||||
String author = "";
|
String author = getString(user, CommentFields.FULLNAME, "");
|
||||||
if (!juser.isJsonNull()) {
|
if (author.isEmpty())
|
||||||
GiteaUser user = new GiteaUser(juser);
|
author = getString(user, CommentFields.USERNAME, "");
|
||||||
author = user.getName();
|
|
||||||
}
|
|
||||||
result.add(new SimpleComment(date, author, text));
|
result.add(new SimpleComment(date, author, text));
|
||||||
}
|
}
|
||||||
Comment[] primArray = new Comment[result.size()];
|
Comment[] primArray = new Comment[result.size()];
|
||||||
@ -338,16 +262,16 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private JsonElement executeMethod(@NotNull HttpMethod method) throws Exception {
|
private JsonElement executeMethod(@NotNull HttpMethod method) throws Exception {
|
||||||
method.addRequestHeader("Authorization", "token " + token);
|
|
||||||
method.addRequestHeader("Content-type", "application/json");
|
method.addRequestHeader("Content-type", "application/json");
|
||||||
|
List authPrefs = Collections.singletonList(AuthPolicy.BASIC);
|
||||||
|
method.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
|
||||||
getHttpClient().executeMethod(method);
|
getHttpClient().executeMethod(method);
|
||||||
|
|
||||||
if (method.getStatusCode() != HttpStatus.SC_OK && method.getStatusCode() != HttpStatus.SC_CREATED) {
|
if (method.getStatusCode() != HttpStatus.SC_OK && method.getStatusCode() != HttpStatus.SC_CREATED) {
|
||||||
logger.warn(String.format("HTTP error: %d, %s", method.getStatusCode(), method.getStatusText()));
|
throw new Exception("Request failed with HTTP error: " + method.getStatusText());
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new JsonParser().parse(new InputStreamReader(method.getResponseBodyAsStream(), StandardCharsets.UTF_8));
|
return new JsonParser().parse(new InputStreamReader(method.getResponseBodyAsStream(), "UTF-8"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private HttpMethod getPatchMethod(String url, StringRequestEntity data) {
|
private HttpMethod getPatchMethod(String url, StringRequestEntity data) {
|
||||||
@ -361,43 +285,42 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|||||||
return patchMethod;
|
return patchMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
private void ensureUserId() throws Exception {
|
||||||
private boolean ensureUserId() throws Exception {
|
if (userId == null || userId.isEmpty()) {
|
||||||
if (userLogin == null || userLogin.isEmpty()) {
|
|
||||||
JsonElement result = executeMethod(new GetMethod(getApiUrl() + Consts.EndPoint.ME));
|
JsonElement result = executeMethod(new GetMethod(getApiUrl() + Consts.EndPoint.ME));
|
||||||
if (result == null)
|
userId = result.getAsJsonObject().get("login").getAsJsonPrimitive().getAsString();
|
||||||
return false;
|
|
||||||
userId = result.getAsJsonObject().get("id").getAsJsonPrimitive().getAsString();
|
|
||||||
userLogin = result.getAsJsonObject().get("login").getAsJsonPrimitive().getAsString();
|
|
||||||
}
|
}
|
||||||
return true;
|
}
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
List<GiteaProject> getProjectList() throws Exception {
|
||||||
|
ensureUserId();
|
||||||
|
if (projects == null || projects.isEmpty()) {
|
||||||
|
JsonElement response = executeMethod(new GetMethod(getApiUrl() + Consts.EndPoint.REPOS_SEARCH + userId));
|
||||||
|
JsonArray query = getOkData(response);
|
||||||
|
List<GiteaProject> result = new ArrayList<>();
|
||||||
|
for (int i = 0; i < query.size(); i++) {
|
||||||
|
JsonObject current = getObject(query.get(i));
|
||||||
|
GiteaProject project = new GiteaProject().setId(getString(current, "id", ""))
|
||||||
|
.setName(getString(current, "full_name", ""));
|
||||||
|
if (!project.isValid()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
result.add(project);
|
||||||
|
}
|
||||||
|
projects = result;
|
||||||
|
}
|
||||||
|
return projects;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
public String getRepoName() {
|
public GiteaProject getSelectedProject() {
|
||||||
return repoName;
|
return selectedProject;
|
||||||
}
|
|
||||||
|
|
||||||
public void setRepoName(String repoName) {
|
|
||||||
this.repoName = repoName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
public String getProjName() {
|
public void setSelectedProject(GiteaProject selectedProject) {
|
||||||
return projName;
|
this.selectedProject = selectedProject;
|
||||||
}
|
|
||||||
|
|
||||||
public void setProjName(String projName) {
|
|
||||||
this.projName = projName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
|
||||||
public String getToken() {
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setToken(String token) {
|
|
||||||
this.token = token;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("UnusedDeclaration")
|
@SuppressWarnings("UnusedDeclaration")
|
||||||
@ -411,20 +334,13 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("UnusedDeclaration")
|
@SuppressWarnings("UnusedDeclaration")
|
||||||
public String getUserLogin() {
|
@AbstractCollection(surroundWithTag = false, elementTag = "GiteaProject", elementTypes = GiteaProject.class)
|
||||||
return userLogin;
|
public List<GiteaProject> getProjects() {
|
||||||
|
return projects;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("UnusedDeclaration")
|
@SuppressWarnings("UnusedDeclaration")
|
||||||
public void setUserLogin(String userLogin) {
|
public void setProjects(List<GiteaProject> projects) {
|
||||||
this.userLogin = userLogin;
|
this.projects = projects;
|
||||||
}
|
|
||||||
|
|
||||||
public void setAssigned(boolean assigned) {
|
|
||||||
this.assigned = assigned;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getAssigned() {
|
|
||||||
return assigned;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,101 +1,104 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2019 by elfuego.biz
|
* Copyright © 2018 by elfuego.biz
|
||||||
*/
|
*/
|
||||||
package biz.elfuego.idea.issues.gitea;
|
package biz.elfuego.idea.issues.gitea;
|
||||||
|
|
||||||
|
import biz.elfuego.idea.issues.gitea.model.GiteaProject;
|
||||||
|
import com.intellij.openapi.progress.ProgressIndicator;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.openapi.ui.ComboBox;
|
||||||
import com.intellij.tasks.config.BaseRepositoryEditor;
|
import com.intellij.tasks.config.BaseRepositoryEditor;
|
||||||
|
import com.intellij.tasks.impl.TaskUiUtil;
|
||||||
import com.intellij.ui.components.JBLabel;
|
import com.intellij.ui.components.JBLabel;
|
||||||
import com.intellij.util.Consumer;
|
import com.intellij.util.Consumer;
|
||||||
import com.intellij.util.ui.FormBuilder;
|
import com.intellij.util.ui.FormBuilder;
|
||||||
import org.jdesktop.swingx.HorizontalLayout;
|
import com.intellij.util.ui.UIUtil;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Roman Pedchenko <elfuego@elfuego.biz>
|
* @author Roman Pedchenko <elfuego@elfuego.biz>
|
||||||
* @date 2018.06.30
|
* @date 2018.06.30
|
||||||
*/
|
*/
|
||||||
public class GiteaRepositoryEditor extends BaseRepositoryEditor<GiteaRepository> {
|
public class GiteaRepositoryEditor extends BaseRepositoryEditor<GiteaRepository> {
|
||||||
private JBLabel repoLabel;
|
private JBLabel projectLabel;
|
||||||
private JTextField repoName;
|
private ComboBox projectBox;
|
||||||
|
|
||||||
private JTextField projName;
|
|
||||||
|
|
||||||
private JBLabel tokenLabel;
|
|
||||||
private JPasswordField token;
|
|
||||||
|
|
||||||
private JBLabel assignedLabel;
|
|
||||||
private JCheckBox assignedCheckBox;
|
|
||||||
|
|
||||||
GiteaRepositoryEditor(GiteaRepository repository, Project project, Consumer<GiteaRepository> consumer) {
|
GiteaRepositoryEditor(GiteaRepository repository, Project project, Consumer<GiteaRepository> consumer) {
|
||||||
super(project, repository, consumer);
|
super(project, repository, consumer);
|
||||||
|
|
||||||
repoName.setText(repository.getRepoName());
|
installListener(projectBox);
|
||||||
projName.setText(repository.getProjName());
|
|
||||||
token.setText(repository.getToken());
|
|
||||||
assignedCheckBox.setSelected(repository.getAssigned());
|
|
||||||
installListener(repoName);
|
|
||||||
installListener(projName);
|
|
||||||
installListener(token);
|
|
||||||
installListener(assignedCheckBox);
|
|
||||||
|
|
||||||
myUserNameText.setVisible(false);
|
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||||
myPasswordText.setVisible(false);
|
@Override
|
||||||
myUserNameText.setEnabled(false);
|
public void run() {
|
||||||
myPasswordText.setEnabled(false);
|
initialize();
|
||||||
myUsernameLabel.setVisible(false);
|
}
|
||||||
myPasswordLabel.setVisible(false);
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initialize() {
|
||||||
|
if (myRepository.isConfigured()) {
|
||||||
|
new FetchProjectsTask().queue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
protected JComponent createCustomPanel() {
|
protected JComponent createCustomPanel() {
|
||||||
JPanel panel = new JPanel();
|
projectBox = new ComboBox(300);
|
||||||
panel.setLayout(new HorizontalLayout());
|
projectBox.setRenderer(new TaskUiUtil.SimpleComboBoxRenderer("Set URL, username, and password"));
|
||||||
repoName = new JTextField(20);
|
projectLabel = new JBLabel("Project:", SwingConstants.RIGHT);
|
||||||
repoLabel = new JBLabel("Repository:", SwingConstants.RIGHT);
|
projectLabel.setLabelFor(projectBox);
|
||||||
repoLabel.setLabelFor(panel);
|
|
||||||
panel.add(repoName);
|
|
||||||
|
|
||||||
projName = new JTextField(30);
|
|
||||||
JBLabel projLabel = new JBLabel(" / Project: ", SwingConstants.RIGHT);
|
|
||||||
projLabel.setLabelFor(projName);
|
|
||||||
panel.add(projLabel);
|
|
||||||
panel.add(projName);
|
|
||||||
|
|
||||||
token = new JPasswordField();
|
|
||||||
tokenLabel = new JBLabel("Token:", SwingConstants.RIGHT);
|
|
||||||
tokenLabel.setLabelFor(token);
|
|
||||||
|
|
||||||
assignedCheckBox = new JCheckBox();
|
|
||||||
assignedLabel = new JBLabel("Only issues assigned to me:", SwingConstants.RIGHT);
|
|
||||||
assignedLabel.setLabelFor(assignedCheckBox);
|
|
||||||
|
|
||||||
return new FormBuilder().setAlignLabelOnRight(true)
|
return new FormBuilder().setAlignLabelOnRight(true)
|
||||||
.addLabeledComponent(repoLabel, panel)
|
.addLabeledComponent(projectLabel, projectBox)
|
||||||
.addLabeledComponent(tokenLabel, token)
|
|
||||||
.addLabeledComponent(assignedLabel, assignedCheckBox)
|
|
||||||
.getPanel();
|
.getPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAnchor(@Nullable JComponent anchor) {
|
public void setAnchor(@Nullable JComponent anchor) {
|
||||||
super.setAnchor(anchor);
|
super.setAnchor(anchor);
|
||||||
repoLabel.setAnchor(anchor);
|
projectLabel.setAnchor(anchor);
|
||||||
tokenLabel.setAnchor(anchor);
|
}
|
||||||
// assignedLabel.setAnchor(anchor);
|
|
||||||
|
@Override
|
||||||
|
protected void afterTestConnection(boolean connectionSuccessful) {
|
||||||
|
if (connectionSuccessful) {
|
||||||
|
new FetchProjectsTask().queue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply() {
|
public void apply() {
|
||||||
super.apply();
|
super.apply();
|
||||||
myRepository.setRepoName(repoName.getText());
|
myRepository.setSelectedProject((GiteaProject) projectBox.getSelectedItem());
|
||||||
myRepository.setProjName(projName.getText());
|
|
||||||
//noinspection deprecation
|
|
||||||
myRepository.setToken(token.getText());
|
|
||||||
myRepository.setAssigned(assignedCheckBox.isSelected());
|
|
||||||
myTestButton.setEnabled(myRepository.isConfigured());
|
myTestButton.setEnabled(myRepository.isConfigured());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class FetchProjectsTask extends TaskUiUtil.ComboBoxUpdater<GiteaProject> {
|
||||||
|
private FetchProjectsTask() {
|
||||||
|
super(GiteaRepositoryEditor.this.myProject, "Downloading Gitea projects...", projectBox);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GiteaProject getExtraItem() {
|
||||||
|
return GiteaProject.UNSPECIFIED_PROJECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public GiteaProject getSelectedItem() {
|
||||||
|
return myRepository.getSelectedProject();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
protected List<GiteaProject> fetch(@NotNull ProgressIndicator indicator) throws Exception {
|
||||||
|
return myRepository.getProjectList();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2019 by elfuego.biz
|
* Copyright © 2018 by elfuego.biz
|
||||||
*/
|
*/
|
||||||
package biz.elfuego.idea.issues.gitea;
|
package biz.elfuego.idea.issues.gitea;
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2019 by elfuego.biz
|
* Copyright © 2018 by elfuego.biz
|
||||||
*/
|
*/
|
||||||
package biz.elfuego.idea.issues.gitea;
|
package biz.elfuego.idea.issues.gitea;
|
||||||
|
|
||||||
|
import biz.elfuego.idea.issues.gitea.model.GiteaProject;
|
||||||
import biz.elfuego.idea.issues.gitea.model.GiteaTask;
|
import biz.elfuego.idea.issues.gitea.model.GiteaTask;
|
||||||
import biz.elfuego.idea.issues.gitea.util.Consts;
|
import biz.elfuego.idea.issues.gitea.util.Consts;
|
||||||
import com.intellij.openapi.util.IconLoader;
|
import com.intellij.openapi.util.IconLoader;
|
||||||
@ -21,10 +22,10 @@ import java.util.Date;
|
|||||||
* @date 2018.06.30
|
* @date 2018.06.30
|
||||||
*/
|
*/
|
||||||
public class GiteaTaskImpl extends Task implements Comparable<GiteaTaskImpl> {
|
public class GiteaTaskImpl extends Task implements Comparable<GiteaTaskImpl> {
|
||||||
private final String project;
|
private GiteaProject project;
|
||||||
private final GiteaRepository repository;
|
private GiteaRepository repository;
|
||||||
private Comment[] comments;
|
private Comment[] comments;
|
||||||
final GiteaTask task;
|
GiteaTask task;
|
||||||
|
|
||||||
GiteaTaskImpl(@NotNull GiteaRepository repository, @NotNull GiteaTask task) {
|
GiteaTaskImpl(@NotNull GiteaRepository repository, @NotNull GiteaTask task) {
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
@ -106,7 +107,7 @@ public class GiteaTaskImpl extends Task implements Comparable<GiteaTaskImpl> {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getIssueUrl() {
|
public String getIssueUrl() {
|
||||||
return repository.getUrl() + "/" + project + Consts.EndPoint.ISSUES + "/" + task.getId();
|
return repository.getUrl() + "/" + project.getName() + Consts.EndPoint.ISSUES + "/" + task.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
71
src/biz/elfuego/idea/issues/gitea/model/GiteaProject.java
Normal file
71
src/biz/elfuego/idea/issues/gitea/model/GiteaProject.java
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2018 by elfuego.biz
|
||||||
|
*/
|
||||||
|
package biz.elfuego.idea.issues.gitea.model;
|
||||||
|
|
||||||
|
import biz.elfuego.idea.issues.gitea.util.Consts;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Roman Pedchenko <elfuego@elfuego.biz>
|
||||||
|
* @date 2018.06.30
|
||||||
|
*/
|
||||||
|
public class GiteaProject {
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GiteaProject setId(String mProjectId) {
|
||||||
|
this.id = mProjectId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GiteaProject setName(String mProjectTitle) {
|
||||||
|
this.name = mProjectTitle;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isValid() {
|
||||||
|
return !(id.equals("") || name.equals(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name != null ? name : super.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o)
|
||||||
|
return true;
|
||||||
|
if (o == null || getClass() != o.getClass())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
GiteaProject that = (GiteaProject) o;
|
||||||
|
|
||||||
|
return (id != null ? id.equals(that.id) : that.id == null) && (name != null ? name.equals(that.name) : that.name == null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final GiteaProject UNSPECIFIED_PROJECT = new GiteaProject() {
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "-- Select A Project (Required) --";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getId() {
|
||||||
|
return Consts.UNSPEC_PROJ_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getName();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
@ -1,46 +1,41 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2019 by elfuego.biz
|
* Copyright © 2018 by elfuego.biz
|
||||||
*/
|
*/
|
||||||
package biz.elfuego.idea.issues.gitea.model;
|
package biz.elfuego.idea.issues.gitea.model;
|
||||||
|
|
||||||
import biz.elfuego.idea.issues.gitea.util.Consts.TaskFields;
|
import biz.elfuego.idea.issues.gitea.util.Consts.TaskFields;
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import org.apache.http.util.TextUtils;
|
import org.apache.http.util.TextUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static biz.elfuego.idea.issues.gitea.util.Utils.*;
|
import static biz.elfuego.idea.issues.gitea.util.Utils.getDate;
|
||||||
|
import static biz.elfuego.idea.issues.gitea.util.Utils.getString;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Roman Pedchenko <elfuego@elfuego.biz>
|
* @author Roman Pedchenko <elfuego@elfuego.biz>
|
||||||
* @date 2018.06.30
|
* @date 2018.06.30
|
||||||
*/
|
*/
|
||||||
public class GiteaTask {
|
public class GiteaTask {
|
||||||
private String project;
|
private GiteaProject project;
|
||||||
private String id;
|
private String id;
|
||||||
private String title;
|
private String title;
|
||||||
private String description;
|
private String description;
|
||||||
private Date createdAt;
|
private Date createdAt;
|
||||||
private Date updatedAt;
|
private Date updatedAt;
|
||||||
private String state;
|
private String state;
|
||||||
private GiteaUser assignee;
|
private String assignee;
|
||||||
private List<GiteaUser> assignees;
|
|
||||||
|
|
||||||
public GiteaTask(String project, JsonObject json) throws Exception {
|
public GiteaTask(GiteaProject project, JsonObject json) {
|
||||||
this.project = project;
|
this.project = project;
|
||||||
this.fromJson(json);
|
this.fromJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProject() {
|
public GiteaProject getProject() {
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
public void setProject(GiteaProject project) {
|
||||||
public void setProject(String project) {
|
|
||||||
this.project = project;
|
this.project = project;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,28 +88,20 @@ public class GiteaTask {
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("WeakerAccess")
|
||||||
public void setState(String state) {
|
public void setState(String state) {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
public String getAssignee() {
|
||||||
public GiteaUser getAssignee() {
|
|
||||||
return assignee;
|
return assignee;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
public void setAssignee(GiteaUser assignee) {
|
public void setAssignee(String assignee) {
|
||||||
this.assignee = assignee;
|
this.assignee = assignee;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GiteaUser> getAssignees() {
|
|
||||||
return assignees;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAssignees(List<GiteaUser> assignees) {
|
|
||||||
this.assignees = assignees;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isValid() {
|
public boolean isValid() {
|
||||||
return !(TextUtils.isEmpty(id) ||
|
return !(TextUtils.isEmpty(id) ||
|
||||||
TextUtils.isEmpty(title) ||
|
TextUtils.isEmpty(title) ||
|
||||||
@ -123,32 +110,27 @@ public class GiteaTask {
|
|||||||
TextUtils.isEmpty(state));
|
TextUtils.isEmpty(state));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAssignedTo(String login) {
|
private void fromJson(JsonObject current) {
|
||||||
if (assignee != null && assignee.getLogin().equals(login))
|
if (current.has(TaskFields.ID)) {
|
||||||
return true;
|
this.setId(getString(current, TaskFields.ID, ""));
|
||||||
if (assignees != null)
|
|
||||||
for (GiteaUser u : assignees)
|
|
||||||
if (u.getLogin().equals(login))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
if (current.has(TaskFields.TITLE)) {
|
||||||
private void fromJson(JsonObject current) throws Exception {
|
|
||||||
this.setId(getString(current, TaskFields.NUMBER, ""));
|
|
||||||
this.setTitle(getString(current, TaskFields.TITLE, ""));
|
this.setTitle(getString(current, TaskFields.TITLE, ""));
|
||||||
|
}
|
||||||
|
if (current.has(TaskFields.DESCRIPTION)) {
|
||||||
this.setDescription(getString(current, TaskFields.DESCRIPTION, ""));
|
this.setDescription(getString(current, TaskFields.DESCRIPTION, ""));
|
||||||
|
}
|
||||||
|
if (current.has(TaskFields.CREATEDAT)) {
|
||||||
this.setCreatedAt(getDate(current, TaskFields.CREATEDAT));
|
this.setCreatedAt(getDate(current, TaskFields.CREATEDAT));
|
||||||
|
}
|
||||||
|
if (current.has(TaskFields.UPDATEDAT)) {
|
||||||
this.setUpdatedAt(getDate(current, TaskFields.UPDATEDAT));
|
this.setUpdatedAt(getDate(current, TaskFields.UPDATEDAT));
|
||||||
|
}
|
||||||
|
if (current.has(TaskFields.STATE)) {
|
||||||
this.setState(getString(current, TaskFields.STATE, ""));
|
this.setState(getString(current, TaskFields.STATE, ""));
|
||||||
if (current.has(TaskFields.ASSIGNEE) && current.get(TaskFields.ASSIGNEE).isJsonObject())
|
}
|
||||||
this.setAssignee(new GiteaUser(getObject(current, TaskFields.ASSIGNEE)));
|
if (current.has(TaskFields.ASSIGNEE)) {
|
||||||
if (current.has(TaskFields.ASSIGNEES) && current.get(TaskFields.ASSIGNEES).isJsonArray()) {
|
this.setAssignee(getString(current, TaskFields.ASSIGNEE, ""));
|
||||||
JsonArray arr = getArray(current.get(TaskFields.ASSIGNEES));
|
|
||||||
List<GiteaUser> assignees1 = new ArrayList<>();
|
|
||||||
for (JsonElement el : arr)
|
|
||||||
if (el.isJsonObject())
|
|
||||||
assignees1.add(new GiteaUser(getObject(el)));
|
|
||||||
this.setAssignees(assignees1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,108 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright © 2019 by elfuego.biz
|
|
||||||
*/
|
|
||||||
package biz.elfuego.idea.issues.gitea.model;
|
|
||||||
|
|
||||||
import biz.elfuego.idea.issues.gitea.util.Consts;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import static biz.elfuego.idea.issues.gitea.util.Utils.getString;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Roman Pedchenko <elfuego@elfuego.biz>
|
|
||||||
* @date 2019.04.04
|
|
||||||
*/
|
|
||||||
public class GiteaUser {
|
|
||||||
private String id;
|
|
||||||
private String login;
|
|
||||||
private String username;
|
|
||||||
private String full_name;
|
|
||||||
private String email;
|
|
||||||
private String avatar_url;
|
|
||||||
private String language;
|
|
||||||
|
|
||||||
public GiteaUser(JsonObject json) {
|
|
||||||
this.fromJson(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
|
||||||
public void setId(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLogin() {
|
|
||||||
return login;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
|
||||||
public void setLogin(String login) {
|
|
||||||
this.login = login;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
|
||||||
public void setUsername(String username) {
|
|
||||||
this.username = username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFull_name() {
|
|
||||||
return full_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
|
||||||
public void setFull_name(String full_name) {
|
|
||||||
this.full_name = full_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmail() {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
|
||||||
public void setEmail(String email) {
|
|
||||||
this.email = email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAvatar_url() {
|
|
||||||
return avatar_url;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
|
||||||
public void setAvatar_url(String avatar_url) {
|
|
||||||
this.avatar_url = avatar_url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLanguage() {
|
|
||||||
return language;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
|
||||||
public void setLanguage(String language) {
|
|
||||||
this.language = language;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
if (!full_name.isEmpty())
|
|
||||||
return full_name;
|
|
||||||
if (!username.isEmpty())
|
|
||||||
return username;
|
|
||||||
return login;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void fromJson(JsonObject current) {
|
|
||||||
this.setId(getString(current, Consts.UserFields.ID, ""));
|
|
||||||
this.setLogin(getString(current, Consts.UserFields.LOGIN, ""));
|
|
||||||
this.setUsername(getString(current, Consts.UserFields.USERNAME, ""));
|
|
||||||
this.setFull_name(getString(current, Consts.UserFields.FULL_NAME, ""));
|
|
||||||
this.setEmail(getString(current, Consts.UserFields.EMAIL, ""));
|
|
||||||
this.setAvatar_url(getString(current, Consts.UserFields.AVATAR_URL, ""));
|
|
||||||
this.setLanguage(getString(current, Consts.UserFields.LANGUAGE, ""));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2019 by elfuego.biz
|
* Copyright © 2018 by elfuego.biz
|
||||||
*/
|
*/
|
||||||
package biz.elfuego.idea.issues.gitea.util;
|
package biz.elfuego.idea.issues.gitea.util;
|
||||||
|
|
||||||
@ -11,23 +11,6 @@ public class Consts {
|
|||||||
public static final String ERROR = "Error communicating to the server";
|
public static final String ERROR = "Error communicating to the server";
|
||||||
public static final String UNSPEC_PROJ_ID = "--";
|
public static final String UNSPEC_PROJ_ID = "--";
|
||||||
|
|
||||||
public enum ProjectFilter {
|
|
||||||
GENERAL("General search"),
|
|
||||||
CONTRUBUTOR("Owned and participated by me"),
|
|
||||||
OWNER("Owned by me");
|
|
||||||
|
|
||||||
private final String message;
|
|
||||||
|
|
||||||
ProjectFilter(String message) {
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return this.message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface Url {
|
public interface Url {
|
||||||
String DEFAULT = "https://try.gitea.io";
|
String DEFAULT = "https://try.gitea.io";
|
||||||
}
|
}
|
||||||
@ -38,9 +21,7 @@ public class Consts {
|
|||||||
String REPOS = "/repos/";
|
String REPOS = "/repos/";
|
||||||
String ISSUES = "/issues";
|
String ISSUES = "/issues";
|
||||||
String COMMENTS = "/comments";
|
String COMMENTS = "/comments";
|
||||||
String REPOS_SEARCH = REPOS + "search";
|
String REPOS_SEARCH = REPOS + "search?uid=";
|
||||||
String REPOS_SEARCH_UID = REPOS + "search?uid=";
|
|
||||||
String REPOS_SEARCH_UID_EX = REPOS + "search?exclusive=true&uid=";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum States {
|
public enum States {
|
||||||
@ -48,29 +29,20 @@ public class Consts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface TaskFields {
|
public interface TaskFields {
|
||||||
String NUMBER = "number";
|
String ID = "id";
|
||||||
String TITLE = "title";
|
String TITLE = "title";
|
||||||
String DESCRIPTION = "body";
|
String DESCRIPTION = "body";
|
||||||
String CREATEDAT = "created_at";
|
String CREATEDAT = "created_at";
|
||||||
String UPDATEDAT = "updated_at";
|
String UPDATEDAT = "updated_at";
|
||||||
String STATE = "state";
|
String STATE = "state";
|
||||||
String ASSIGNEE = "assignee";
|
String ASSIGNEE = "assignee";
|
||||||
String ASSIGNEES = "assignees";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface CommentFields {
|
public interface CommentFields {
|
||||||
String DATE = "updated_at";
|
String DATE = "updated_at";
|
||||||
String TEXT = "body";
|
String TEXT = "body";
|
||||||
String USER = "user";
|
String USER = "user";
|
||||||
}
|
String FULLNAME = "full_name";
|
||||||
|
|
||||||
public interface UserFields {
|
|
||||||
String ID = "id";
|
|
||||||
String LOGIN = "login";
|
|
||||||
String FULL_NAME = "full_name";
|
|
||||||
String EMAIL = "email";
|
|
||||||
String AVATAR_URL = "avatar_url";
|
|
||||||
String LANGUAGE = "language";
|
|
||||||
String USERNAME = "username";
|
String USERNAME = "username";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2019 by elfuego.biz
|
* Copyright © 2018 by elfuego.biz
|
||||||
*/
|
*/
|
||||||
package biz.elfuego.idea.issues.gitea.util;
|
package biz.elfuego.idea.issues.gitea.util;
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ public class Utils {
|
|||||||
int inset = 6;
|
int inset = 6;
|
||||||
|
|
||||||
String s0 = input.substring(0, input.length() - inset);
|
String s0 = input.substring(0, input.length() - inset);
|
||||||
String s1 = input.substring(input.length() - inset);
|
String s1 = input.substring(input.length() - inset, input.length());
|
||||||
|
|
||||||
input = s0 + "GMT" + s1;
|
input = s0 + "GMT" + s1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user