Search in sources :

Example 1 with GitlabProject

use of com.intellij.tasks.gitlab.model.GitlabProject in project intellij-community by JetBrains.

the class GitlabIntegrationTest method testIssueFilteringByState.

public void testIssueFilteringByState() throws Exception {
    final GitlabProject project = ContainerUtil.find(myRepository.getProjects(), p -> p.getName().equals("Issue Filtering Tests"));
    assertNotNull(project);
    myRepository.setCurrentProject(project);
    final Task[] allIssues = myRepository.getIssues("", 0, 20, true);
    assertSize(2, allIssues);
    assertNotNull(ContainerUtil.find(allIssues, task -> task.isClosed() && task.getSummary().equals("Closed issue #1")));
    assertNotNull(ContainerUtil.find(allIssues, task -> !task.isClosed() && task.getSummary().equals("Opened issue #1")));
    final Task[] openedIssues = myRepository.getIssues("", 0, 20, false);
    assertSize(1, openedIssues);
    assertFalse(openedIssues[0].isClosed());
    assertEquals("Opened issue #1", openedIssues[0].getSummary());
}
Also used : GitlabProject(com.intellij.tasks.gitlab.model.GitlabProject) TaskManagerTestCase(com.intellij.tasks.TaskManagerTestCase) GitlabTask(com.intellij.tasks.gitlab.GitlabTask) LocalTaskImpl(com.intellij.tasks.impl.LocalTaskImpl) Gson(com.google.gson.Gson) GitlabRepository(com.intellij.tasks.gitlab.GitlabRepository) GitlabIssue(com.intellij.tasks.gitlab.model.GitlabIssue) ContainerUtil(com.intellij.util.containers.ContainerUtil) Collections(java.util.Collections) TaskUtil(com.intellij.tasks.impl.TaskUtil) TaskGsonUtil(com.intellij.tasks.impl.gson.TaskGsonUtil) Task(com.intellij.tasks.Task) GitlabTask(com.intellij.tasks.gitlab.GitlabTask) Task(com.intellij.tasks.Task) GitlabProject(com.intellij.tasks.gitlab.model.GitlabProject)

Example 2 with GitlabProject

use of com.intellij.tasks.gitlab.model.GitlabProject in project intellij-community by JetBrains.

the class GitlabIntegrationTest method testCommitMessageFormat.

public void testCommitMessageFormat() throws Exception {
    String issueJson = "{\n" + "    \"id\": 1,\n" + "    \"iid\": 2,\n" + "    \"project_id\": 3,\n" + "    \"title\": \"Sample title\",\n" + "    \"state\": \"opened\",\n" + "    \"updated_at\": \"2013-11-14T12:30:39Z\",\n" + "    \"created_at\": \"2013-11-14T12:30:39Z\"\n" + "}";
    String projectJson = "{\n" + "   \"id\": 3,\n" + "   \"name\": \"project-1\"\n" + "}";
    GitlabIssue issue = GSON.fromJson(issueJson, GitlabIssue.class);
    GitlabProject project = GSON.fromJson(projectJson, GitlabProject.class);
    myRepository.setProjects(Collections.singletonList(project));
    myRepository.setShouldFormatCommitMessage(true);
    myRepository.setCommitMessageFormat("{project} {number} {id} {summary}");
    LocalTaskImpl localTask = new LocalTaskImpl(new GitlabTask(myRepository, issue));
    String changeListComment = TaskUtil.getChangeListComment(localTask);
    assertEquals("project-1 2 #2 Sample title", changeListComment);
    myRepository.setProjects(Collections.<GitlabProject>emptyList());
    localTask = new LocalTaskImpl(new GitlabTask(myRepository, issue));
    changeListComment = TaskUtil.getChangeListComment(localTask);
    // Project is unknown, so "" is substituted instead
    assertEquals(" 2 #2 Sample title", changeListComment);
}
Also used : LocalTaskImpl(com.intellij.tasks.impl.LocalTaskImpl) GitlabProject(com.intellij.tasks.gitlab.model.GitlabProject) GitlabTask(com.intellij.tasks.gitlab.GitlabTask) GitlabIssue(com.intellij.tasks.gitlab.model.GitlabIssue)

Example 3 with GitlabProject

use of com.intellij.tasks.gitlab.model.GitlabProject in project intellij-community by JetBrains.

the class GitlabRepository method fetchProjects.

/**
   * Always forcibly attempts do fetch new projects from server.
   */
@NotNull
public List<GitlabProject> fetchProjects() throws Exception {
    final ResponseHandler<List<GitlabProject>> handler = new GsonMultipleObjectsDeserializer<>(GSON, LIST_OF_PROJECTS_TYPE);
    final String projectUrl = getRestApiUrl("projects");
    final List<GitlabProject> result = new ArrayList<>();
    int pageNum = 1;
    while (true) {
        final URI paginatedProjectsUrl = new URIBuilder(projectUrl).addParameter("page", String.valueOf(pageNum)).addParameter("per_page", "30").build();
        final List<GitlabProject> page = getHttpClient().execute(new HttpGet(paginatedProjectsUrl), handler);
        // Gitlab's REST API doesn't allow to know beforehand how many projects are available
        if (page.isEmpty()) {
            break;
        }
        result.addAll(page);
        pageNum++;
    }
    myProjects = result;
    return Collections.unmodifiableList(myProjects);
}
Also used : GitlabProject(com.intellij.tasks.gitlab.model.GitlabProject) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) GsonMultipleObjectsDeserializer(com.intellij.tasks.impl.httpclient.TaskResponseUtil.GsonMultipleObjectsDeserializer) ArrayList(java.util.ArrayList) List(java.util.List) URI(java.net.URI) URIBuilder(org.apache.http.client.utils.URIBuilder) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GitlabProject (com.intellij.tasks.gitlab.model.GitlabProject)3 GitlabTask (com.intellij.tasks.gitlab.GitlabTask)2 GitlabIssue (com.intellij.tasks.gitlab.model.GitlabIssue)2 LocalTaskImpl (com.intellij.tasks.impl.LocalTaskImpl)2 Gson (com.google.gson.Gson)1 Task (com.intellij.tasks.Task)1 TaskManagerTestCase (com.intellij.tasks.TaskManagerTestCase)1 GitlabRepository (com.intellij.tasks.gitlab.GitlabRepository)1 TaskUtil (com.intellij.tasks.impl.TaskUtil)1 TaskGsonUtil (com.intellij.tasks.impl.gson.TaskGsonUtil)1 GsonMultipleObjectsDeserializer (com.intellij.tasks.impl.httpclient.TaskResponseUtil.GsonMultipleObjectsDeserializer)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 HttpGet (org.apache.http.client.methods.HttpGet)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1 NotNull (org.jetbrains.annotations.NotNull)1