Skip to content

Commit

Permalink
Add unique github id check
Browse files Browse the repository at this point in the history
Signed-off-by: Brandon Shien <[email protected]>
  • Loading branch information
bshien committed Nov 4, 2024
1 parent 91099eb commit f8967e2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ public List<MaintainerData> repoMaintainers(String repo) {
String rawMaintainersFile = String.format("https://raw.githubusercontent.com/opensearch-project/%s/main/MAINTAINERS.md", repo);
boolean isEmeritusSection = false;
List<MaintainerData> maintainersList = new ArrayList<>();
Set<String> maintainerIdSet = new HashSet<>();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(rawMaintainersFile).openStream(),
StandardCharsets.UTF_8))) {
String line;
Expand All @@ -256,7 +257,10 @@ public List<MaintainerData> repoMaintainers(String repo) {
maintainerData.setName(maintainer);
maintainerData.setGithubLogin(githubId);
maintainerData.setAffiliation(affiliation);
maintainersList.add(maintainerData);
if(!maintainerIdSet.contains(githubId)){ // Add only unique github ids
maintainerIdSet.add(githubId);
maintainersList.add(maintainerData);
}
}
}
} else if (line.contains("Emeritus")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,37 @@ public void testRepoMaintainers() {
}
}

@Test
public void testRepoMaintainersDuplicateId() {
MaintainerMetrics maintainerMetrics = new MaintainerMetrics();
String expectedContent = "test content\n" +
"| Maintainer | GitHub ID | Affiliation |\n" +
"| maintainer | [githubId](https://github.com/githubId) | affiliation |\n" +
"| maintainer | [githubId](https://github.com/githubId) | affiliation |\n" +
"## Emeritus Maintainers" +
"| maintainer | [githubId](https://github.com/githubId) | affiliation |\n" +
"line3\n";
ByteArrayInputStream inputStream = new ByteArrayInputStream(
expectedContent.getBytes(StandardCharsets.UTF_8)
);

try (MockedConstruction<URL> mocked = mockConstruction(URL.class, (mockUrl, context) ->
when(mockUrl.openStream()).thenReturn(inputStream))) {

List<MaintainerData> maintainerDataList = maintainerMetrics.repoMaintainers("repo");

List<MaintainerData> expectedList = new ArrayList<>();
MaintainerData expectedMaintainer = new MaintainerData();
expectedMaintainer.setRepository("repo");
expectedMaintainer.setName("maintainer");
expectedMaintainer.setGithubLogin("githubId");
expectedMaintainer.setAffiliation("affiliation");
expectedList.add(expectedMaintainer);

assertEquals(expectedList, maintainerDataList);
}
}

@Test
public void testRepoMaintainersFileNotFound() {
MaintainerMetrics maintainerMetrics = new MaintainerMetrics();
Expand Down

0 comments on commit f8967e2

Please sign in to comment.