Search in sources :

Example 1 with GithubConnection

use of org.jetbrains.plugins.github.api.GithubConnection in project intellij-community by JetBrains.

the class GithubRepository method setTaskState.

@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();
    }
}
Also used : GithubConnection(org.jetbrains.plugins.github.api.GithubConnection)

Example 2 with GithubConnection

use of org.jetbrains.plugins.github.api.GithubConnection in project intellij-community by JetBrains.

the class GithubRepository method findTask.

@Nullable
@Override
public Task findTask(@NotNull String id) throws Exception {
    final int index = id.lastIndexOf("-");
    if (index < 0) {
        return null;
    }
    final String numericId = id.substring(index + 1);
    GithubConnection connection = getConnection();
    try {
        return createTask(GithubApiUtil.getIssue(connection, getRepoAuthor(), getRepoName(), numericId));
    } catch (GithubStatusCodeException e) {
        if (e.getStatusCode() == 404) {
            return null;
        }
        throw e;
    } finally {
        connection.close();
    }
}
Also used : GithubConnection(org.jetbrains.plugins.github.api.GithubConnection) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with GithubConnection

use of org.jetbrains.plugins.github.api.GithubConnection in project intellij-community by JetBrains.

the class GithubIssuesTest method testQueriedIssues1.

public void testQueriedIssues1() throws Exception {
    List<GithubIssue> result = GithubApiUtil.getIssuesQueried(new GithubConnection(myAuth), myLogin2, REPO_NAME, null, "abracadabra", true);
    List<Long> issues = ContainerUtil.map(result, new Function<GithubIssue, Long>() {

        @Override
        public Long fun(GithubIssue githubIssue) {
            return githubIssue.getNumber();
        }
    });
    List<Long> expected = Arrays.asList(10L, 12L);
    assertTrue(Comparing.haveEqualElements(issues, expected));
}
Also used : GithubConnection(org.jetbrains.plugins.github.api.GithubConnection) GithubIssue(org.jetbrains.plugins.github.api.data.GithubIssue)

Example 4 with GithubConnection

use of org.jetbrains.plugins.github.api.GithubConnection in project intellij-community by JetBrains.

the class GithubIssuesTest method testAssigneeIssues2.

public void testAssigneeIssues2() throws Exception {
    List<GithubIssue> result = GithubApiUtil.getIssuesAssigned(new GithubConnection(myAuth), myLogin2, REPO_NAME, myLogin2, 100, false);
    List<Long> issues = ContainerUtil.map(result, new Function<GithubIssue, Long>() {

        @Override
        public Long fun(GithubIssue githubIssue) {
            return githubIssue.getNumber();
        }
    });
    List<Long> expected = Arrays.asList(1L, 2L);
    assertTrue(Comparing.haveEqualElements(issues, expected));
}
Also used : GithubConnection(org.jetbrains.plugins.github.api.GithubConnection) GithubIssue(org.jetbrains.plugins.github.api.data.GithubIssue)

Example 5 with GithubConnection

use of org.jetbrains.plugins.github.api.GithubConnection in project intellij-community by JetBrains.

the class GithubIssuesTest method testAssigneeIssues5.

public void testAssigneeIssues5() throws Exception {
    List<GithubIssue> result = GithubApiUtil.getIssuesAssigned(new GithubConnection(myAuth), myLogin2, REPO_NAME, myLogin2, 100, true);
    List<Long> issues = ContainerUtil.map(result, new Function<GithubIssue, Long>() {

        @Override
        public Long fun(GithubIssue githubIssue) {
            return githubIssue.getNumber();
        }
    });
    List<Long> expected = Arrays.asList(1L, 2L);
    assertTrue(Comparing.haveEqualElements(issues, expected));
}
Also used : GithubConnection(org.jetbrains.plugins.github.api.GithubConnection) GithubIssue(org.jetbrains.plugins.github.api.data.GithubIssue)

Aggregations

GithubConnection (org.jetbrains.plugins.github.api.GithubConnection)20 GithubIssue (org.jetbrains.plugins.github.api.data.GithubIssue)10 ArrayList (java.util.ArrayList)3 GithubRepo (org.jetbrains.plugins.github.api.data.GithubRepo)3 ContainerUtil (com.intellij.util.containers.ContainerUtil)2 List (java.util.List)2 NotNull (org.jetbrains.annotations.NotNull)2 GithubApiUtil (org.jetbrains.plugins.github.api.GithubApiUtil)2 GithubTwoFactorAuthenticationException (org.jetbrains.plugins.github.exceptions.GithubTwoFactorAuthenticationException)2 GithubTest (org.jetbrains.plugins.github.test.GithubTest)2 Assume.assumeNotNull (org.junit.Assume.assumeNotNull)2 Ref (com.intellij.openapi.util.Ref)1 Nullable (org.jetbrains.annotations.Nullable)1 GithubRepoDetailed (org.jetbrains.plugins.github.api.data.GithubRepoDetailed)1 GithubAuthenticationException (org.jetbrains.plugins.github.exceptions.GithubAuthenticationException)1 GithubOperationCanceledException (org.jetbrains.plugins.github.exceptions.GithubOperationCanceledException)1 GithubAuthData (org.jetbrains.plugins.github.util.GithubAuthData)1