mirror of
https://github.com/e1fueg0/intellij-gitea-plugin.git
synced 2025-06-08 02:14:04 +00:00
Compare commits
No commits in common. "master" and "1.4" have entirely different histories.
@ -1,11 +1,7 @@
|
|||||||
<!--
|
|
||||||
~ Copyright © 2020 by elfuego.biz
|
|
||||||
-->
|
|
||||||
|
|
||||||
<idea-plugin>
|
<idea-plugin>
|
||||||
<id>biz.elfuego.idea.issues.gitea</id>
|
<id>biz.elfuego.idea.issues.gitea</id>
|
||||||
<name>Gitea issues</name>
|
<name>Gitea issues</name>
|
||||||
<version>1.6</version>
|
<version>1.4</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[
|
||||||
@ -13,8 +9,9 @@
|
|||||||
]]></description>
|
]]></description>
|
||||||
|
|
||||||
<change-notes><![CDATA[
|
<change-notes><![CDATA[
|
||||||
Fixes errors with loading issues without limits (contributed by billlhead).<br>
|
Changed login method to token authorization.<br>
|
||||||
Fixes searching for issues containing white spaces (contributed by billlhead).<br>
|
Got rid of project search limitations by implementing manual project name input.<br>
|
||||||
|
Fixed "HTTP: Unauthorized" exception.<br>
|
||||||
]]>
|
]]>
|
||||||
</change-notes>
|
</change-notes>
|
||||||
|
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2019 by elfuego.biz
|
* Copyright © 2018 by elfuego.biz
|
||||||
*/
|
*/
|
||||||
package biz.elfuego.idea.issues.gitea;
|
package biz.elfuego.idea.issues.gitea;
|
||||||
|
|
||||||
import biz.elfuego.idea.issues.gitea.model.GiteaTask;
|
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;
|
||||||
import biz.elfuego.idea.issues.gitea.util.Consts.CommentFields;
|
import biz.elfuego.idea.issues.gitea.util.Consts.CommentFields;
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
@ -30,10 +29,8 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -46,14 +43,12 @@ import static biz.elfuego.idea.issues.gitea.util.Utils.*;
|
|||||||
@Tag("Gitea")
|
@Tag("Gitea")
|
||||||
class GiteaRepository extends BaseRepositoryImpl {
|
class GiteaRepository extends BaseRepositoryImpl {
|
||||||
private static final Logger logger = Logger.getInstance(GiteaRepository.class);
|
private static final Logger logger = Logger.getInstance(GiteaRepository.class);
|
||||||
private static final int DEFAULT_PAGE = 10;
|
|
||||||
|
|
||||||
private String userId = null;
|
private String userId = null;
|
||||||
private String userLogin = null;
|
private String userLogin = null;
|
||||||
private String repoName = null;
|
private String repoName = null;
|
||||||
private String projName = null;
|
private String projName = null;
|
||||||
private String token = null;
|
private String token = null;
|
||||||
private boolean assigned = false;
|
|
||||||
|
|
||||||
@SuppressWarnings("UnusedDeclaration")
|
@SuppressWarnings("UnusedDeclaration")
|
||||||
public GiteaRepository() {
|
public GiteaRepository() {
|
||||||
@ -75,7 +70,6 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|||||||
repoName = other.repoName;
|
repoName = other.repoName;
|
||||||
projName = other.projName;
|
projName = other.projName;
|
||||||
token = other.token;
|
token = other.token;
|
||||||
assigned = other.assigned;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -87,8 +81,7 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|||||||
equal(userLogin, other.userLogin) &&
|
equal(userLogin, other.userLogin) &&
|
||||||
equal(repoName, other.repoName) &&
|
equal(repoName, other.repoName) &&
|
||||||
equal(projName, other.projName) &&
|
equal(projName, other.projName) &&
|
||||||
equal(token, other.token) &&
|
equal(token, other.token);
|
||||||
equal(assigned, other.assigned);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean equal(Object o1, Object o2) {
|
private boolean equal(Object o1, Object o2) {
|
||||||
@ -104,7 +97,7 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Task[] getIssues(@Nullable String query, int offset, int limit, boolean withClosed, @NotNull ProgressIndicator cancelled) throws Exception {
|
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
|
@NotNull
|
||||||
@ -181,7 +174,7 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getFeatures() {
|
protected int getFeatures() {
|
||||||
return STATE_UPDATING;
|
return NATIVE_SEARCH | STATE_UPDATING;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTest() throws Exception {
|
private void doTest() throws Exception {
|
||||||
@ -252,58 +245,27 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Task[] getIssues() throws Exception {
|
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())
|
if (!ensureUserId())
|
||||||
return new Task[]{};
|
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, '?');
|
|
||||||
List<GiteaTaskImpl> result = new ArrayList<>();
|
List<GiteaTaskImpl> result = new ArrayList<>();
|
||||||
final String url = getApiUrl() + Consts.EndPoint.REPOS + getProject() + Consts.EndPoint.ISSUES + qu.toString();
|
|
||||||
|
|
||||||
int firstPage = offset / DEFAULT_PAGE;
|
final String url = getApiUrl() + Consts.EndPoint.REPOS + getProject() + Consts.EndPoint.ISSUES;
|
||||||
for (int p = firstPage + 1; ; p++) {
|
final JsonElement response = executeMethod(new GetMethod(url));
|
||||||
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)
|
if (response == null)
|
||||||
return false;
|
return new Task[]{};
|
||||||
JsonArray tasks = getArray(response);
|
JsonArray tasks = getArray(response);
|
||||||
if (tasks.size() < 1)
|
|
||||||
return false;
|
|
||||||
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(getProject(), current);
|
GiteaTask raw = new GiteaTask(getProject(), current);
|
||||||
if (!raw.isValid())
|
if (!raw.isValid()) {
|
||||||
continue;
|
|
||||||
if (val != null && !val.apply(raw))
|
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
GiteaTaskImpl mapped = new GiteaTaskImpl(this, raw);
|
GiteaTaskImpl mapped = new GiteaTaskImpl(this, raw);
|
||||||
result.add(mapped);
|
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() {
|
private String getProject() {
|
||||||
@ -325,12 +287,10 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|||||||
JsonObject current = comments.get(i).getAsJsonObject();
|
JsonObject current = comments.get(i).getAsJsonObject();
|
||||||
Date date = getDate(current, CommentFields.DATE);
|
Date date = getDate(current, CommentFields.DATE);
|
||||||
String text = getString(current, CommentFields.TEXT, "");
|
String text = getString(current, CommentFields.TEXT, "");
|
||||||
JsonObject juser = getObject(current, CommentFields.USER);
|
JsonObject user = getObject(current, CommentFields.USER);
|
||||||
String author = "";
|
String author = getString(user, CommentFields.FULLNAME, "");
|
||||||
if (!juser.isJsonNull()) {
|
if (author.isEmpty())
|
||||||
GiteaUser user = new GiteaUser(juser);
|
author = getString(user, CommentFields.USERNAME, "");
|
||||||
author = user.getName();
|
|
||||||
}
|
|
||||||
result.add(new SimpleComment(date, author, text));
|
result.add(new SimpleComment(date, author, text));
|
||||||
}
|
}
|
||||||
Comment[] primArray = new Comment[result.size()];
|
Comment[] primArray = new Comment[result.size()];
|
||||||
@ -419,12 +379,4 @@ class GiteaRepository extends BaseRepositoryImpl {
|
|||||||
public void setUserLogin(String userLogin) {
|
public void setUserLogin(String userLogin) {
|
||||||
this.userLogin = userLogin;
|
this.userLogin = userLogin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAssigned(boolean assigned) {
|
|
||||||
this.assigned = assigned;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getAssigned() {
|
|
||||||
return assigned;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2019 by elfuego.biz
|
* Copyright © 2018 by elfuego.biz
|
||||||
*/
|
*/
|
||||||
package biz.elfuego.idea.issues.gitea;
|
package biz.elfuego.idea.issues.gitea;
|
||||||
|
|
||||||
@ -26,20 +26,15 @@ public class GiteaRepositoryEditor extends BaseRepositoryEditor<GiteaRepository>
|
|||||||
private JBLabel tokenLabel;
|
private JBLabel tokenLabel;
|
||||||
private JPasswordField token;
|
private JPasswordField token;
|
||||||
|
|
||||||
private JBLabel assignedLabel;
|
|
||||||
private JCheckBox assignedCheckBox;
|
|
||||||
|
|
||||||
GiteaRepositoryEditor(GiteaRepository repository, Project project, Consumer<GiteaRepository> consumer) {
|
GiteaRepositoryEditor(GiteaRepository repository, Project project, Consumer<GiteaRepository> consumer) {
|
||||||
super(project, repository, consumer);
|
super(project, repository, consumer);
|
||||||
|
|
||||||
repoName.setText(repository.getRepoName());
|
repoName.setText(repository.getRepoName());
|
||||||
projName.setText(repository.getProjName());
|
projName.setText(repository.getProjName());
|
||||||
token.setText(repository.getToken());
|
token.setText(repository.getToken());
|
||||||
assignedCheckBox.setSelected(repository.getAssigned());
|
|
||||||
installListener(repoName);
|
installListener(repoName);
|
||||||
installListener(projName);
|
installListener(projName);
|
||||||
installListener(token);
|
installListener(token);
|
||||||
installListener(assignedCheckBox);
|
|
||||||
|
|
||||||
myUserNameText.setVisible(false);
|
myUserNameText.setVisible(false);
|
||||||
myPasswordText.setVisible(false);
|
myPasswordText.setVisible(false);
|
||||||
@ -69,14 +64,9 @@ public class GiteaRepositoryEditor extends BaseRepositoryEditor<GiteaRepository>
|
|||||||
tokenLabel = new JBLabel("Token:", SwingConstants.RIGHT);
|
tokenLabel = new JBLabel("Token:", SwingConstants.RIGHT);
|
||||||
tokenLabel.setLabelFor(token);
|
tokenLabel.setLabelFor(token);
|
||||||
|
|
||||||
assignedCheckBox = new JCheckBox();
|
|
||||||
assignedLabel = new JBLabel("Only issues assigned to me:", SwingConstants.RIGHT);
|
|
||||||
assignedLabel.setLabelFor(assignedCheckBox);
|
|
||||||
|
|
||||||
return new FormBuilder().setAlignLabelOnRight(true)
|
return new FormBuilder().setAlignLabelOnRight(true)
|
||||||
.addLabeledComponent(repoLabel, panel)
|
.addLabeledComponent(repoLabel, panel)
|
||||||
.addLabeledComponent(tokenLabel, token)
|
.addLabeledComponent(tokenLabel, token)
|
||||||
.addLabeledComponent(assignedLabel, assignedCheckBox)
|
|
||||||
.getPanel();
|
.getPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +75,6 @@ public class GiteaRepositoryEditor extends BaseRepositoryEditor<GiteaRepository>
|
|||||||
super.setAnchor(anchor);
|
super.setAnchor(anchor);
|
||||||
repoLabel.setAnchor(anchor);
|
repoLabel.setAnchor(anchor);
|
||||||
tokenLabel.setAnchor(anchor);
|
tokenLabel.setAnchor(anchor);
|
||||||
// assignedLabel.setAnchor(anchor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -95,7 +84,6 @@ public class GiteaRepositoryEditor extends BaseRepositoryEditor<GiteaRepository>
|
|||||||
myRepository.setProjName(projName.getText());
|
myRepository.setProjName(projName.getText());
|
||||||
//noinspection deprecation
|
//noinspection deprecation
|
||||||
myRepository.setToken(token.getText());
|
myRepository.setToken(token.getText());
|
||||||
myRepository.setAssigned(assignedCheckBox.isSelected());
|
|
||||||
myTestButton.setEnabled(myRepository.isConfigured());
|
myTestButton.setEnabled(myRepository.isConfigured());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2019 by elfuego.biz
|
* Copyright © 2018 by elfuego.biz
|
||||||
*/
|
*/
|
||||||
package biz.elfuego.idea.issues.gitea;
|
package biz.elfuego.idea.issues.gitea;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2019 by elfuego.biz
|
* Copyright © 2018 by elfuego.biz
|
||||||
*/
|
*/
|
||||||
package biz.elfuego.idea.issues.gitea;
|
package biz.elfuego.idea.issues.gitea;
|
||||||
|
|
||||||
|
@ -1,19 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2019 by elfuego.biz
|
* Copyright © 2018 by elfuego.biz
|
||||||
*/
|
*/
|
||||||
package biz.elfuego.idea.issues.gitea.model;
|
package biz.elfuego.idea.issues.gitea.model;
|
||||||
|
|
||||||
import biz.elfuego.idea.issues.gitea.util.Consts.TaskFields;
|
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 com.google.gson.JsonObject;
|
||||||
import org.apache.http.util.TextUtils;
|
import org.apache.http.util.TextUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
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>
|
* @author Roman Pedchenko <elfuego@elfuego.biz>
|
||||||
@ -27,10 +24,9 @@ public class GiteaTask {
|
|||||||
private Date createdAt;
|
private Date createdAt;
|
||||||
private Date updatedAt;
|
private Date updatedAt;
|
||||||
private String state;
|
private String state;
|
||||||
private GiteaUser assignee;
|
private String assignee;
|
||||||
private List<GiteaUser> assignees;
|
|
||||||
|
|
||||||
public GiteaTask(String project, JsonObject json) throws Exception {
|
public GiteaTask(String project, JsonObject json) {
|
||||||
this.project = project;
|
this.project = project;
|
||||||
this.fromJson(json);
|
this.fromJson(json);
|
||||||
}
|
}
|
||||||
@ -98,23 +94,15 @@ public class GiteaTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public GiteaUser getAssignee() {
|
public String getAssignee() {
|
||||||
return assignee;
|
return assignee;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
public void setAssignee(GiteaUser assignee) {
|
public void setAssignee(String assignee) {
|
||||||
this.assignee = assignee;
|
this.assignee = assignee;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GiteaUser> getAssignees() {
|
|
||||||
return assignees;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAssignees(List<GiteaUser> assignees) {
|
|
||||||
this.assignees = assignees;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isValid() {
|
public boolean isValid() {
|
||||||
return !(TextUtils.isEmpty(id) ||
|
return !(TextUtils.isEmpty(id) ||
|
||||||
TextUtils.isEmpty(title) ||
|
TextUtils.isEmpty(title) ||
|
||||||
@ -123,32 +111,27 @@ public class GiteaTask {
|
|||||||
TextUtils.isEmpty(state));
|
TextUtils.isEmpty(state));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAssignedTo(String login) {
|
private void fromJson(JsonObject current) {
|
||||||
if (assignee != null && assignee.getLogin().equals(login))
|
if (current.has(TaskFields.NUMBER)) {
|
||||||
return true;
|
this.setId(getString(current, TaskFields.NUMBER, ""));
|
||||||
if (assignees != null)
|
}
|
||||||
for (GiteaUser u : assignees)
|
if (current.has(TaskFields.TITLE)) {
|
||||||
if (u.getLogin().equals(login))
|
this.setTitle(getString(current, TaskFields.TITLE, ""));
|
||||||
return true;
|
}
|
||||||
return false;
|
if (current.has(TaskFields.DESCRIPTION)) {
|
||||||
}
|
this.setDescription(getString(current, TaskFields.DESCRIPTION, ""));
|
||||||
|
}
|
||||||
private void fromJson(JsonObject current) throws Exception {
|
if (current.has(TaskFields.CREATEDAT)) {
|
||||||
this.setId(getString(current, TaskFields.NUMBER, ""));
|
this.setCreatedAt(getDate(current, TaskFields.CREATEDAT));
|
||||||
this.setTitle(getString(current, TaskFields.TITLE, ""));
|
}
|
||||||
this.setDescription(getString(current, TaskFields.DESCRIPTION, ""));
|
if (current.has(TaskFields.UPDATEDAT)) {
|
||||||
this.setCreatedAt(getDate(current, TaskFields.CREATEDAT));
|
this.setUpdatedAt(getDate(current, TaskFields.UPDATEDAT));
|
||||||
this.setUpdatedAt(getDate(current, TaskFields.UPDATEDAT));
|
}
|
||||||
this.setState(getString(current, TaskFields.STATE, ""));
|
if (current.has(TaskFields.STATE)) {
|
||||||
if (current.has(TaskFields.ASSIGNEE) && current.get(TaskFields.ASSIGNEE).isJsonObject())
|
this.setState(getString(current, TaskFields.STATE, ""));
|
||||||
this.setAssignee(new GiteaUser(getObject(current, TaskFields.ASSIGNEE)));
|
}
|
||||||
if (current.has(TaskFields.ASSIGNEES) && current.get(TaskFields.ASSIGNEES).isJsonArray()) {
|
if (current.has(TaskFields.ASSIGNEE)) {
|
||||||
JsonArray arr = getArray(current.get(TaskFields.ASSIGNEES));
|
this.setAssignee(getString(current, TaskFields.ASSIGNEE, ""));
|
||||||
List<GiteaUser> assignees1 = new ArrayList<>();
|
|
||||||
for (JsonElement el : arr)
|
|
||||||
if (el.isJsonObject())
|
|
||||||
assignees1.add(new GiteaUser(getObject(el)));
|
|
||||||
this.setAssignees(assignees1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
package biz.elfuego.idea.issues.gitea.util;
|
||||||
|
|
||||||
@ -55,22 +55,13 @@ public class Consts {
|
|||||||
String UPDATEDAT = "updated_at";
|
String UPDATEDAT = "updated_at";
|
||||||
String STATE = "state";
|
String STATE = "state";
|
||||||
String ASSIGNEE = "assignee";
|
String ASSIGNEE = "assignee";
|
||||||
String ASSIGNEES = "assignees";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface CommentFields {
|
public interface CommentFields {
|
||||||
String DATE = "updated_at";
|
String DATE = "updated_at";
|
||||||
String TEXT = "body";
|
String TEXT = "body";
|
||||||
String USER = "user";
|
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";
|
String USERNAME = "username";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2019 by elfuego.biz
|
* Copyright © 2018 by elfuego.biz
|
||||||
*/
|
*/
|
||||||
package biz.elfuego.idea.issues.gitea.util;
|
package biz.elfuego.idea.issues.gitea.util;
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ public class Utils {
|
|||||||
int inset = 6;
|
int inset = 6;
|
||||||
|
|
||||||
String s0 = input.substring(0, input.length() - inset);
|
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;
|
input = s0 + "GMT" + s1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user