|
|
@ -3,11 +3,9 @@
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
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 biz.elfuego.idea.issues.gitea.util.Consts.CommentFields;
|
|
|
|
import biz.elfuego.idea.issues.gitea.util.Consts.CommentFields;
|
|
|
|
import biz.elfuego.idea.issues.gitea.util.Consts.ProjectFilter;
|
|
|
|
|
|
|
|
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;
|
|
|
@ -20,12 +18,9 @@ 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;
|
|
|
@ -51,9 +46,9 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|
|
|
|
|
|
|
|
|
|
|
private String userId = null;
|
|
|
|
private String userId = null;
|
|
|
|
private String userLogin = null;
|
|
|
|
private String userLogin = null;
|
|
|
|
private ProjectFilter projectFilter = ProjectFilter.GENERAL;
|
|
|
|
private String repoName = null;
|
|
|
|
private List<GiteaProject> projects = new ArrayList<>();
|
|
|
|
private String projName = null;
|
|
|
|
private GiteaProject selectedProject = null;
|
|
|
|
private String token = null;
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("UnusedDeclaration")
|
|
|
|
@SuppressWarnings("UnusedDeclaration")
|
|
|
|
public GiteaRepository() {
|
|
|
|
public GiteaRepository() {
|
|
|
@ -72,9 +67,9 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|
|
|
super(other);
|
|
|
|
super(other);
|
|
|
|
userId = other.userId;
|
|
|
|
userId = other.userId;
|
|
|
|
userLogin = other.userLogin;
|
|
|
|
userLogin = other.userLogin;
|
|
|
|
projectFilter = other.projectFilter;
|
|
|
|
repoName = other.repoName;
|
|
|
|
projects = other.projects;
|
|
|
|
projName = other.projName;
|
|
|
|
selectedProject = other.selectedProject;
|
|
|
|
token = other.token;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -84,9 +79,9 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|
|
|
GiteaRepository other = (GiteaRepository) o;
|
|
|
|
GiteaRepository other = (GiteaRepository) o;
|
|
|
|
return equal(userId, other.userId) &&
|
|
|
|
return equal(userId, other.userId) &&
|
|
|
|
equal(userLogin, other.userLogin) &&
|
|
|
|
equal(userLogin, other.userLogin) &&
|
|
|
|
equal(projectFilter, other.projectFilter) &&
|
|
|
|
equal(repoName, other.repoName) &&
|
|
|
|
equal(projects, other.projects) &&
|
|
|
|
equal(projName, other.projName) &&
|
|
|
|
equal(selectedProject, other.selectedProject);
|
|
|
|
equal(token, other.token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean equal(Object o1, Object o2) {
|
|
|
|
private boolean equal(Object o1, Object o2) {
|
|
|
@ -172,7 +167,7 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|
|
|
"application/json",
|
|
|
|
"application/json",
|
|
|
|
"UTF-8"
|
|
|
|
"UTF-8"
|
|
|
|
);
|
|
|
|
);
|
|
|
|
HttpMethod patchTask = getPatchMethod(getApiUrl() + Consts.EndPoint.REPOS + selectedProject.getName()
|
|
|
|
HttpMethod patchTask = getPatchMethod(getApiUrl() + Consts.EndPoint.REPOS + getProject()
|
|
|
|
+ Consts.EndPoint.ISSUES + "/" + giteaTask.getId(), data);
|
|
|
|
+ Consts.EndPoint.ISSUES + "/" + giteaTask.getId(), data);
|
|
|
|
executeMethod(patchTask);
|
|
|
|
executeMethod(patchTask);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -210,10 +205,13 @@ 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.getUsername())) {
|
|
|
|
if (result && StringUtil.isEmpty(this.getRepoName())) {
|
|
|
|
result = false;
|
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result && StringUtil.isEmpty(this.getPassword())) {
|
|
|
|
if (result && StringUtil.isEmpty(this.getProjName())) {
|
|
|
|
|
|
|
|
result = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result && StringUtil.isEmpty(this.getToken())) {
|
|
|
|
result = false;
|
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
@ -226,14 +224,19 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|
|
|
result += "Server";
|
|
|
|
result += "Server";
|
|
|
|
errors++;
|
|
|
|
errors++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtil.isEmpty(getUsername())) {
|
|
|
|
if (StringUtil.isEmpty(getRepoName())) {
|
|
|
|
|
|
|
|
result += !StringUtils.isEmpty(result) ? " & " : "";
|
|
|
|
|
|
|
|
result += "Repo name";
|
|
|
|
|
|
|
|
errors++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StringUtil.isEmpty(getProjName())) {
|
|
|
|
result += !StringUtils.isEmpty(result) ? " & " : "";
|
|
|
|
result += !StringUtils.isEmpty(result) ? " & " : "";
|
|
|
|
result += "Username";
|
|
|
|
result += "Project name";
|
|
|
|
errors++;
|
|
|
|
errors++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtil.isEmpty(getPassword())) {
|
|
|
|
if (StringUtil.isEmpty(getToken())) {
|
|
|
|
result += !StringUtils.isEmpty(result) ? " & " : "";
|
|
|
|
result += !StringUtils.isEmpty(result) ? " & " : "";
|
|
|
|
result += "Password";
|
|
|
|
result += "Token";
|
|
|
|
errors++;
|
|
|
|
errors++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!result.isEmpty()) {
|
|
|
|
if (!result.isEmpty()) {
|
|
|
@ -242,20 +245,18 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Task[] getIssues() throws Exception {
|
|
|
|
private Task[] getIssues() throws Exception {
|
|
|
|
if (ifNoSelectedProj())
|
|
|
|
|
|
|
|
return new Task[]{};
|
|
|
|
|
|
|
|
if (!ensureUserId())
|
|
|
|
if (!ensureUserId())
|
|
|
|
return new Task[]{};
|
|
|
|
return new Task[]{};
|
|
|
|
List<GiteaTaskImpl> result = new ArrayList<>();
|
|
|
|
List<GiteaTaskImpl> result = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
final String url = getApiUrl() + Consts.EndPoint.REPOS + selectedProject.getName() + Consts.EndPoint.ISSUES;
|
|
|
|
final String url = getApiUrl() + Consts.EndPoint.REPOS + getProject() + Consts.EndPoint.ISSUES;
|
|
|
|
final JsonElement response = executeMethod(new GetMethod(url));
|
|
|
|
final JsonElement response = executeMethod(new GetMethod(url));
|
|
|
|
if (response == null)
|
|
|
|
if (response == null)
|
|
|
|
return new Task[]{};
|
|
|
|
return new Task[]{};
|
|
|
|
JsonArray tasks = getArray(response);
|
|
|
|
JsonArray tasks = getArray(response);
|
|
|
|
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(selectedProject, current);
|
|
|
|
GiteaTask raw = new GiteaTask(getProject(), current);
|
|
|
|
if (!raw.isValid()) {
|
|
|
|
if (!raw.isValid()) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -267,18 +268,16 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|
|
|
return result.toArray(primArray);
|
|
|
|
return result.toArray(primArray);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean ifNoSelectedProj() {
|
|
|
|
private String getProject() {
|
|
|
|
return selectedProject == null || selectedProject.getId().equals("-1");
|
|
|
|
return String.format("%s/%s", repoName, projName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Comment[] getComments(GiteaTaskImpl task) throws Exception {
|
|
|
|
Comment[] getComments(GiteaTaskImpl task) throws Exception {
|
|
|
|
if (ifNoSelectedProj())
|
|
|
|
|
|
|
|
return new Comment[]{};
|
|
|
|
|
|
|
|
if (!ensureUserId())
|
|
|
|
if (!ensureUserId())
|
|
|
|
return new Comment[]{};
|
|
|
|
return new Comment[]{};
|
|
|
|
List<SimpleComment> result = new ArrayList<>();
|
|
|
|
List<SimpleComment> result = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
final String url = getApiUrl() + Consts.EndPoint.REPOS + selectedProject.getName() + Consts.EndPoint.ISSUES
|
|
|
|
final String url = getApiUrl() + Consts.EndPoint.REPOS + getProject() + 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)
|
|
|
|
if (response == null)
|
|
|
@ -299,9 +298,8 @@ 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) {
|
|
|
@ -335,56 +333,31 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transient
|
|
|
|
@SuppressWarnings("WeakerAccess")
|
|
|
|
List<GiteaProject> getProjectList(ProjectFilter projectFilter) throws Exception {
|
|
|
|
public String getRepoName() {
|
|
|
|
if (!ensureUserId())
|
|
|
|
return repoName;
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
|
|
|
final String query;
|
|
|
|
|
|
|
|
if (projectFilter == null)
|
|
|
|
|
|
|
|
projectFilter = ProjectFilter.GENERAL;
|
|
|
|
|
|
|
|
switch (projectFilter) {
|
|
|
|
|
|
|
|
case CONTRUBUTOR:
|
|
|
|
|
|
|
|
query = Consts.EndPoint.REPOS_SEARCH_UID + userId;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OWNER:
|
|
|
|
|
|
|
|
query = Consts.EndPoint.REPOS_SEARCH_UID_EX + userId;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
query = Consts.EndPoint.REPOS_SEARCH;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonElement response = executeMethod(new GetMethod(getApiUrl() + query));
|
|
|
|
|
|
|
|
if (response == null)
|
|
|
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
|
|
|
JsonArray reply = getOkData(response);
|
|
|
|
|
|
|
|
List<GiteaProject> result = new ArrayList<>();
|
|
|
|
|
|
|
|
for (int i = 0; i < reply.size(); i++) {
|
|
|
|
|
|
|
|
JsonObject current = getObject(reply.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;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ProjectFilter getProjectFilter() {
|
|
|
|
public void setRepoName(String repoName) {
|
|
|
|
return projectFilter;
|
|
|
|
this.repoName = repoName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setProjectFilter(ProjectFilter projectFilter) {
|
|
|
|
@SuppressWarnings("WeakerAccess")
|
|
|
|
this.projectFilter = projectFilter;
|
|
|
|
public String getProjName() {
|
|
|
|
|
|
|
|
return projName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public GiteaProject getSelectedProject() {
|
|
|
|
public void setProjName(String projName) {
|
|
|
|
return selectedProject;
|
|
|
|
this.projName = projName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setSelectedProject(GiteaProject selectedProject) {
|
|
|
|
@SuppressWarnings("WeakerAccess")
|
|
|
|
this.selectedProject = selectedProject;
|
|
|
|
public String getToken() {
|
|
|
|
|
|
|
|
return token;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setToken(String token) {
|
|
|
|
|
|
|
|
this.token = token;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("UnusedDeclaration")
|
|
|
|
@SuppressWarnings("UnusedDeclaration")
|
|
|
@ -406,15 +379,4 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|
|
|
public void setUserLogin(String userLogin) {
|
|
|
|
public void setUserLogin(String userLogin) {
|
|
|
|
this.userLogin = userLogin;
|
|
|
|
this.userLogin = userLogin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("UnusedDeclaration")
|
|
|
|
|
|
|
|
@AbstractCollection(surroundWithTag = false, elementTag = "GiteaProject", elementTypes = GiteaProject.class)
|
|
|
|
|
|
|
|
public List<GiteaProject> getProjects() {
|
|
|
|
|
|
|
|
return projects;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("UnusedDeclaration")
|
|
|
|
|
|
|
|
public void setProjects(List<GiteaProject> projects) {
|
|
|
|
|
|
|
|
this.projects = projects;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|