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

Fix labelling issue for teams #36

Merged
merged 1 commit into from
Feb 1, 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
14 changes: 10 additions & 4 deletions src/main/java/org/keycloak/gh/bot/representations/Teams.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.*;

public class Teams extends HashMap<String, List<String>> {

Expand All @@ -30,7 +28,15 @@ public synchronized static Teams getTeams(URL url) throws IOException {
ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());
teams = yamlMapper.readValue(url, Teams.class);

teams.keySet().removeIf(s -> !s.startsWith("team/"));
Iterator<Entry<String, List<String>>> itr = teams.entrySet().iterator();
while (itr.hasNext()) {
Entry<String, List<String>> e = itr.next();
if (!e.getKey().startsWith("team/")) {
itr.remove();
} else if (e.getValue() == null) {
e.setValue(Collections.EMPTY_LIST);
}
}

lastUpdated = System.currentTimeMillis();
log.infov("Updating teams list from {0}", TEAMS_URL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class AddTeamLabelToIssuesTest {

@Test
public void testTeamAdded() throws IOException {
verifyLabelAdded("area/oidc", "team/core");
verifyLabelAdded("area/admin/client/node", "team/ui");
verifyLabelAdded("area/oidc", "team/core-clients");
verifyLabelAdded("area/admin/client-js", "team/ui");
}

@Test
Expand Down
16 changes: 13 additions & 3 deletions src/test/java/org/keycloak/gh/bot/representations/TeamsTest.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package org.keycloak.gh.bot.representations;

import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

public class TeamsTest {

Expand All @@ -16,15 +20,21 @@ public void resetTeams() {
public void testRemote() throws IOException {
Teams teams = Teams.getTeams();
Assertions.assertFalse(teams.isEmpty());
Assertions.assertFalse(teams.values().iterator().next().isEmpty());
for (Map.Entry<String, List<String>> e : teams.entrySet()) {
Assertions.assertNotNull(e.getValue());
}
}

@Test
public void testNotPrefixedRemoved() throws IOException {
Teams teams = Teams.getTeams(getClass().getResource("teams.yml"));
Assertions.assertFalse(teams.isEmpty());
Assertions.assertEquals(3, teams.size());

Assertions.assertTrue(teams.get("team/empty").isEmpty());
Assertions.assertFalse(teams.containsKey("no-team"));
Assertions.assertTrue(teams.containsKey("team/core-shared"));
MatcherAssert.assertThat(teams.get("team/team-a"), CoreMatchers.hasItems("area/test1"));
MatcherAssert.assertThat(teams.get("team/team-b"), CoreMatchers.hasItems("area/test2"));
Assertions.assertTrue(teams.containsKey("team/team-b"));
}

}
54 changes: 6 additions & 48 deletions src/test/resources/org/keycloak/gh/bot/representations/teams.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,10 @@
team/cloud-native:
- area/admin/cli
- area/dist/quarkus
- area/operator
team/team-a:
- area/test1

team/continuous-testing:
- area/ci
- area/testsuite
team/team-b:
- area/test2

team/core-clients:
- area/adapter/fuse
- area/adapter/java-cli
- area/adapter/jee
- area/adapter/jee-saml
- area/adapter/spring
- area/authentication
- area/authentication/webauthn
- area/login/ui
- area/oidc
- area/oid4vc
- area/saml

team/core-iam:
- area/admin/fine-grained-permissions
- area/authorization-services
- area/identity-brokering
- area/user-profile

team/core-shared:
- area/account/api
- area/admin/api
- area/admin/client-java
- area/core
- area/import-export
- area/infinispan
- area/ldap
- area/storage
- area/token-exchange

team/ui:
- area/account/ui
- area/adapter/javascript
- area/admin/client-js
- area/admin/ui
- area/welcome/ui

team/community:
- area/translations
team/empty:

no-team:
- area/docs
- area/dependencies
- area/test3
Loading