From 0818069df0b676e109c99acc4ca4971312b59f64 Mon Sep 17 00:00:00 2001 From: MahtabBukhari Date: Fri, 6 Dec 2024 23:23:05 +0500 Subject: [PATCH 1/2] fix(generate-analyze): replace generate tests with analyze test coverage in repository node --- .../Universe/Graph/UI/NodeControls/index.tsx | 23 +++++++++++++++++-- src/network/fetchSourcesData/index.ts | 12 ++++++++++ src/stores/useDataStore/index.ts | 22 ++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/components/Universe/Graph/UI/NodeControls/index.tsx b/src/components/Universe/Graph/UI/NodeControls/index.tsx index 7b3fc5cb2..8a90fe088 100644 --- a/src/components/Universe/Graph/UI/NodeControls/index.tsx +++ b/src/components/Universe/Graph/UI/NodeControls/index.tsx @@ -24,6 +24,7 @@ import { useUserStore } from '~/stores/useUserStore' import { NodeExtended } from '~/types' import { colors } from '~/utils/colors' import { buttonColors } from './constants' +import { analyzeGitHubRepository } from '~/network/fetchSourcesData' const reuseableVector3 = new Vector3() @@ -38,7 +39,7 @@ export const NodeControls = memo(() => { const { open: createBountyModal } = useModal('createBounty') const [isAdmin] = useUserStore((s) => [s.isAdmin]) - const [addNewNode] = useDataStore((s) => [s.addNewNode]) + const { addNewNode, setGraph } = useDataStore((s) => s) const selectedNode = useSelectedNode() @@ -163,6 +164,20 @@ export const NodeControls = memo(() => { setAnchorEl(null) } + const handleAnalyzeTestCoverage = async (githubName: string) => { + try { + const res = await analyzeGitHubRepository(githubName) + + if (res) { + setSelectedNode(null) + + setGraph({ nodes: res.functions }) + } + } catch (error) { + console.error('Error during test coverage analysis:', error) + } + } + const open = Boolean(anchorEl) const id = open ? 'simple-popover' : undefined @@ -248,13 +263,17 @@ export const NodeControls = memo(() => { { + if (selectedNode?.name) { + handleAnalyzeTestCoverage(selectedNode.name) + } + handleClose() }} > - Generate Tests + Analyze Test Coverage => { + const url = `/github/analyze?github_repository=${github_repository}&analysis=["coverage"]` + + const response = await api.get(url) + + return response +} + export const getNodes = async (): Promise => { const url = `/prediction/graph/search?node_type=['Episode']&include_properties=true&includeContent=true&sort_by=date` diff --git a/src/stores/useDataStore/index.ts b/src/stores/useDataStore/index.ts index 866291d1c..9d23ee3fb 100644 --- a/src/stores/useDataStore/index.ts +++ b/src/stores/useDataStore/index.ts @@ -88,6 +88,7 @@ export type DataStore = { abortFetchData: () => void resetGraph: () => void resetData: () => void + setGraph: (graph: { nodes: NodeExtended[] }) => void } const defaultData: Omit< @@ -119,6 +120,7 @@ const defaultData: Omit< | 'abortFetchData' | 'resetGraph' | 'resetData' + | 'setGraph' > = { categoryFilter: null, dataInitial: null, @@ -320,6 +322,26 @@ export const useDataStore = create()( }) }, + setGraph: (data: { nodes: NodeExtended[] }) => { + const uniqueNodes = deduplicateByRefId(data.nodes) + + const nodeTypes = [...new Set(uniqueNodes.map((node) => node.node_type))] + const sidebarFilters = ['all', ...nodeTypes.map((type) => type.toLowerCase())] + + const sidebarFilterCounts = sidebarFilters.map((filter) => ({ + name: filter, + count: uniqueNodes.filter((node) => filter === 'all' || node.node_type?.toLowerCase() === filter).length, + })) + + set({ + dataInitial: { nodes: uniqueNodes, links: [] }, + dataNew: { nodes: uniqueNodes, links: [] }, + nodeTypes, + sidebarFilters, + sidebarFilterCounts, + }) + }, + nextPage: () => { const { filters, fetchData, setAbortRequests } = get() const { setBudget } = useUserStore.getState() From 83ddcec55bd483e8cca79ff2c3589ffa083b359c Mon Sep 17 00:00:00 2001 From: MahtabBukhari Date: Fri, 6 Dec 2024 23:43:48 +0500 Subject: [PATCH 2/2] fix(generate-analyze): replace generate tests with analyze test coverage in repository --- src/network/fetchSourcesData/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/network/fetchSourcesData/index.ts b/src/network/fetchSourcesData/index.ts index c0d8f6a7b..b61746ccb 100644 --- a/src/network/fetchSourcesData/index.ts +++ b/src/network/fetchSourcesData/index.ts @@ -187,9 +187,9 @@ type GithubRepositoryResponse = { export const analyzeGitHubRepository = async (github_repository: string): Promise => { const url = `/github/analyze?github_repository=${github_repository}&analysis=["coverage"]` - const response = await api.get(url) + const res = await api.get(url) - return response + return res } export const getNodes = async (): Promise => {