follow-up: Tasks from Github now map to TaskTypes based on the GithubIssue labels. "bug" --> TaskType.BUG "enhancement" --> TaskType.FEATURE all others --> TaskType.OTHER

Make GithubRepository visible for testing and fix build for tests

GitOrigin-RevId: 282f237675df6f77ca97f2cf5d3f7d37f99f84a5
This commit is contained in:
Chris Lemaire
2025-09-30 11:15:44 +00:00
committed by intellij-monorepo-bot
parent a57f946374
commit f6b64ba65b
4 changed files with 22 additions and 28 deletions
+2
View File
@@ -268,6 +268,7 @@ jvm_library(
"//jvm/jvm-analysis-impl:analysis-impl",
"//plugins/ByteCodeViewer:java-byteCodeViewer",
"//plugins/github/github-json:vcs-github-json",
"//plugins/github/github-tracker:vcs-github-tracker",
"//plugins/search-everywhere-ml/ranking/core",
"//plugins/search-everywhere-ml/ranking/java",
"//plugins/search-everywhere-ml/ranking/vcs",
@@ -548,6 +549,7 @@ jvm_library(
"//jvm/jvm-analysis-impl:analysis-impl",
"//plugins/ByteCodeViewer:java-byteCodeViewer",
"//plugins/github/github-json:vcs-github-json",
"//plugins/github/github-tracker:vcs-github-tracker",
"//plugins/search-everywhere-ml/ranking/core",
"//plugins/search-everywhere-ml/ranking/java",
"//plugins/search-everywhere-ml/ranking/vcs",
+1
View File
@@ -232,6 +232,7 @@
<orderEntry type="module" module-name="intellij.jvm.analysis.impl" scope="RUNTIME" />
<orderEntry type="module" module-name="intellij.java.byteCodeViewer" scope="RUNTIME" />
<orderEntry type="module" module-name="intellij.vcs.github.json" scope="RUNTIME" />
<orderEntry type="module" module-name="intellij.vcs.github.tracker" scope="RUNTIME" />
<orderEntry type="module" module-name="intellij.searchEverywhereMl.ranking.core" scope="RUNTIME" />
<orderEntry type="module" module-name="intellij.searchEverywhereMl.ranking.java" scope="RUNTIME" />
<orderEntry type="module" module-name="intellij.searchEverywhereMl.ranking.vcs" scope="RUNTIME" />
@@ -15,16 +15,14 @@ import com.intellij.tasks.*;
import com.intellij.tasks.impl.BaseRepository;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.xmlb.annotations.Tag;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.VisibleForTesting;
import org.jetbrains.plugins.github.api.GithubApiRequestExecutor;
import org.jetbrains.plugins.github.api.GithubApiRequests;
import org.jetbrains.plugins.github.api.GithubServerPath;
import org.jetbrains.plugins.github.api.data.GithubIssue;
import org.jetbrains.plugins.github.api.data.GithubIssueBase;
import org.jetbrains.plugins.github.api.data.GithubIssueCommentWithHtml;
import org.jetbrains.plugins.github.api.data.GithubIssueLabel;
import org.jetbrains.plugins.github.api.data.GithubIssueState;
import org.jetbrains.plugins.github.api.data.*;
import org.jetbrains.plugins.github.api.util.GithubApiPagesLoader;
import org.jetbrains.plugins.github.exceptions.GithubAuthenticationException;
import org.jetbrains.plugins.github.exceptions.GithubJsonException;
@@ -41,16 +39,17 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Tag("GitHub")
final class GithubRepository extends BaseRepository {
@VisibleForTesting
@ApiStatus.Internal
public final class GithubRepository extends BaseRepository {
private Pattern myPattern = Pattern.compile("($^)");
private @NotNull String myRepoAuthor = "";
private @NotNull String myRepoName = "";
private @NotNull String myUser = "";
private boolean myAssignedIssuesOnly = false;
@SuppressWarnings("UnusedDeclaration")
GithubRepository() {
@VisibleForTesting
public GithubRepository() {
}
GithubRepository(GithubRepository other) {
@@ -157,7 +156,8 @@ final class GithubRepository extends BaseRepository {
return tasks.toArray(Task.EMPTY_ARRAY);
}
private @NotNull Task createTask(@NotNull GithubIssueBase issue, @NotNull List<GithubIssueCommentWithHtml> comments) {
@VisibleForTesting
public @NotNull Task createTask(@NotNull GithubIssueBase issue, @NotNull List<GithubIssueCommentWithHtml> comments) {
return new Task() {
private final @NotNull String myRepoName = getRepoName();
private final Comment @NotNull [] myComments =
@@ -11,15 +11,12 @@ import org.jetbrains.plugins.github.api.data.GithubIssueLabel;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class GithubRepositoryTest {
class GithubRepositoryTest {
private GithubRepository repository;
@BeforeEach
@@ -28,21 +25,21 @@ public class GithubRepositoryTest {
}
@Test
public void testCreateTaskBug() throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
public void testCreateTaskBug() {
GithubIssueBase issue = makeIssueWithLabels(Collections.singletonList("bug"));
Task task = createTask(repository, issue, Collections.emptyList());
assertEquals(TaskType.BUG, task.getType());
}
@Test
public void testCreateTaskFeature() throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
public void testCreateTaskFeature() {
GithubIssueBase issue = makeIssueWithLabels(Collections.singletonList("enhancement"));
Task task = createTask(repository, issue, Collections.emptyList());
assertEquals(TaskType.FEATURE, task.getType());
}
@Test
public void testCreateTaskUnmapped() throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
public void testCreateTaskUnmapped() {
// Test with a label that is not recognized as a specific type
GithubIssueBase issue = makeIssueWithLabels(Collections.singletonList("question"));
Task task = createTask(repository, issue, Collections.emptyList());
@@ -50,7 +47,7 @@ public class GithubRepositoryTest {
}
@Test
public void testCreateTaskMultipleLabelsMatchFirstWins() throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
public void testCreateTaskMultipleLabelsMatchFirstWins() {
GithubIssueBase issue = makeIssueWithLabels(
List.of("bug", "enhancement", "feature", "task", "question") // Multiple labels including bug and enhancement
);
@@ -59,7 +56,7 @@ public class GithubRepositoryTest {
}
@Test
public void testCreateTaskMultipleLabelsSingleMatch() throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
public void testCreateTaskMultipleLabelsSingleMatch() {
GithubIssueBase issue = makeIssueWithLabels(
List.of("custom1", "enhancement", "custom2") // Multiple labels including enhancement in the middle
);
@@ -68,7 +65,7 @@ public class GithubRepositoryTest {
}
@Test
public void testCreateTaskNoLabel() throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
public void testCreateTaskNoLabel() {
GithubIssueBase issue = makeIssueWithLabels(
Collections.emptyList()
);
@@ -114,15 +111,9 @@ public class GithubRepositoryTest {
* @param issue the GithubIssueBase instance
* @param comments the list of comments associated with the issue
* @return a Task object created by the private createTask method
* @throws NoSuchMethodException if the method is not found
* @throws InvocationTargetException if the method invocation fails
* @throws IllegalAccessException if access to the method is denied
*/
private static Task createTask(GithubRepository repo, GithubIssueBase issue, List<GithubIssueCommentWithHtml> comments)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Method createTask = GithubRepository.class.getDeclaredMethod("createTask", GithubIssueBase.class, List.class);
createTask.setAccessible(true);
Task task = (Task) createTask.invoke(repo, issue, comments);
private static Task createTask(GithubRepository repo, GithubIssueBase issue, List<GithubIssueCommentWithHtml> comments) {
Task task = repo.createTask(issue, comments);
return task;
}