From 07cf2e556aa80fe72df121cc27468f2fde6b878c Mon Sep 17 00:00:00 2001 From: Gareth Healy Date: Wed, 18 Dec 2024 12:38:17 +0000 Subject: [PATCH] added recursive collection of all members from config yaml --- .../githubstats/services/GitHubService.java | 28 +++++++++++++++++-- .../ConfigYamlMemberInRedHatLdapService.java | 9 ++---- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/garethahealy/githubstats/services/GitHubService.java b/src/main/java/com/garethahealy/githubstats/services/GitHubService.java index ed83e9f..e6b9572 100644 --- a/src/main/java/com/garethahealy/githubstats/services/GitHubService.java +++ b/src/main/java/com/garethahealy/githubstats/services/GitHubService.java @@ -209,8 +209,8 @@ public JsonNode getArchivedRepos(String configContent) throws JsonProcessingExce return configMap.get("orgs").get("redhat-cop").get("teams").get("aarchived").get("repos"); } - public List getConfigMembers(String configContent) throws JsonProcessingException { - List allMembers = new ArrayList<>(); + public Set getConfigMembers(String configContent) throws JsonProcessingException { + Set allMembers = new TreeSet<>(Comparator.naturalOrder()); YAMLMapper mapper = new YAMLMapper(); JsonNode configMap = mapper.readValue(configContent, JsonNode.class); @@ -226,10 +226,32 @@ public List getConfigMembers(String configContent) throws JsonProcessing allMembers.add(current.asText()); } - Collections.sort(allMembers); + recursiveGetConfigMembers(allMembers, configMap.get("orgs").get("redhat-cop")); + return allMembers; } + private void recursiveGetConfigMembers(Set allMembers, JsonNode parent) { + for (JsonNode child : parent) { + JsonNode maintainers = child.get("maintainers"); + JsonNode members = child.get("members"); + + if (maintainers != null) { + for (JsonNode current : maintainers) { + allMembers.add(current.asText()); + } + } + + if (members != null) { + for (JsonNode current : members) { + allMembers.add(current.asText()); + } + } + + recursiveGetConfigMembers(allMembers, child); + } + } + public Map getContributedTo(GHOrganization org, Set unknown, Set unknownWorksForRH) throws IOException, ExecutionException, InterruptedException { Map contributedTo = new ConcurrentHashMap<>(); diff --git a/src/main/java/com/garethahealy/githubstats/services/users/ConfigYamlMemberInRedHatLdapService.java b/src/main/java/com/garethahealy/githubstats/services/users/ConfigYamlMemberInRedHatLdapService.java index 1ab8ae4..eb9da64 100644 --- a/src/main/java/com/garethahealy/githubstats/services/users/ConfigYamlMemberInRedHatLdapService.java +++ b/src/main/java/com/garethahealy/githubstats/services/users/ConfigYamlMemberInRedHatLdapService.java @@ -13,10 +13,7 @@ import org.kohsuke.github.GHRepository; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import java.util.*; @ApplicationScoped public class ConfigYamlMemberInRedHatLdapService { @@ -48,7 +45,7 @@ public List run(GHRepository orgRepo, String sourceBranch, String ldapM return Collections.emptyList(); } - List members = gitHubService.getConfigMembers(configContent); + Set members = gitHubService.getConfigMembers(configContent); List ldapCheck = collectMembersToCheck(members, ldapMembersCsv, supplementaryCsv); List usersFoundOrNot = searchViaLdapFor(ldapCheck, failNoVpn); @@ -57,7 +54,7 @@ public List run(GHRepository orgRepo, String sourceBranch, String ldapM return usersFoundOrNot; } - private List collectMembersToCheck(List members, String ldapMembersCsv, String supplementaryCsv) throws IOException { + private List collectMembersToCheck(Set members, String ldapMembersCsv, String supplementaryCsv) throws IOException { List answer = new ArrayList<>(); Map ldapMembers = csvService.getKnownMembers(ldapMembersCsv);