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>
|
||||
<id>biz.elfuego.idea.issues.gitea</id>
|
||||
<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>
|
||||
|
||||
<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.util.Consts;
|
||||
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.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
@ -45,6 +46,8 @@ import static biz.elfuego.idea.issues.gitea.util.Utils.*;
|
||||
@Tag("Gitea")
|
||||
class GiteaRepository extends BaseRepositoryImpl {
|
||||
private String userId = null;
|
||||
private String userLogin = null;
|
||||
private ProjectFilter projectFilter = ProjectFilter.GENERAL;
|
||||
private List<GiteaProject> projects = new ArrayList<>();
|
||||
private GiteaProject selectedProject = null;
|
||||
|
||||
@ -64,13 +67,31 @@ class GiteaRepository extends BaseRepositoryImpl {
|
||||
public GiteaRepository(GiteaRepository other) {
|
||||
super(other);
|
||||
userId = other.userId;
|
||||
userLogin = other.userLogin;
|
||||
projectFilter = other.projectFilter;
|
||||
projects = other.projects;
|
||||
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
|
||||
@Override
|
||||
public Task findTask(@NotNull String s) throws Exception {
|
||||
public Task findTask(@NotNull String s) /*throws Exception*/ {
|
||||
// TODO
|
||||
return null;
|
||||
}
|
||||
@ -159,6 +180,7 @@ class GiteaRepository extends BaseRepositoryImpl {
|
||||
|
||||
private void doTest() throws Exception {
|
||||
userId = null;
|
||||
userLogin = null;
|
||||
checkSetup();
|
||||
JsonElement response = executeMethod(new GetMethod(getApiUrl() + Consts.EndPoint.ME));
|
||||
final JsonObject obj = getObject(response);
|
||||
@ -286,33 +308,56 @@ class GiteaRepository extends BaseRepositoryImpl {
|
||||
}
|
||||
|
||||
private void ensureUserId() throws Exception {
|
||||
if (userId == null || userId.isEmpty()) {
|
||||
if (userLogin == null || userLogin.isEmpty()) {
|
||||
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
|
||||
List<GiteaProject> getProjectList() throws Exception {
|
||||
List<GiteaProject> getProjectList(ProjectFilter projectFilter) 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;
|
||||
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));
|
||||
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;
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public ProjectFilter getProjectFilter() {
|
||||
return projectFilter;
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public void setProjectFilter(ProjectFilter projectFilter) {
|
||||
this.projectFilter = projectFilter;
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public GiteaProject getSelectedProject() {
|
||||
return selectedProject;
|
||||
@ -333,6 +378,16 @@ class GiteaRepository extends BaseRepositoryImpl {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public String getUserLogin() {
|
||||
return userLogin;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public void setUserLogin(String userLogin) {
|
||||
this.userLogin = userLogin;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
@AbstractCollection(surroundWithTag = false, elementTag = "GiteaProject", elementTypes = GiteaProject.class)
|
||||
public List<GiteaProject> getProjects() {
|
||||
|
@ -4,6 +4,7 @@
|
||||
package biz.elfuego.idea.issues.gitea;
|
||||
|
||||
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.project.Project;
|
||||
import com.intellij.openapi.ui.ComboBox;
|
||||
@ -27,17 +28,18 @@ public class GiteaRepositoryEditor extends BaseRepositoryEditor<GiteaRepository>
|
||||
private JBLabel projectLabel;
|
||||
private ComboBox projectBox;
|
||||
|
||||
private JBLabel filterLabel;
|
||||
private ComboBox<ProjectFilter> filterBox;
|
||||
|
||||
GiteaRepositoryEditor(GiteaRepository repository, Project project, Consumer<GiteaRepository> consumer) {
|
||||
super(project, repository, consumer);
|
||||
|
||||
filterBox.setSelectedItem(myRepository.getProjectFilter());
|
||||
projectBox.setSelectedItem(myRepository.getSelectedProject());
|
||||
installListener(filterBox);
|
||||
installListener(projectBox);
|
||||
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
initialize();
|
||||
}
|
||||
});
|
||||
UIUtil.invokeLaterIfNeeded(this::initialize);
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
@ -49,12 +51,18 @@ public class GiteaRepositoryEditor extends BaseRepositoryEditor<GiteaRepository>
|
||||
@Nullable
|
||||
@Override
|
||||
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.setRenderer(new TaskUiUtil.SimpleComboBoxRenderer("Set URL, username, and password"));
|
||||
projectLabel = new JBLabel("Project:", SwingConstants.RIGHT);
|
||||
projectLabel.setLabelFor(projectBox);
|
||||
|
||||
return new FormBuilder().setAlignLabelOnRight(true)
|
||||
.addLabeledComponent(filterLabel, filterBox)
|
||||
.addLabeledComponent(projectLabel, projectBox)
|
||||
.getPanel();
|
||||
}
|
||||
@ -62,6 +70,7 @@ public class GiteaRepositoryEditor extends BaseRepositoryEditor<GiteaRepository>
|
||||
@Override
|
||||
public void setAnchor(@Nullable JComponent anchor) {
|
||||
super.setAnchor(anchor);
|
||||
filterLabel.setAnchor(anchor);
|
||||
projectLabel.setAnchor(anchor);
|
||||
}
|
||||
|
||||
@ -75,6 +84,7 @@ public class GiteaRepositoryEditor extends BaseRepositoryEditor<GiteaRepository>
|
||||
@Override
|
||||
public void apply() {
|
||||
super.apply();
|
||||
myRepository.setProjectFilter((ProjectFilter) filterBox.getSelectedItem());
|
||||
myRepository.setSelectedProject((GiteaProject) projectBox.getSelectedItem());
|
||||
myTestButton.setEnabled(myRepository.isConfigured());
|
||||
}
|
||||
@ -98,9 +108,7 @@ public class GiteaRepositoryEditor extends BaseRepositoryEditor<GiteaRepository>
|
||||
@NotNull
|
||||
@Override
|
||||
protected List<GiteaProject> fetch(@NotNull ProgressIndicator indicator) throws Exception {
|
||||
myRepository.setSelectedProject(null);
|
||||
myRepository.setProjects(null);
|
||||
return myRepository.getProjectList();
|
||||
return myRepository.getProjectList((ProjectFilter) filterBox.getSelectedItem());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,10 +22,10 @@ import java.util.Date;
|
||||
* @date 2018.06.30
|
||||
*/
|
||||
public class GiteaTaskImpl extends Task implements Comparable<GiteaTaskImpl> {
|
||||
private GiteaProject project;
|
||||
private GiteaRepository repository;
|
||||
private final GiteaProject project;
|
||||
private final GiteaRepository repository;
|
||||
private Comment[] comments;
|
||||
GiteaTask task;
|
||||
final GiteaTask task;
|
||||
|
||||
GiteaTaskImpl(@NotNull GiteaRepository repository, @NotNull GiteaTask task) {
|
||||
this.repository = repository;
|
||||
|
@ -11,6 +11,23 @@ public class Consts {
|
||||
public static final String ERROR = "Error communicating to the server";
|
||||
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 {
|
||||
String DEFAULT = "https://try.gitea.io";
|
||||
}
|
||||
@ -21,7 +38,9 @@ public class Consts {
|
||||
String REPOS = "/repos/";
|
||||
String ISSUES = "/issues";
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user