diff --git a/workspaces/copilot/.changeset/six-years-serve.md b/workspaces/copilot/.changeset/six-years-serve.md new file mode 100644 index 0000000000..4a0a3e1952 --- /dev/null +++ b/workspaces/copilot/.changeset/six-years-serve.md @@ -0,0 +1,5 @@ +--- +'@backstage-community/plugin-copilot': minor +--- + +Fix division by zero in language stats diff --git a/workspaces/copilot/plugins/copilot/src/utils/index.ts b/workspaces/copilot/plugins/copilot/src/utils/index.ts index 8520b5ea61..3e3b10089f 100644 --- a/workspaces/copilot/plugins/copilot/src/utils/index.ts +++ b/workspaces/copilot/plugins/copilot/src/utils/index.ts @@ -45,14 +45,19 @@ export function getLanguageStats(metricsArray: Metric[]): LanguageStats[] { if (existingStats) { existingStats.totalSuggestions += item.suggestions_count; existingStats.totalAcceptances += item.acceptances_count; - existingStats.acceptanceRate = - existingStats.totalAcceptances / existingStats.totalSuggestions; + if (existingStats.totalSuggestions > 0) { + existingStats.acceptanceRate = + existingStats.totalAcceptances / existingStats.totalSuggestions; + } } else { languageStatsMap.set(item.language, { language: item.language, totalSuggestions: item.suggestions_count, totalAcceptances: item.acceptances_count, - acceptanceRate: item.acceptances_count / item.suggestions_count, + acceptanceRate: + item.suggestions_count > 0 + ? item.acceptances_count / item.suggestions_count + : 0, }); } });