summaryrefslogtreecommitdiff
path: root/plugins/github/src/org/jetbrains/plugins/github/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/github/src/org/jetbrains/plugins/github/tasks')
-rw-r--r--plugins/github/src/org/jetbrains/plugins/github/tasks/GithubComment.java12
-rw-r--r--plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepository.java118
-rw-r--r--plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java9
-rw-r--r--plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryType.java7
4 files changed, 99 insertions, 47 deletions
diff --git a/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubComment.java b/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubComment.java
index d65a95044a9c..e3115f71975c 100644
--- a/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubComment.java
+++ b/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubComment.java
@@ -26,16 +26,16 @@ import java.util.Date;
* @author Dennis.Ushakov
*/
public class GithubComment extends SimpleComment {
- @Nullable private final String myGravatarId;
+ @Nullable private final String myAvatarUrl;
@NotNull private final String myUserHtmlUrl;
public GithubComment(@Nullable Date date,
@Nullable String author,
@NotNull String text,
- @Nullable String gravatarId,
+ @Nullable String avatarUrl,
@NotNull String userHtmlUrl) {
super(date, author, text);
- myGravatarId = gravatarId;
+ myAvatarUrl = avatarUrl;
myUserHtmlUrl = userHtmlUrl;
}
@@ -43,9 +43,9 @@ public class GithubComment extends SimpleComment {
builder.append("<hr>");
builder.append("<table>");
builder.append("<tr><td>");
- if (myGravatarId != null) {
- builder.append("<img src=\"").append("http://www.gravatar.com/avatar/").append(myGravatarId).append("?s=40\"/><br>");
- }
+ if (myAvatarUrl != null) {
+ builder.append("<img src=\"").append(myAvatarUrl).append("\" height=\"40\" width=\"40\"/><br>");
+ }
builder.append("</td><td>");
if (getAuthor() != null) {
builder.append("<b>Author:</b> <a href=\"").append(myUserHtmlUrl).append("\">").append(getAuthor()).append("</a><br>");
diff --git a/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepository.java b/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepository.java
index 7ad3238f8a12..a8445b7f76ac 100644
--- a/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepository.java
+++ b/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepository.java
@@ -5,10 +5,7 @@ import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.PasswordUtil;
import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.tasks.Comment;
-import com.intellij.tasks.Task;
-import com.intellij.tasks.TaskRepository;
-import com.intellij.tasks.TaskType;
+import com.intellij.tasks.*;
import com.intellij.tasks.impl.BaseRepository;
import com.intellij.tasks.impl.BaseRepositoryImpl;
import com.intellij.util.Function;
@@ -19,12 +16,10 @@ import icons.TasksIcons;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.github.api.GithubApiUtil;
+import org.jetbrains.plugins.github.api.GithubConnection;
import org.jetbrains.plugins.github.api.GithubIssue;
import org.jetbrains.plugins.github.api.GithubIssueComment;
-import org.jetbrains.plugins.github.exceptions.GithubAuthenticationException;
-import org.jetbrains.plugins.github.exceptions.GithubJsonException;
-import org.jetbrains.plugins.github.exceptions.GithubRateLimitExceededException;
-import org.jetbrains.plugins.github.exceptions.GithubStatusCodeException;
+import org.jetbrains.plugins.github.exceptions.*;
import org.jetbrains.plugins.github.util.GithubAuthData;
import org.jetbrains.plugins.github.util.GithubUtil;
@@ -67,14 +62,20 @@ public class GithubRepository extends BaseRepositoryImpl {
@Override
public CancellableConnection createCancellableConnection() {
return new CancellableConnection() {
+ private final GithubConnection myConnection = new GithubConnection(getAuthData(), false);
+
@Override
protected void doTest() throws Exception {
- getIssues("", 10, false);
+ try {
+ GithubApiUtil.getIssuesQueried(myConnection, getRepoAuthor(), getRepoName(), "", false);
+ }
+ catch (GithubOperationCanceledException ignore) {
+ }
}
@Override
public void cancel() {
- // TODO
+ myConnection.abort();
}
};
}
@@ -122,23 +123,30 @@ public class GithubRepository extends BaseRepositoryImpl {
@NotNull
private Task[] getIssues(@Nullable String query, int max, boolean withClosed) throws Exception {
- List<GithubIssue> issues;
- if (StringUtil.isEmptyOrSpaces(query)) {
- if (StringUtil.isEmptyOrSpaces(myUser)) {
- myUser = GithubApiUtil.getCurrentUser(getAuthData()).getLogin();
+ GithubConnection connection = getConnection();
+
+ try {
+ List<GithubIssue> issues;
+ if (StringUtil.isEmptyOrSpaces(query)) {
+ if (StringUtil.isEmptyOrSpaces(myUser)) {
+ myUser = GithubApiUtil.getCurrentUser(connection).getLogin();
+ }
+ issues = GithubApiUtil.getIssuesAssigned(connection, getRepoAuthor(), getRepoName(), myUser, max, withClosed);
+ }
+ else {
+ issues = GithubApiUtil.getIssuesQueried(connection, getRepoAuthor(), getRepoName(), query, withClosed);
}
- issues = GithubApiUtil.getIssuesAssigned(getAuthData(), getRepoAuthor(), getRepoName(), myUser, max, withClosed);
+
+ return ContainerUtil.map2Array(issues, Task.class, new Function<GithubIssue, Task>() {
+ @Override
+ public Task fun(GithubIssue issue) {
+ return createTask(issue);
+ }
+ });
}
- else {
- issues = GithubApiUtil.getIssuesQueried(getAuthData(), getRepoAuthor(), getRepoName(), query, withClosed);
+ finally {
+ connection.close();
}
-
- return ContainerUtil.map2Array(issues, Task.class, new Function<GithubIssue, Task>() {
- @Override
- public Task fun(GithubIssue issue) {
- return createTask(issue);
- }
- });
}
@NotNull
@@ -224,16 +232,22 @@ public class GithubRepository extends BaseRepositoryImpl {
}
private Comment[] fetchComments(final long id) throws Exception {
- List<GithubIssueComment> result = GithubApiUtil.getIssueComments(getAuthData(), getRepoAuthor(), getRepoName(), id);
-
- return ContainerUtil.map2Array(result, Comment.class, new Function<GithubIssueComment, Comment>() {
- @Override
- public Comment fun(GithubIssueComment comment) {
- return new GithubComment(comment.getCreatedAt(), comment.getUser().getLogin(), comment.getBodyHtml(),
- comment.getUser().getGravatarId(),
- comment.getUser().getHtmlUrl());
- }
- });
+ GithubConnection connection = getConnection();
+ try {
+ List<GithubIssueComment> result = GithubApiUtil.getIssueComments(connection, getRepoAuthor(), getRepoName(), id);
+
+ return ContainerUtil.map2Array(result, Comment.class, new Function<GithubIssueComment, Comment>() {
+ @Override
+ public Comment fun(GithubIssueComment comment) {
+ return new GithubComment(comment.getCreatedAt(), comment.getUser().getLogin(), comment.getBodyHtml(),
+ comment.getUser().getAvatarUrl(),
+ comment.getUser().getHtmlUrl());
+ }
+ });
+ }
+ finally {
+ connection.close();
+ }
}
@Nullable
@@ -245,7 +259,35 @@ public class GithubRepository extends BaseRepositoryImpl {
@Nullable
@Override
public Task findTask(@NotNull String id) throws Exception {
- return createTask(GithubApiUtil.getIssue(getAuthData(), getRepoAuthor(), getRepoName(), id));
+ GithubConnection connection = getConnection();
+ try {
+ return createTask(GithubApiUtil.getIssue(connection, getRepoAuthor(), getRepoName(), id));
+ }
+ finally {
+ connection.close();
+ }
+ }
+
+ @Override
+ public void setTaskState(@NotNull Task task, @NotNull TaskState state) throws Exception {
+ GithubConnection connection = getConnection();
+ try {
+ boolean isOpen;
+ switch (state) {
+ case OPEN:
+ isOpen = true;
+ break;
+ case RESOLVED:
+ isOpen = false;
+ break;
+ default:
+ throw new IllegalStateException("Unknown state: " + state);
+ }
+ GithubApiUtil.setIssueState(connection, getRepoAuthor(), getRepoName(), task.getNumber(), isOpen);
+ }
+ finally {
+ connection.close();
+ }
}
@NotNull
@@ -311,6 +353,10 @@ public class GithubRepository extends BaseRepositoryImpl {
return GithubAuthData.createTokenAuth(getUrl(), getToken(), isUseProxy());
}
+ private GithubConnection getConnection() {
+ return new GithubConnection(getAuthData(), true);
+ }
+
@Override
public boolean equals(Object o) {
if (!super.equals(o)) return false;
@@ -326,6 +372,6 @@ public class GithubRepository extends BaseRepositoryImpl {
@Override
protected int getFeatures() {
- return super.getFeatures() | BASIC_HTTP_AUTHORIZATION;
+ return super.getFeatures() | STATE_UPDATING;
}
}
diff --git a/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java b/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java
index 5333d82e3baf..ba863621c969 100644
--- a/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java
+++ b/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java
@@ -14,8 +14,7 @@ import com.intellij.util.ui.GridBag;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.github.api.GithubApiUtil;
-import org.jetbrains.plugins.github.exceptions.GithubOperationCanceledException;
-import org.jetbrains.plugins.github.util.GithubAuthData;
+import org.jetbrains.plugins.github.api.GithubConnection;
import org.jetbrains.plugins.github.util.GithubAuthDataHolder;
import org.jetbrains.plugins.github.util.GithubNotifications;
import org.jetbrains.plugins.github.util.GithubUtil;
@@ -126,12 +125,12 @@ public class GithubRepositoryEditor extends BaseRepositoryEditor<GithubRepositor
public String convert(ProgressIndicator indicator) throws IOException {
return GithubUtil
.runTaskWithBasicAuthForHost(myProject, GithubAuthDataHolder.createFromSettings(), indicator, getHost(),
- new ThrowableConvertor<GithubAuthData, String, IOException>() {
+ new ThrowableConvertor<GithubConnection, String, IOException>() {
@NotNull
@Override
- public String convert(@NotNull GithubAuthData auth) throws IOException {
+ public String convert(@NotNull GithubConnection connection) throws IOException {
return GithubApiUtil
- .getReadOnlyToken(auth, getRepoAuthor(), getRepoName(), "IntelliJ tasks plugin");
+ .getReadOnlyToken(connection, getRepoAuthor(), getRepoName(), "IntelliJ tasks plugin");
}
}
);
diff --git a/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryType.java b/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryType.java
index a677fad0d781..eefab9065add 100644
--- a/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryType.java
+++ b/plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryType.java
@@ -2,6 +2,7 @@ package org.jetbrains.plugins.github.tasks;
import com.intellij.openapi.project.Project;
import com.intellij.tasks.TaskRepository;
+import com.intellij.tasks.TaskState;
import com.intellij.tasks.config.TaskRepositoryEditor;
import com.intellij.tasks.impl.BaseRepositoryType;
import com.intellij.util.Consumer;
@@ -9,6 +10,7 @@ import icons.TasksIcons;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
+import java.util.EnumSet;
/**
* @author Dennis.Ushakov
@@ -45,4 +47,9 @@ public class GithubRepositoryType extends BaseRepositoryType<GithubRepository> {
Consumer<GithubRepository> changeListener) {
return new GithubRepositoryEditor(project, repository, changeListener);
}
+
+ public EnumSet<TaskState> getPossibleTaskStates() {
+ return EnumSet.of(TaskState.OPEN, TaskState.RESOLVED);
+ }
+
}