Skip to content

Commit

Permalink
added recursive collection of all members from config yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
garethahealy committed Dec 18, 2024
1 parent c5ace1c commit 07cf2e5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> getConfigMembers(String configContent) throws JsonProcessingException {
List<String> allMembers = new ArrayList<>();
public Set<String> getConfigMembers(String configContent) throws JsonProcessingException {
Set<String> allMembers = new TreeSet<>(Comparator.naturalOrder());

YAMLMapper mapper = new YAMLMapper();
JsonNode configMap = mapper.readValue(configContent, JsonNode.class);
Expand All @@ -226,10 +226,32 @@ public List<String> 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<String> 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<GHUser, String> getContributedTo(GHOrganization org, Set<GHUser> unknown, Set<GHUser> unknownWorksForRH) throws IOException, ExecutionException, InterruptedException {
Map<GHUser, String> contributedTo = new ConcurrentHashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -48,7 +45,7 @@ public List<Members> run(GHRepository orgRepo, String sourceBranch, String ldapM
return Collections.emptyList();
}

List<String> members = gitHubService.getConfigMembers(configContent);
Set<String> members = gitHubService.getConfigMembers(configContent);

List<String> ldapCheck = collectMembersToCheck(members, ldapMembersCsv, supplementaryCsv);
List<Members> usersFoundOrNot = searchViaLdapFor(ldapCheck, failNoVpn);
Expand All @@ -57,7 +54,7 @@ public List<Members> run(GHRepository orgRepo, String sourceBranch, String ldapM
return usersFoundOrNot;
}

private List<String> collectMembersToCheck(List<String> members, String ldapMembersCsv, String supplementaryCsv) throws IOException {
private List<String> collectMembersToCheck(Set<String> members, String ldapMembersCsv, String supplementaryCsv) throws IOException {
List<String> answer = new ArrayList<>();

Map<String, Members> ldapMembers = csvService.getKnownMembers(ldapMembersCsv);
Expand Down

0 comments on commit 07cf2e5

Please sign in to comment.