Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 8 additions & 1 deletion src/services/analytics.healthMetrics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,15 @@ describe('computeBusFactor', () => {
})

it('supports model contributor objects using totalContribs', () => {
const contributors = [{ totalContribs: 60 }, { totalContribs: 40 }]
const contributors = [
{ login: 'alice', totalContribs: 60 },
{ login: 'bob', totalContribs: 40 }
]
expect(computeBusFactor(contributors)).toEqual({ factor: 1, risk: 'critical' })
})

it('supports primitive numbers array', () => {
expect(computeBusFactor([60, 40])).toEqual({ factor: 1, risk: 'critical' })
})
})

2 changes: 1 addition & 1 deletion src/services/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function computeActivityClassification(repo) {
// Bus Factor
export function computeBusFactor(contributors = []) {
if (!contributors.length) return { factor: 0, risk: 'unknown' }
const getCount = c => c.contributions ?? c.totalContribs ?? 0
const getCount = c => (typeof c === 'number' ? c : (c.contributions ?? c.totalContribs ?? 0))
const total = contributors.reduce((s, c) => s + getCount(c), 0)
if (!total) return { factor: 0, risk: 'unknown' }
let cum = 0
Expand Down
Loading