mirror of
https://github.com/e1fueg0/intellij-gitea-plugin.git
synced 2025-06-07 18:04:06 +00:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
f16e8ff7da | ||
|
2f14392e1e | ||
|
1f7fcd7d03 | ||
|
e5e3e84b23 | ||
|
dba6bf0408 | ||
|
dc98e2adac | ||
|
01a7e1a17f |
@ -1,7 +1,11 @@
|
||||
<!--
|
||||
~ Copyright © 2020 by elfuego.biz
|
||||
-->
|
||||
|
||||
<idea-plugin>
|
||||
<id>biz.elfuego.idea.issues.gitea</id>
|
||||
<name>Gitea issues</name>
|
||||
<version>1.4</version>
|
||||
<version>1.6</version>
|
||||
<vendor email="support@elfuego.biz" url="http://elfuego.biz">elfuego.biz</vendor>
|
||||
|
||||
<description><![CDATA[
|
||||
@ -9,9 +13,8 @@
|
||||
]]></description>
|
||||
|
||||
<change-notes><![CDATA[
|
||||
Changed login method to token authorization.<br>
|
||||
Got rid of project search limitations by implementing manual project name input.<br>
|
||||
Fixed "HTTP: Unauthorized" exception.<br>
|
||||
Fixes errors with loading issues without limits (contributed by billlhead).<br>
|
||||
Fixes searching for issues containing white spaces (contributed by billlhead).<br>
|
||||
]]>
|
||||
</change-notes>
|
||||
|
||||
|
@ -1,9 +1,10 @@
|
||||
/*
|
||||
* Copyright © 2018 by elfuego.biz
|
||||
* Copyright © 2019 by elfuego.biz
|
||||
*/
|
||||
package biz.elfuego.idea.issues.gitea;
|
||||
|
||||
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;
|
||||
@ -29,8 +30,10 @@ 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;
|
||||
|
||||
@ -43,12 +46,14 @@ 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;
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public GiteaRepository() {
|
||||
@ -70,6 +75,7 @@ class GiteaRepository extends BaseRepositoryImpl {
|
||||
repoName = other.repoName;
|
||||
projName = other.projName;
|
||||
token = other.token;
|
||||
assigned = other.assigned;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -81,7 +87,8 @@ class GiteaRepository extends BaseRepositoryImpl {
|
||||
equal(userLogin, other.userLogin) &&
|
||||
equal(repoName, other.repoName) &&
|
||||
equal(projName, other.projName) &&
|
||||
equal(token, other.token);
|
||||
equal(token, other.token) &&
|
||||
equal(assigned, other.assigned);
|
||||
}
|
||||
|
||||
private boolean equal(Object o1, Object o2) {
|
||||
@ -97,7 +104,7 @@ class GiteaRepository extends BaseRepositoryImpl {
|
||||
|
||||
@Override
|
||||
public Task[] getIssues(@Nullable String query, int offset, int limit, boolean withClosed, @NotNull ProgressIndicator cancelled) throws Exception {
|
||||
return getIssues();
|
||||
return findIssues(query, offset, limit, withClosed, cancelled);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@ -174,7 +181,7 @@ class GiteaRepository extends BaseRepositoryImpl {
|
||||
|
||||
@Override
|
||||
protected int getFeatures() {
|
||||
return NATIVE_SEARCH | STATE_UPDATING;
|
||||
return STATE_UPDATING;
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
@ -245,27 +252,58 @@ 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[]{};
|
||||
List<GiteaTaskImpl> result = new ArrayList<>();
|
||||
|
||||
final String url = getApiUrl() + Consts.EndPoint.REPOS + getProject() + Consts.EndPoint.ISSUES;
|
||||
final JsonElement response = executeMethod(new GetMethod(url));
|
||||
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<>();
|
||||
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 new Task[]{};
|
||||
return false;
|
||||
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()) {
|
||||
if (!raw.isValid())
|
||||
continue;
|
||||
if (val != null && !val.apply(raw))
|
||||
continue;
|
||||
}
|
||||
GiteaTaskImpl mapped = new GiteaTaskImpl(this, raw);
|
||||
result.add(mapped);
|
||||
if (limit > -1) {
|
||||
limit--;
|
||||
if (limit < 1)
|
||||
return false;
|
||||
}
|
||||
Collections.sort(result);
|
||||
Task[] primArray = new Task[result.size()];
|
||||
return result.toArray(primArray);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private String getProject() {
|
||||
@ -287,10 +325,12 @@ class GiteaRepository extends BaseRepositoryImpl {
|
||||
JsonObject current = comments.get(i).getAsJsonObject();
|
||||
Date date = getDate(current, CommentFields.DATE);
|
||||
String text = getString(current, CommentFields.TEXT, "");
|
||||
JsonObject user = getObject(current, CommentFields.USER);
|
||||
String author = getString(user, CommentFields.FULLNAME, "");
|
||||
if (author.isEmpty())
|
||||
author = getString(user, CommentFields.USERNAME, "");
|
||||
JsonObject juser = getObject(current, CommentFields.USER);
|
||||
String author = "";
|
||||
if (!juser.isJsonNull()) {
|
||||
GiteaUser user = new GiteaUser(juser);
|
||||
author = user.getName();
|
||||
}
|
||||
result.add(new SimpleComment(date, author, text));
|
||||
}
|
||||
Comment[] primArray = new Comment[result.size()];
|
||||
@ -379,4 +419,12 @@ class GiteaRepository extends BaseRepositoryImpl {
|
||||
public void setUserLogin(String userLogin) {
|
||||
this.userLogin = userLogin;
|
||||
}
|
||||
|
||||
public void setAssigned(boolean assigned) {
|
||||
this.assigned = assigned;
|
||||
}
|
||||
|
||||
public boolean getAssigned() {
|
||||
return assigned;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2018 by elfuego.biz
|
||||
* Copyright © 2019 by elfuego.biz
|
||||
*/
|
||||
package biz.elfuego.idea.issues.gitea;
|
||||
|
||||
@ -26,15 +26,20 @@ public class GiteaRepositoryEditor extends BaseRepositoryEditor<GiteaRepository>
|
||||
private JBLabel tokenLabel;
|
||||
private JPasswordField token;
|
||||
|
||||
private JBLabel assignedLabel;
|
||||
private JCheckBox assignedCheckBox;
|
||||
|
||||
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);
|
||||
|
||||
myUserNameText.setVisible(false);
|
||||
myPasswordText.setVisible(false);
|
||||
@ -64,9 +69,14 @@ public class GiteaRepositoryEditor extends BaseRepositoryEditor<GiteaRepository>
|
||||
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)
|
||||
.addLabeledComponent(repoLabel, panel)
|
||||
.addLabeledComponent(tokenLabel, token)
|
||||
.addLabeledComponent(assignedLabel, assignedCheckBox)
|
||||
.getPanel();
|
||||
}
|
||||
|
||||
@ -75,6 +85,7 @@ public class GiteaRepositoryEditor extends BaseRepositoryEditor<GiteaRepository>
|
||||
super.setAnchor(anchor);
|
||||
repoLabel.setAnchor(anchor);
|
||||
tokenLabel.setAnchor(anchor);
|
||||
// assignedLabel.setAnchor(anchor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -84,6 +95,7 @@ public class GiteaRepositoryEditor extends BaseRepositoryEditor<GiteaRepository>
|
||||
myRepository.setProjName(projName.getText());
|
||||
//noinspection deprecation
|
||||
myRepository.setToken(token.getText());
|
||||
myRepository.setAssigned(assignedCheckBox.isSelected());
|
||||
myTestButton.setEnabled(myRepository.isConfigured());
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2018 by elfuego.biz
|
||||
* Copyright © 2019 by elfuego.biz
|
||||
*/
|
||||
package biz.elfuego.idea.issues.gitea;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2018 by elfuego.biz
|
||||
* Copyright © 2019 by elfuego.biz
|
||||
*/
|
||||
package biz.elfuego.idea.issues.gitea;
|
||||
|
||||
|
@ -1,16 +1,19 @@
|
||||
/*
|
||||
* Copyright © 2018 by elfuego.biz
|
||||
* Copyright © 2019 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.getDate;
|
||||
import static biz.elfuego.idea.issues.gitea.util.Utils.getString;
|
||||
import static biz.elfuego.idea.issues.gitea.util.Utils.*;
|
||||
|
||||
/**
|
||||
* @author Roman Pedchenko <elfuego@elfuego.biz>
|
||||
@ -24,9 +27,10 @@ public class GiteaTask {
|
||||
private Date createdAt;
|
||||
private Date updatedAt;
|
||||
private String state;
|
||||
private String assignee;
|
||||
private GiteaUser assignee;
|
||||
private List<GiteaUser> assignees;
|
||||
|
||||
public GiteaTask(String project, JsonObject json) {
|
||||
public GiteaTask(String project, JsonObject json) throws Exception {
|
||||
this.project = project;
|
||||
this.fromJson(json);
|
||||
}
|
||||
@ -94,15 +98,23 @@ public class GiteaTask {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public String getAssignee() {
|
||||
public GiteaUser getAssignee() {
|
||||
return assignee;
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public void setAssignee(String assignee) {
|
||||
public void setAssignee(GiteaUser 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) ||
|
||||
@ -111,27 +123,32 @@ public class GiteaTask {
|
||||
TextUtils.isEmpty(state));
|
||||
}
|
||||
|
||||
private void fromJson(JsonObject current) {
|
||||
if (current.has(TaskFields.NUMBER)) {
|
||||
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) 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)) {
|
||||
this.setAssignee(getString(current, TaskFields.ASSIGNEE, ""));
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
108
src/biz/elfuego/idea/issues/gitea/model/GiteaUser.java
Normal file
108
src/biz/elfuego/idea/issues/gitea/model/GiteaUser.java
Normal file
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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 © 2018 by elfuego.biz
|
||||
* Copyright © 2019 by elfuego.biz
|
||||
*/
|
||||
package biz.elfuego.idea.issues.gitea.util;
|
||||
|
||||
@ -55,13 +55,22 @@ public class Consts {
|
||||
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";
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2018 by elfuego.biz
|
||||
* Copyright © 2019 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, input.length());
|
||||
String s1 = input.substring(input.length() - inset);
|
||||
|
||||
input = s0 + "GMT" + s1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user