Skip to content

Commit

Permalink
fix: division by zero in language stats
Browse files Browse the repository at this point in the history
Signed-off-by: Jos Ahrens <[email protected]>
  • Loading branch information
Zarthus committed Dec 11, 2024
1 parent c3bbe0f commit aa8a8c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions workspaces/copilot/.changeset/six-years-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage-community/plugin-copilot': minor
---

Fix division by zero in language stats
11 changes: 8 additions & 3 deletions workspaces/copilot/plugins/copilot/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
});
Expand Down

0 comments on commit aa8a8c8

Please sign in to comment.