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$/resources" type="java-resource" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="IntelliJ IDEA IU-173.4674.60" jdkType="IDEA JDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -1,11 +1,7 @@
|
||||
<!--
|
||||
~ Copyright © 2020 by elfuego.biz
|
||||
-->
|
||||
|
||||
<idea-plugin>
|
||||
<id>biz.elfuego.idea.issues.gitea</id>
|
||||
<name>Gitea issues</name>
|
||||
<version>1.6</version>
|
||||
<name>Gitea issues plugin</name>
|
||||
<version>1.1</version>
|
||||
<vendor email="support@elfuego.biz" url="http://elfuego.biz">elfuego.biz</vendor>
|
||||
|
||||
<description><![CDATA[
|
||||
@ -13,8 +9,7 @@
|
||||
]]></description>
|
||||
|
||||
<change-notes><![CDATA[
|
||||
Fixes errors with loading issues without limits (contributed by billlhead).<br>
|
||||
Fixes searching for issues containing white spaces (contributed by billlhead).<br>
|
||||
First implementation.<br>
|
||||
]]>
|
||||
</change-notes>
|
||||
|
||||
@ -29,4 +24,5 @@
|
||||
|
||||
<actions>
|
||||
</actions>
|
||||
|
||||
</idea-plugin>
|
||||
|
@ -1,17 +1,16 @@
|
||||
/*
|
||||
* Copyright © 2019 by elfuego.biz
|
||||
* Copyright © 2018 by elfuego.biz
|
||||
*/
|
||||
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.GiteaUser;
|
||||
import biz.elfuego.idea.issues.gitea.util.Consts;
|
||||
import biz.elfuego.idea.issues.gitea.util.Consts.CommentFields;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.tasks.Comment;
|
||||
@ -19,9 +18,12 @@ import com.intellij.tasks.CustomTaskState;
|
||||
import com.intellij.tasks.Task;
|
||||
import com.intellij.tasks.impl.BaseRepositoryImpl;
|
||||
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.Transient;
|
||||
import org.apache.commons.httpclient.HttpMethod;
|
||||
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.PostMethod;
|
||||
import org.apache.commons.httpclient.methods.StringRequestEntity;
|
||||
@ -30,10 +32,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -45,15 +44,9 @@ import static biz.elfuego.idea.issues.gitea.util.Utils.*;
|
||||
*/
|
||||
@Tag("Gitea")
|
||||
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 userLogin = null;
|
||||
private String repoName = null;
|
||||
private String projName = null;
|
||||
private String token = null;
|
||||
private boolean assigned = false;
|
||||
private List<GiteaProject> projects = new ArrayList<>();
|
||||
private GiteaProject selectedProject = null;
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public GiteaRepository() {
|
||||
@ -71,40 +64,20 @@ class GiteaRepository extends BaseRepositoryImpl {
|
||||
public GiteaRepository(GiteaRepository other) {
|
||||
super(other);
|
||||
userId = other.userId;
|
||||
userLogin = other.userLogin;
|
||||
repoName = other.repoName;
|
||||
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);
|
||||
projects = other.projects;
|
||||
selectedProject = other.selectedProject;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Task findTask(@NotNull String s) /*throws Exception*/ {
|
||||
public Task findTask(@NotNull String s) throws Exception {
|
||||
// TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
@ -174,24 +147,20 @@ class GiteaRepository extends BaseRepositoryImpl {
|
||||
"application/json",
|
||||
"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);
|
||||
executeMethod(patchTask);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getFeatures() {
|
||||
return STATE_UPDATING;
|
||||
return NATIVE_SEARCH | STATE_UPDATING;
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
userId = null;
|
||||
userLogin = null;
|
||||
checkSetup();
|
||||
GetMethod method = 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()));
|
||||
JsonElement response = executeMethod(new GetMethod(getApiUrl() + Consts.EndPoint.ME));
|
||||
final JsonObject obj = getObject(response);
|
||||
if (obj.has("id") && obj.has("login"))
|
||||
return;
|
||||
@ -212,13 +181,10 @@ class GiteaRepository extends BaseRepositoryImpl {
|
||||
if (result && StringUtil.isEmpty(this.getUrl())) {
|
||||
result = false;
|
||||
}
|
||||
if (result && StringUtil.isEmpty(this.getRepoName())) {
|
||||
if (result && StringUtil.isEmpty(this.getUsername())) {
|
||||
result = false;
|
||||
}
|
||||
if (result && StringUtil.isEmpty(this.getProjName())) {
|
||||
result = false;
|
||||
}
|
||||
if (result && StringUtil.isEmpty(this.getToken())) {
|
||||
if (result && StringUtil.isEmpty(this.getPassword())) {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
@ -231,19 +197,14 @@ class GiteaRepository extends BaseRepositoryImpl {
|
||||
result += "Server";
|
||||
errors++;
|
||||
}
|
||||
if (StringUtil.isEmpty(getRepoName())) {
|
||||
if (StringUtil.isEmpty(getUsername())) {
|
||||
result += !StringUtils.isEmpty(result) ? " & " : "";
|
||||
result += "Repo name";
|
||||
result += "Username";
|
||||
errors++;
|
||||
}
|
||||
if (StringUtil.isEmpty(getProjName())) {
|
||||
if (StringUtil.isEmpty(getPassword())) {
|
||||
result += !StringUtils.isEmpty(result) ? " & " : "";
|
||||
result += "Project name";
|
||||
errors++;
|
||||
}
|
||||
if (StringUtil.isEmpty(getToken())) {
|
||||
result += !StringUtils.isEmpty(result) ? " & " : "";
|
||||
result += "Token";
|
||||
result += "Password";
|
||||
errors++;
|
||||
}
|
||||
if (!result.isEmpty()) {
|
||||
@ -252,85 +213,48 @@ class GiteaRepository extends BaseRepositoryImpl {
|
||||
}
|
||||
|
||||
private Task[] getIssues() throws Exception {
|
||||
return findIssues(null, -1, -1, false, null);
|
||||
}
|
||||
|
||||
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, '?');
|
||||
if (ifNoSelectedProj()) return new Task[]{};
|
||||
ensureUserId();
|
||||
List<GiteaTaskImpl> result = new ArrayList<>();
|
||||
final String url = getApiUrl() + Consts.EndPoint.REPOS + getProject() + Consts.EndPoint.ISSUES + qu.toString();
|
||||
|
||||
int firstPage = offset / DEFAULT_PAGE;
|
||||
for (int p = firstPage + 1; ; p++) {
|
||||
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;
|
||||
final String url = getApiUrl() + Consts.EndPoint.REPOS + selectedProject.getName() + Consts.EndPoint.ISSUES;
|
||||
final JsonElement response = executeMethod(new GetMethod(url));
|
||||
JsonArray tasks = getArray(response);
|
||||
if (tasks.size() < 1)
|
||||
return false;
|
||||
for (int i = 0; i < tasks.size(); i++) {
|
||||
JsonObject current = tasks.get(i).getAsJsonObject();
|
||||
GiteaTask raw = new GiteaTask(getProject(), current);
|
||||
if (!raw.isValid())
|
||||
continue;
|
||||
if (val != null && !val.apply(raw))
|
||||
GiteaTask raw = new GiteaTask(selectedProject, current);
|
||||
if (!raw.isValid()) {
|
||||
continue;
|
||||
}
|
||||
GiteaTaskImpl mapped = new GiteaTaskImpl(this, raw);
|
||||
result.add(mapped);
|
||||
if (limit > -1) {
|
||||
limit--;
|
||||
if (limit < 1)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
Collections.sort(result);
|
||||
Task[] primArray = new Task[result.size()];
|
||||
return result.toArray(primArray);
|
||||
}
|
||||
|
||||
private String getProject() {
|
||||
return String.format("%s/%s", repoName, projName);
|
||||
private boolean ifNoSelectedProj() {
|
||||
return selectedProject == null || selectedProject.getId().equals("-1");
|
||||
}
|
||||
|
||||
Comment[] getComments(GiteaTaskImpl task) throws Exception {
|
||||
if (!ensureUserId())
|
||||
return new Comment[]{};
|
||||
public Comment[] getComments(GiteaTaskImpl task) throws Exception {
|
||||
if (ifNoSelectedProj()) return new Comment[]{};
|
||||
ensureUserId();
|
||||
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;
|
||||
final JsonElement response = executeMethod(new GetMethod(url));
|
||||
if (response == null)
|
||||
return new Comment[]{};
|
||||
JsonArray comments = getArray(response);
|
||||
for (int i = 0; i < comments.size(); i++) {
|
||||
JsonObject current = comments.get(i).getAsJsonObject();
|
||||
Date date = getDate(current, CommentFields.DATE);
|
||||
String text = getString(current, CommentFields.TEXT, "");
|
||||
JsonObject juser = getObject(current, CommentFields.USER);
|
||||
String author = "";
|
||||
if (!juser.isJsonNull()) {
|
||||
GiteaUser user = new GiteaUser(juser);
|
||||
author = user.getName();
|
||||
}
|
||||
JsonObject user = getObject(current, CommentFields.USER);
|
||||
String author = getString(user, CommentFields.FULLNAME, "");
|
||||
if (author.isEmpty())
|
||||
author = getString(user, CommentFields.USERNAME, "");
|
||||
result.add(new SimpleComment(date, author, text));
|
||||
}
|
||||
Comment[] primArray = new Comment[result.size()];
|
||||
@ -338,16 +262,16 @@ class GiteaRepository extends BaseRepositoryImpl {
|
||||
}
|
||||
|
||||
private JsonElement executeMethod(@NotNull HttpMethod method) throws Exception {
|
||||
method.addRequestHeader("Authorization", "token " + token);
|
||||
method.addRequestHeader("Content-type", "application/json");
|
||||
List authPrefs = Collections.singletonList(AuthPolicy.BASIC);
|
||||
method.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
|
||||
getHttpClient().executeMethod(method);
|
||||
|
||||
if (method.getStatusCode() != HttpStatus.SC_OK && method.getStatusCode() != HttpStatus.SC_CREATED) {
|
||||
logger.warn(String.format("HTTP error: %d, %s", method.getStatusCode(), method.getStatusText()));
|
||||
return null;
|
||||
throw new Exception("Request failed with HTTP error: " + method.getStatusText());
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -361,43 +285,42 @@ class GiteaRepository extends BaseRepositoryImpl {
|
||||
return patchMethod;
|
||||
}
|
||||
|
||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||
private boolean ensureUserId() throws Exception {
|
||||
if (userLogin == null || userLogin.isEmpty()) {
|
||||
private void ensureUserId() throws Exception {
|
||||
if (userId == null || userId.isEmpty()) {
|
||||
JsonElement result = executeMethod(new GetMethod(getApiUrl() + Consts.EndPoint.ME));
|
||||
if (result == null)
|
||||
return false;
|
||||
userId = result.getAsJsonObject().get("id").getAsJsonPrimitive().getAsString();
|
||||
userLogin = result.getAsJsonObject().get("login").getAsJsonPrimitive().getAsString();
|
||||
userId = 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")
|
||||
public String getRepoName() {
|
||||
return repoName;
|
||||
}
|
||||
|
||||
public void setRepoName(String repoName) {
|
||||
this.repoName = repoName;
|
||||
public GiteaProject getSelectedProject() {
|
||||
return selectedProject;
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public String getProjName() {
|
||||
return projName;
|
||||
}
|
||||
|
||||
public void setProjName(String projName) {
|
||||
this.projName = projName;
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
public void setSelectedProject(GiteaProject selectedProject) {
|
||||
this.selectedProject = selectedProject;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
@ -411,20 +334,13 @@ class GiteaRepository extends BaseRepositoryImpl {
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public String getUserLogin() {
|
||||
return userLogin;
|
||||
@AbstractCollection(surroundWithTag = false, elementTag = "GiteaProject", elementTypes = GiteaProject.class)
|
||||
public List<GiteaProject> getProjects() {
|
||||
return projects;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public void setUserLogin(String userLogin) {
|
||||
this.userLogin = userLogin;
|
||||
}
|
||||
|
||||
public void setAssigned(boolean assigned) {
|
||||
this.assigned = assigned;
|
||||
}
|
||||
|
||||
public boolean getAssigned() {
|
||||
return assigned;
|
||||
public void setProjects(List<GiteaProject> projects) {
|
||||
this.projects = projects;
|
||||
}
|
||||
}
|
||||
|
@ -1,101 +1,104 @@
|
||||
/*
|
||||
* Copyright © 2019 by elfuego.biz
|
||||
* Copyright © 2018 by elfuego.biz
|
||||
*/
|
||||
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.ui.ComboBox;
|
||||
import com.intellij.tasks.config.BaseRepositoryEditor;
|
||||
import com.intellij.tasks.impl.TaskUiUtil;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.util.Consumer;
|
||||
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 javax.swing.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Roman Pedchenko <elfuego@elfuego.biz>
|
||||
* @date 2018.06.30
|
||||
*/
|
||||
public class GiteaRepositoryEditor extends BaseRepositoryEditor<GiteaRepository> {
|
||||
private JBLabel repoLabel;
|
||||
private JTextField repoName;
|
||||
|
||||
private JTextField projName;
|
||||
|
||||
private JBLabel tokenLabel;
|
||||
private JPasswordField token;
|
||||
|
||||
private JBLabel assignedLabel;
|
||||
private JCheckBox assignedCheckBox;
|
||||
private JBLabel projectLabel;
|
||||
private ComboBox projectBox;
|
||||
|
||||
GiteaRepositoryEditor(GiteaRepository repository, Project project, Consumer<GiteaRepository> consumer) {
|
||||
super(project, repository, consumer);
|
||||
|
||||
repoName.setText(repository.getRepoName());
|
||||
projName.setText(repository.getProjName());
|
||||
token.setText(repository.getToken());
|
||||
assignedCheckBox.setSelected(repository.getAssigned());
|
||||
installListener(repoName);
|
||||
installListener(projName);
|
||||
installListener(token);
|
||||
installListener(assignedCheckBox);
|
||||
installListener(projectBox);
|
||||
|
||||
myUserNameText.setVisible(false);
|
||||
myPasswordText.setVisible(false);
|
||||
myUserNameText.setEnabled(false);
|
||||
myPasswordText.setEnabled(false);
|
||||
myUsernameLabel.setVisible(false);
|
||||
myPasswordLabel.setVisible(false);
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
initialize();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
if (myRepository.isConfigured()) {
|
||||
new FetchProjectsTask().queue();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected JComponent createCustomPanel() {
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new HorizontalLayout());
|
||||
repoName = new JTextField(20);
|
||||
repoLabel = new JBLabel("Repository:", SwingConstants.RIGHT);
|
||||
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);
|
||||
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(repoLabel, panel)
|
||||
.addLabeledComponent(tokenLabel, token)
|
||||
.addLabeledComponent(assignedLabel, assignedCheckBox)
|
||||
.addLabeledComponent(projectLabel, projectBox)
|
||||
.getPanel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAnchor(@Nullable JComponent anchor) {
|
||||
super.setAnchor(anchor);
|
||||
repoLabel.setAnchor(anchor);
|
||||
tokenLabel.setAnchor(anchor);
|
||||
// assignedLabel.setAnchor(anchor);
|
||||
projectLabel.setAnchor(anchor);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void afterTestConnection(boolean connectionSuccessful) {
|
||||
if (connectionSuccessful) {
|
||||
new FetchProjectsTask().queue();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
super.apply();
|
||||
myRepository.setRepoName(repoName.getText());
|
||||
myRepository.setProjName(projName.getText());
|
||||
//noinspection deprecation
|
||||
myRepository.setToken(token.getText());
|
||||
myRepository.setAssigned(assignedCheckBox.isSelected());
|
||||
myRepository.setSelectedProject((GiteaProject) projectBox.getSelectedItem());
|
||||
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;
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
/*
|
||||
* Copyright © 2019 by elfuego.biz
|
||||
* Copyright © 2018 by elfuego.biz
|
||||
*/
|
||||
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.util.Consts;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
@ -21,10 +22,10 @@ import java.util.Date;
|
||||
* @date 2018.06.30
|
||||
*/
|
||||
public class GiteaTaskImpl extends Task implements Comparable<GiteaTaskImpl> {
|
||||
private final String project;
|
||||
private final GiteaRepository repository;
|
||||
private GiteaProject project;
|
||||
private GiteaRepository repository;
|
||||
private Comment[] comments;
|
||||
final GiteaTask task;
|
||||
GiteaTask task;
|
||||
|
||||
GiteaTaskImpl(@NotNull GiteaRepository repository, @NotNull GiteaTask task) {
|
||||
this.repository = repository;
|
||||
@ -106,7 +107,7 @@ public class GiteaTaskImpl extends Task implements Comparable<GiteaTaskImpl> {
|
||||
@Nullable
|
||||
@Override
|
||||
public String getIssueUrl() {
|
||||
return repository.getUrl() + "/" + project + Consts.EndPoint.ISSUES + "/" + task.getId();
|
||||
return repository.getUrl() + "/" + project.getName() + Consts.EndPoint.ISSUES + "/" + task.getId();
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
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 org.apache.http.util.TextUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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>
|
||||
* @date 2018.06.30
|
||||
*/
|
||||
public class GiteaTask {
|
||||
private String project;
|
||||
private GiteaProject project;
|
||||
private String id;
|
||||
private String title;
|
||||
private String description;
|
||||
private Date createdAt;
|
||||
private Date updatedAt;
|
||||
private String state;
|
||||
private GiteaUser assignee;
|
||||
private List<GiteaUser> assignees;
|
||||
private String assignee;
|
||||
|
||||
public GiteaTask(String project, JsonObject json) throws Exception {
|
||||
public GiteaTask(GiteaProject project, JsonObject json) {
|
||||
this.project = project;
|
||||
this.fromJson(json);
|
||||
}
|
||||
|
||||
public String getProject() {
|
||||
public GiteaProject getProject() {
|
||||
return project;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void setProject(String project) {
|
||||
public void setProject(GiteaProject project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
@ -93,28 +88,20 @@ public class GiteaTask {
|
||||
return state;
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public GiteaUser getAssignee() {
|
||||
public String getAssignee() {
|
||||
return assignee;
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public void setAssignee(GiteaUser assignee) {
|
||||
public void setAssignee(String assignee) {
|
||||
this.assignee = assignee;
|
||||
}
|
||||
|
||||
public List<GiteaUser> getAssignees() {
|
||||
return assignees;
|
||||
}
|
||||
|
||||
public void setAssignees(List<GiteaUser> assignees) {
|
||||
this.assignees = assignees;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return !(TextUtils.isEmpty(id) ||
|
||||
TextUtils.isEmpty(title) ||
|
||||
@ -123,32 +110,27 @@ public class GiteaTask {
|
||||
TextUtils.isEmpty(state));
|
||||
}
|
||||
|
||||
public boolean isAssignedTo(String login) {
|
||||
if (assignee != null && assignee.getLogin().equals(login))
|
||||
return true;
|
||||
if (assignees != null)
|
||||
for (GiteaUser u : assignees)
|
||||
if (u.getLogin().equals(login))
|
||||
return true;
|
||||
return false;
|
||||
private void fromJson(JsonObject current) {
|
||||
if (current.has(TaskFields.ID)) {
|
||||
this.setId(getString(current, TaskFields.ID, ""));
|
||||
}
|
||||
|
||||
private void fromJson(JsonObject current) throws Exception {
|
||||
this.setId(getString(current, TaskFields.NUMBER, ""));
|
||||
if (current.has(TaskFields.TITLE)) {
|
||||
this.setTitle(getString(current, TaskFields.TITLE, ""));
|
||||
}
|
||||
if (current.has(TaskFields.DESCRIPTION)) {
|
||||
this.setDescription(getString(current, TaskFields.DESCRIPTION, ""));
|
||||
}
|
||||
if (current.has(TaskFields.CREATEDAT)) {
|
||||
this.setCreatedAt(getDate(current, TaskFields.CREATEDAT));
|
||||
}
|
||||
if (current.has(TaskFields.UPDATEDAT)) {
|
||||
this.setUpdatedAt(getDate(current, TaskFields.UPDATEDAT));
|
||||
}
|
||||
if (current.has(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.ASSIGNEES) && current.get(TaskFields.ASSIGNEES).isJsonArray()) {
|
||||
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);
|
||||
}
|
||||
if (current.has(TaskFields.ASSIGNEE)) {
|
||||
this.setAssignee(getString(current, TaskFields.ASSIGNEE, ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
@ -11,23 +11,6 @@ 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";
|
||||
}
|
||||
@ -38,9 +21,7 @@ public class Consts {
|
||||
String REPOS = "/repos/";
|
||||
String ISSUES = "/issues";
|
||||
String COMMENTS = "/comments";
|
||||
String REPOS_SEARCH = REPOS + "search";
|
||||
String REPOS_SEARCH_UID = REPOS + "search?uid=";
|
||||
String REPOS_SEARCH_UID_EX = REPOS + "search?exclusive=true&uid=";
|
||||
String REPOS_SEARCH = REPOS + "search?uid=";
|
||||
}
|
||||
|
||||
public enum States {
|
||||
@ -48,29 +29,20 @@ public class Consts {
|
||||
}
|
||||
|
||||
public interface TaskFields {
|
||||
String NUMBER = "number";
|
||||
String ID = "id";
|
||||
String TITLE = "title";
|
||||
String DESCRIPTION = "body";
|
||||
String CREATEDAT = "created_at";
|
||||
String UPDATEDAT = "updated_at";
|
||||
String STATE = "state";
|
||||
String ASSIGNEE = "assignee";
|
||||
String ASSIGNEES = "assignees";
|
||||
}
|
||||
|
||||
public interface CommentFields {
|
||||
String DATE = "updated_at";
|
||||
String TEXT = "body";
|
||||
String USER = "user";
|
||||
}
|
||||
|
||||
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 FULLNAME = "full_name";
|
||||
String USERNAME = "username";
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2019 by elfuego.biz
|
||||
* Copyright © 2018 by elfuego.biz
|
||||
*/
|
||||
package biz.elfuego.idea.issues.gitea.util;
|
||||
|
||||
@ -44,7 +44,7 @@ public class Utils {
|
||||
int inset = 6;
|
||||
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user