mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Github: allow to change issue state
This commit is contained in:
@@ -519,6 +519,28 @@ public class GithubApiUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setIssueState(@NotNull GithubConnection connection,
|
||||
@NotNull String user,
|
||||
@NotNull String repo,
|
||||
@NotNull String id,
|
||||
boolean open)
|
||||
throws IOException {
|
||||
try {
|
||||
String path = "/repos/" + user + "/" + repo + "/issues/" + id;
|
||||
|
||||
GithubChangeIssueStateRequest request = new GithubChangeIssueStateRequest(open ? "open" : "closed");
|
||||
|
||||
JsonElement result = connection.patchRequest(path, gson.toJson(request), ACCEPT_V3_JSON);
|
||||
|
||||
createDataFromRaw(fromJson(result, GithubIssueRaw.class), GithubIssue.class);
|
||||
}
|
||||
catch (GithubConfusingException e) {
|
||||
e.setDetails("Can't set issue state: " + user + "/" + repo + " - " + id + "@" + (open ? "open" : "closed"));
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public static GithubCommitDetailed getCommit(@NotNull GithubConnection connection,
|
||||
@NotNull String user,
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package org.jetbrains.plugins.github.api;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
|
||||
public class GithubChangeIssueStateRequest {
|
||||
@NotNull private final String state;
|
||||
|
||||
public GithubChangeIssueStateRequest(@NotNull String state) {
|
||||
this.state = state;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
@@ -271,6 +268,28 @@ public class GithubRepository extends BaseRepositoryImpl {
|
||||
}
|
||||
}
|
||||
|
||||
@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
|
||||
@Override
|
||||
public BaseRepository clone() {
|
||||
@@ -353,6 +372,6 @@ public class GithubRepository extends BaseRepositoryImpl {
|
||||
|
||||
@Override
|
||||
protected int getFeatures() {
|
||||
return super.getFeatures() | BASIC_HTTP_AUTHORIZATION;
|
||||
return super.getFeatures() | STATE_UPDATING;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user