Skip to content

Commit

Permalink
Filter values for teams without team prefix
Browse files Browse the repository at this point in the history
Signed-off-by: stianst <stianst@gmail.com>
  • Loading branch information
stianst committed Jan 31, 2024
1 parent 7d0be29 commit cd750dd
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 1 deletion.
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public void testTeamAdded() throws IOException {
verifyLabelAdded("area/admin/client/node", "team/ui");
}

@Test
public void testTeamNotAddedForNoTeam() throws IOException {
verifyLabelAdded("area/docs", null);
}

@Test
public void notAnArea() throws IOException {
verifyLabelAdded("kind/bug", null);
Expand Down
27 changes: 27 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,27 @@
package org.keycloak.gh.bot.representations;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.IOException;

public class TeamsTest {

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

@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"));
Teams.clearInstance();
}

}
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

0 comments on commit cd750dd

Please sign in to comment.