Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require only partial intersection between components #74

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/java/org/jboss/set/draw/entities/Participant.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.smallrye.mutiny.tuples.Tuple2;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -53,8 +54,9 @@ private Tuple2<Integer, Set<String>> getProjectComponents(String project) {

public boolean isAssignable(Issue issue) {
Tuple2<Integer, Set<String>> issuesComponentsKey = getProjectComponents(issue.getProject());
List<String> components = issue.getComponents();
boolean betweenComponents = issuesComponentsKey.getItem2() == null ||
issuesComponentsKey.getItem2().containsAll(issue.getComponents());
!issuesComponentsKey.getItem2().stream().filter(components::contains).toList().isEmpty();
boolean canAssignIssue = assignableIssues == null || assignableIssues > 0;
return issuesComponentsKey.getItem1() != 0 && betweenComponents && canAssignIssue;
}
Expand Down
86 changes: 85 additions & 1 deletion src/test/java/org/jboss/set/draw/LotteryDrawingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected List<com.atlassian.jira.rest.client.api.domain.Issue> setupIssues() {
new IssueWrapper("Issue", 1L, "WFLY", IssueStatus.NEW, Set.of("Documentation")),
new IssueWrapper("Issue", 2L, "RESTEASY", IssueStatus.NEW, Set.of("Logging")),
new IssueWrapper("Issue", 3L, "WELD", IssueStatus.NEW, Set.of("Logging")),
new IssueWrapper("Issue", 4L, "WELD", IssueStatus.NEW, Set.of("Logging")));
new IssueWrapper("Issue", 4L, "WELD", IssueStatus.NEW, Set.of("Logging", "Documentation")));
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -279,4 +279,88 @@ public void testAssigningMaximumIssues() throws Exception {
assertEquals(1, sent.size());
assertEquals(Lottery.createEmailText(email, List.of(ourIssues.get(2))), sent.get(0).getText());
}

@Test
public void testAssigningPartialComponentsHitFromConfig() throws Exception {
String email = "[email protected]";
String configFile = """
delay: P14D
participants:
- email: %s
maxIssues: 5
projects:
- project: WELD
components: [Logging]
maxIssues: 2""".formatted(email);

LotteryConfig testLotteryConfig = objectMapper.readValue(configFile, LotteryConfig.class);
when(lotteryConfigProducer.getLotteryConfig()).thenReturn(testLotteryConfig);

StringWriter sw = new StringWriter();
CommandLine cmd = new CommandLine(app);
cmd.setOut(new PrintWriter(sw));

int exitCode = cmd.execute();
assertEquals(0, exitCode);

List<Mail> sent = mailbox.getMailsSentTo(email);
assertEquals(1, sent.size());
assertEquals(Lottery.createEmailText(email, List.of(ourIssues.get(2), ourIssues.get(3))), sent.get(0).getText());
}

@Test
public void testAssigningPartialComponentsHitFromIssue() throws Exception {
String email = "[email protected]";
String configFile = """
delay: P14D
participants:
- email: %s
maxIssues: 5
projects:
- project: WELD
components: [Logging, Documentation]
maxIssues: 2""".formatted(email);

LotteryConfig testLotteryConfig = objectMapper.readValue(configFile, LotteryConfig.class);
when(lotteryConfigProducer.getLotteryConfig()).thenReturn(testLotteryConfig);

StringWriter sw = new StringWriter();
CommandLine cmd = new CommandLine(app);
cmd.setOut(new PrintWriter(sw));

int exitCode = cmd.execute();
assertEquals(0, exitCode);

List<Mail> sent = mailbox.getMailsSentTo(email);
assertEquals(1, sent.size());
assertEquals(Lottery.createEmailText(email, List.of(ourIssues.get(2), ourIssues.get(3))), sent.get(0).getText());
}

@Test
public void testAssigningWithNoPartialComponentsHit() throws Exception {
String email = "[email protected]";
String configFile = """
delay: P14D
participants:
- email: %s
maxIssues: 5
projects:
- project: WELD
components: [Documentation]
maxIssues: 2""".formatted(email);

LotteryConfig testLotteryConfig = objectMapper.readValue(configFile, LotteryConfig.class);
when(lotteryConfigProducer.getLotteryConfig()).thenReturn(testLotteryConfig);

StringWriter sw = new StringWriter();
CommandLine cmd = new CommandLine(app);
cmd.setOut(new PrintWriter(sw));

int exitCode = cmd.execute();
assertEquals(0, exitCode);

List<Mail> sent = mailbox.getMailsSentTo(email);
assertEquals(1, sent.size());
assertEquals(Lottery.createEmailText(email, List.of(ourIssues.get(3))), sent.get(0).getText());
}
}
Loading