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

Filter values for teams without team prefix #35

Merged
merged 1 commit into from
Jan 31, 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
15 changes: 14 additions & 1 deletion src/main/java/org/keycloak/gh/bot/representations/Teams.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

public class Teams extends HashMap<String, List<String>> {
Expand All @@ -21,15 +22,27 @@ public class Teams extends HashMap<String, List<String>> {
private static final Logger log = Logger.getLogger(Teams.class);

public synchronized static Teams getTeams() throws IOException {
return getTeams(new URL(TEAMS_URL));
}

public synchronized static Teams getTeams(URL url) throws IOException {
if (teams == null || lastUpdated + EXPIRATION < System.currentTimeMillis()) {
ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());
teams = yamlMapper.readValue(new URL(TEAMS_URL), Teams.class);
teams = yamlMapper.readValue(url, Teams.class);

teams.keySet().removeIf(s -> !s.startsWith("team/"));

lastUpdated = System.currentTimeMillis();
log.infov("Updating teams list from {0}", TEAMS_URL);
}
return teams;
}

public synchronized static void clearInstance() {
teams = null;
lastUpdated = 0;
}

public Teams() {
}

Expand Down
30 changes: 30 additions & 0 deletions src/test/java/org/keycloak/gh/bot/representations/TeamsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.keycloak.gh.bot.representations;

import org.junit.jupiter.api.*;

import java.io.IOException;

public class TeamsTest {

@BeforeEach
@AfterEach
public void resetTeams() {
Teams.clearInstance();
}

@Test
public void testRemote() throws IOException {
Teams teams = Teams.getTeams();
Assertions.assertFalse(teams.isEmpty());
Assertions.assertFalse(teams.values().iterator().next().isEmpty());
}

@Test
public void testNotPrefixedRemoved() throws IOException {
Teams teams = Teams.getTeams(getClass().getResource("teams.yml"));
Assertions.assertFalse(teams.isEmpty());
Assertions.assertFalse(teams.containsKey("no-team"));
Assertions.assertTrue(teams.containsKey("team/core-shared"));
}

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

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

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

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