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

MARP-1294 Enhance performance for central monitoring reporting #259

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0015c30
Implement
ndkhanh-axonivy Dec 4, 2024
bd5b0b0
Add tests and refactor code UI
ndkhanh-axonivy Dec 4, 2024
d5d107f
Implement Test for BE
ndkhanh-axonivy Dec 4, 2024
fb068b0
Handle feedbacks
ndkhanh-axonivy Dec 6, 2024
c03eb6e
Handle feedbacks
ndkhanh-axonivy Dec 6, 2024
d5a2306
Handle feedbacks
ndkhanh-axonivy Dec 10, 2024
6cab5cd
Handle feedbacks
ndkhanh-axonivy Dec 10, 2024
d37e64b
Update GitHubUtilsTest.java
ndkhanh-axonivy Dec 10, 2024
ff89fb9
Fix sonar issues
ndkhanh-axonivy Dec 10, 2024
97be794
Fix sonars
ndkhanh-axonivy Dec 10, 2024
8c61d56
Sonar fixes
ndkhanh-axonivy Dec 10, 2024
98cf424
Update security-monitor.component.ts
ndkhanh-axonivy Dec 10, 2024
b7e4f6f
Update test UI
ndkhanh-axonivy Dec 10, 2024
259ce0a
Handle feedbacks
ndkhanh-axonivy Dec 15, 2024
2e834b1
Merge branch 'develop' into feature/MARP-1294-Create-a-central-monito…
ndkhanh-axonivy Dec 15, 2024
f0f0caf
Fix sonar issues
ndkhanh-axonivy Dec 16, 2024
564de97
Fix UI sonar issues
ndkhanh-axonivy Dec 16, 2024
4668ce1
Fix sonar UI
ndkhanh-axonivy Dec 16, 2024
0fa0987
Update security-monitor.component.ts
ndkhanh-axonivy Dec 16, 2024
ebfff4f
Update security-monitor.component.ts
ndkhanh-axonivy Dec 16, 2024
c2b4431
Handle feedbacks
ndkhanh-axonivy Dec 16, 2024
af3ae9c
Update security-monitor.component.ts
ndkhanh-axonivy Dec 17, 2024
cd4f397
Update security-monitor.component.spec.ts
ndkhanh-axonivy Dec 17, 2024
90a1f61
Update security-monitor.component.ts
ndkhanh-axonivy Dec 17, 2024
eeb6abb
Update security-monitor.component.spec.ts
ndkhanh-axonivy Dec 17, 2024
cfe9240
Update security-monitor.component.ts
ndkhanh-axonivy Dec 17, 2024
3e5af14
Merge branch 'develop' into feature/MARP-1294-Create-a-central-monito…
ndkhanh-axonivy Dec 18, 2024
a8c8d52
Enhance performance of security-monitor
ndkhanh-axonivy Dec 18, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -173,11 +172,13 @@ public List<ProductSecurityInfo> getSecurityDetailsForAllProducts(String accessT
GitHub gitHub = getGitHub(accessToken);
GHOrganization organization = gitHub.getOrganization(orgName);

return organization.listRepositories().toList().stream()
.map(repo -> CompletableFuture.supplyAsync(() -> fetchSecurityInfoSafe(repo, organization, accessToken), taskScheduler.getScheduledExecutor()))
.map(CompletableFuture::join)
.sorted(Comparator.comparing(ProductSecurityInfo::getRepoName))
.collect(Collectors.toList());
List<CompletableFuture<ProductSecurityInfo>> futures = organization.listRepositories().toList().stream()
.map(repo -> CompletableFuture.supplyAsync(() -> fetchSecurityInfoSafe(repo, organization, accessToken),
taskScheduler.getScheduledExecutor())).toList();

return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]))
.thenApply(v -> futures.stream().map(CompletableFuture::join).sorted(
Comparator.comparing(ProductSecurityInfo::getRepoName)).collect(Collectors.toList())).join();
} catch (IOException e) {
log.error(e.getStackTrace());
return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class GitHubServiceImplTest {
private GitHubAccessTokenResponse gitHubAccessTokenResponse;

@Mock
private GHTeam team1;
private GHTeam ghTeam;

@Spy
@InjectMocks
Expand Down Expand Up @@ -281,7 +281,7 @@ void testIsUserInOrganizationAndTeam_TeamNotFound() throws IOException {
String organization = "my-org";
String teamName = "my-team";
Set<GHTeam> teams = new HashSet<>();
teams.add(team1);
teams.add(ghTeam);
Map<String, Set<GHTeam>> hashMapTeams = new HashMap<>();
hashMapTeams.put(organization, teams);
when(gitHub.getMyTeams()).thenReturn(hashMapTeams);
Expand All @@ -296,8 +296,8 @@ void testIsUserInOrganizationAndTeam_TeamFound() throws IOException {
String organization = "my-org";
String teamName = "my-team";
Set<GHTeam> teams = new HashSet<>();
when(team1.getName()).thenReturn(teamName);
teams.add(team1);
when(ghTeam.getName()).thenReturn(teamName);
teams.add(ghTeam);
Map<String, Set<GHTeam>> hashMapTeams = new HashMap<>();
hashMapTeams.put(organization, teams);
when(gitHub.getMyTeams()).thenReturn(hashMapTeams);
Expand Down Expand Up @@ -511,4 +511,17 @@ void testGetDependabotAlerts_Disabled() {
Dependabot result = gitHubService.getDependabotAlerts(ghRepository, ghOrganization, accessToken);
assertEquals(AccessLevel.DISABLED, result.getStatus());
}

@Test
void testGetSecurityDetailsForAllProducts() throws Exception {
String accessToken = "mockAccessToken";
String orgName = "mockOrganization";
GHOrganization ghOrganization = mock(GHOrganization.class);
when(gitHubService.getGitHub(accessToken)).thenReturn(gitHub);
when(gitHub.getOrganization(orgName)).thenReturn(ghOrganization);
PagedIterable<GHRepository> mockPagedIterable = mock(PagedIterable.class);
when(ghOrganization.listRepositories()).thenReturn(mockPagedIterable);
List<ProductSecurityInfo> result = gitHubService.getSecurityDetailsForAllProducts(accessToken, orgName);
assertEquals(0, result.size());
}
}
Loading