mirror of
https://github.com/e1fueg0/intellij-gitea-plugin.git
synced 2024-10-27 20:34:04 +00:00
- added project filter
- fixed some serialization issues - made some code optimizations
This commit is contained in:
parent
356b9ec312
commit
f62d7081a5
@ -1,7 +1,7 @@
|
|||||||
<idea-plugin>
|
<idea-plugin>
|
||||||
<id>biz.elfuego.idea.issues.gitea</id>
|
<id>biz.elfuego.idea.issues.gitea</id>
|
||||||
<name>Gitea issues plugin</name>
|
<name>Gitea issues plugin</name>
|
||||||
<version>1.2</version>
|
<version>1.3</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[
|
||||||
|
@ -7,6 +7,7 @@ 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;
|
||||||
@ -45,6 +46,8 @@ import static biz.elfuego.idea.issues.gitea.util.Utils.*;
|
|||||||
@Tag("Gitea")
|
@Tag("Gitea")
|
||||||
class GiteaRepository extends BaseRepositoryImpl {
|
class GiteaRepository extends BaseRepositoryImpl {
|
||||||
private String userId = null;
|
private String userId = null;
|
||||||
|
private String userLogin = null;
|
||||||
|
private ProjectFilter projectFilter = ProjectFilter.GENERAL;
|
||||||
private List<GiteaProject> projects = new ArrayList<>();
|
private List<GiteaProject> projects = new ArrayList<>();
|
||||||
private GiteaProject selectedProject = null;
|
private GiteaProject selectedProject = null;
|
||||||
|
|
||||||
@ -64,13 +67,31 @@ 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;
|
||||||
|
projectFilter = other.projectFilter;
|
||||||
projects = other.projects;
|
projects = other.projects;
|
||||||
selectedProject = other.selectedProject;
|
selectedProject = other.selectedProject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == null || !(o instanceof GiteaRepository))
|
||||||
|
return false;
|
||||||
|
GiteaRepository other = (GiteaRepository) o;
|
||||||
|
return equal(userId, other.userId) &&
|
||||||
|
equal(userLogin, other.userLogin) &&
|
||||||
|
equal(projectFilter, other.projectFilter) &&
|
||||||
|
equal(projects, other.projects) &&
|
||||||
|
equal(selectedProject, other.selectedProject);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean equal(Object o1, Object o2) {
|
||||||
|
return o1 == null && o2 == null || o1 != null && o2 != 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;
|
||||||
}
|
}
|
||||||
@ -159,6 +180,7 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|||||||
|
|
||||||
private void doTest() throws Exception {
|
private void doTest() throws Exception {
|
||||||
userId = null;
|
userId = null;
|
||||||
|
userLogin = null;
|
||||||
checkSetup();
|
checkSetup();
|
||||||
JsonElement response = executeMethod(new GetMethod(getApiUrl() + Consts.EndPoint.ME));
|
JsonElement response = executeMethod(new GetMethod(getApiUrl() + Consts.EndPoint.ME));
|
||||||
final JsonObject obj = getObject(response);
|
final JsonObject obj = getObject(response);
|
||||||
@ -286,33 +308,56 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void ensureUserId() throws Exception {
|
private void 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));
|
||||||
userId = result.getAsJsonObject().get("login").getAsJsonPrimitive().getAsString();
|
userId = result.getAsJsonObject().get("id").getAsJsonPrimitive().getAsString();
|
||||||
|
userLogin = result.getAsJsonObject().get("login").getAsJsonPrimitive().getAsString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
List<GiteaProject> getProjectList() throws Exception {
|
List<GiteaProject> getProjectList(ProjectFilter projectFilter) throws Exception {
|
||||||
ensureUserId();
|
ensureUserId();
|
||||||
if (projects == null || projects.isEmpty()) {
|
final String query;
|
||||||
JsonElement response = executeMethod(new GetMethod(getApiUrl() + Consts.EndPoint.REPOS_SEARCH + userId));
|
if (projectFilter == null)
|
||||||
JsonArray query = getOkData(response);
|
projectFilter = ProjectFilter.GENERAL;
|
||||||
List<GiteaProject> result = new ArrayList<>();
|
switch (projectFilter) {
|
||||||
for (int i = 0; i < query.size(); i++) {
|
case CONTRUBUTOR:
|
||||||
JsonObject current = getObject(query.get(i));
|
query = Consts.EndPoint.REPOS_SEARCH_UID + userId;
|
||||||
GiteaProject project = new GiteaProject().setId(getString(current, "id", ""))
|
break;
|
||||||
.setName(getString(current, "full_name", ""));
|
case OWNER:
|
||||||
if (!project.isValid()) {
|
query = Consts.EndPoint.REPOS_SEARCH_UID_EX + userId;
|
||||||
continue;
|
break;
|
||||||
}
|
default:
|
||||||
result.add(project);
|
query = Consts.EndPoint.REPOS_SEARCH;
|
||||||
}
|
break;
|
||||||
projects = result;
|
|
||||||
}
|
}
|
||||||
|
JsonElement response = executeMethod(new GetMethod(getApiUrl() + query));
|
||||||
|
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;
|
return projects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("WeakerAccess")
|
||||||
|
public ProjectFilter getProjectFilter() {
|
||||||
|
return projectFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("WeakerAccess")
|
||||||
|
public void setProjectFilter(ProjectFilter projectFilter) {
|
||||||
|
this.projectFilter = projectFilter;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
public GiteaProject getSelectedProject() {
|
public GiteaProject getSelectedProject() {
|
||||||
return selectedProject;
|
return selectedProject;
|
||||||
@ -333,6 +378,16 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("UnusedDeclaration")
|
||||||
|
public String getUserLogin() {
|
||||||
|
return userLogin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("UnusedDeclaration")
|
||||||
|
public void setUserLogin(String userLogin) {
|
||||||
|
this.userLogin = userLogin;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("UnusedDeclaration")
|
@SuppressWarnings("UnusedDeclaration")
|
||||||
@AbstractCollection(surroundWithTag = false, elementTag = "GiteaProject", elementTypes = GiteaProject.class)
|
@AbstractCollection(surroundWithTag = false, elementTag = "GiteaProject", elementTypes = GiteaProject.class)
|
||||||
public List<GiteaProject> getProjects() {
|
public List<GiteaProject> getProjects() {
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
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.GiteaProject;
|
||||||
|
import biz.elfuego.idea.issues.gitea.util.Consts.ProjectFilter;
|
||||||
import com.intellij.openapi.progress.ProgressIndicator;
|
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.openapi.ui.ComboBox;
|
||||||
@ -27,17 +28,18 @@ public class GiteaRepositoryEditor extends BaseRepositoryEditor<GiteaRepository>
|
|||||||
private JBLabel projectLabel;
|
private JBLabel projectLabel;
|
||||||
private ComboBox projectBox;
|
private ComboBox projectBox;
|
||||||
|
|
||||||
|
private JBLabel filterLabel;
|
||||||
|
private ComboBox<ProjectFilter> filterBox;
|
||||||
|
|
||||||
GiteaRepositoryEditor(GiteaRepository repository, Project project, Consumer<GiteaRepository> consumer) {
|
GiteaRepositoryEditor(GiteaRepository repository, Project project, Consumer<GiteaRepository> consumer) {
|
||||||
super(project, repository, consumer);
|
super(project, repository, consumer);
|
||||||
|
|
||||||
|
filterBox.setSelectedItem(myRepository.getProjectFilter());
|
||||||
|
projectBox.setSelectedItem(myRepository.getSelectedProject());
|
||||||
|
installListener(filterBox);
|
||||||
installListener(projectBox);
|
installListener(projectBox);
|
||||||
|
|
||||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
UIUtil.invokeLaterIfNeeded(this::initialize);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
initialize();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
@ -49,12 +51,18 @@ public class GiteaRepositoryEditor extends BaseRepositoryEditor<GiteaRepository>
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
protected JComponent createCustomPanel() {
|
protected JComponent createCustomPanel() {
|
||||||
|
filterBox = new ComboBox<>(ProjectFilter.values(), 300);
|
||||||
|
filterBox.addActionListener(e -> new FetchProjectsTask().queue());
|
||||||
|
filterLabel = new JBLabel("Project filter:", SwingConstants.RIGHT);
|
||||||
|
filterLabel.setLabelFor(filterBox);
|
||||||
|
|
||||||
projectBox = new ComboBox(300);
|
projectBox = new ComboBox(300);
|
||||||
projectBox.setRenderer(new TaskUiUtil.SimpleComboBoxRenderer("Set URL, username, and password"));
|
projectBox.setRenderer(new TaskUiUtil.SimpleComboBoxRenderer("Set URL, username, and password"));
|
||||||
projectLabel = new JBLabel("Project:", SwingConstants.RIGHT);
|
projectLabel = new JBLabel("Project:", SwingConstants.RIGHT);
|
||||||
projectLabel.setLabelFor(projectBox);
|
projectLabel.setLabelFor(projectBox);
|
||||||
|
|
||||||
return new FormBuilder().setAlignLabelOnRight(true)
|
return new FormBuilder().setAlignLabelOnRight(true)
|
||||||
|
.addLabeledComponent(filterLabel, filterBox)
|
||||||
.addLabeledComponent(projectLabel, projectBox)
|
.addLabeledComponent(projectLabel, projectBox)
|
||||||
.getPanel();
|
.getPanel();
|
||||||
}
|
}
|
||||||
@ -62,6 +70,7 @@ public class GiteaRepositoryEditor extends BaseRepositoryEditor<GiteaRepository>
|
|||||||
@Override
|
@Override
|
||||||
public void setAnchor(@Nullable JComponent anchor) {
|
public void setAnchor(@Nullable JComponent anchor) {
|
||||||
super.setAnchor(anchor);
|
super.setAnchor(anchor);
|
||||||
|
filterLabel.setAnchor(anchor);
|
||||||
projectLabel.setAnchor(anchor);
|
projectLabel.setAnchor(anchor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,6 +84,7 @@ public class GiteaRepositoryEditor extends BaseRepositoryEditor<GiteaRepository>
|
|||||||
@Override
|
@Override
|
||||||
public void apply() {
|
public void apply() {
|
||||||
super.apply();
|
super.apply();
|
||||||
|
myRepository.setProjectFilter((ProjectFilter) filterBox.getSelectedItem());
|
||||||
myRepository.setSelectedProject((GiteaProject) projectBox.getSelectedItem());
|
myRepository.setSelectedProject((GiteaProject) projectBox.getSelectedItem());
|
||||||
myTestButton.setEnabled(myRepository.isConfigured());
|
myTestButton.setEnabled(myRepository.isConfigured());
|
||||||
}
|
}
|
||||||
@ -98,9 +108,7 @@ public class GiteaRepositoryEditor extends BaseRepositoryEditor<GiteaRepository>
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected List<GiteaProject> fetch(@NotNull ProgressIndicator indicator) throws Exception {
|
protected List<GiteaProject> fetch(@NotNull ProgressIndicator indicator) throws Exception {
|
||||||
myRepository.setSelectedProject(null);
|
return myRepository.getProjectList((ProjectFilter) filterBox.getSelectedItem());
|
||||||
myRepository.setProjects(null);
|
|
||||||
return myRepository.getProjectList();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,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 GiteaProject project;
|
private final GiteaProject project;
|
||||||
private GiteaRepository repository;
|
private final GiteaRepository repository;
|
||||||
private Comment[] comments;
|
private Comment[] comments;
|
||||||
GiteaTask task;
|
final GiteaTask task;
|
||||||
|
|
||||||
GiteaTaskImpl(@NotNull GiteaRepository repository, @NotNull GiteaTask task) {
|
GiteaTaskImpl(@NotNull GiteaRepository repository, @NotNull GiteaTask task) {
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
|
@ -11,6 +11,23 @@ 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";
|
||||||
}
|
}
|
||||||
@ -21,7 +38,9 @@ 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?uid=";
|
String REPOS_SEARCH = REPOS + "search";
|
||||||
|
String REPOS_SEARCH_UID = REPOS + "search?uid=";
|
||||||
|
String REPOS_SEARCH_UID_EX = REPOS + "search?exclusive=true&uid=";
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum States {
|
public enum States {
|
||||||
|
Loading…
Reference in New Issue
Block a user