Skip to content
Open
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
60 changes: 60 additions & 0 deletions src/components/RadialGauge.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React from 'react'

export default function RadialGauge({ score, size = 80, strokeWidth = 7 }) {
const center = size / 2
const radius = center - strokeWidth
const circumference = 2 * Math.PI * radius

const validScore = typeof score === 'number' && !isNaN(score) ? Math.min(100, Math.max(0, score)) : null
const offset = validScore !== null ? circumference - (validScore / 100) * circumference : circumference

let color = 'var(--text3)'
let bgStroke = 'var(--border)'

if (validScore !== null) {
if (validScore >= 70) color = 'var(--green, #22c55e)'
else if (validScore >= 40) color = 'var(--amber, #f59e0b)'
else color = 'var(--red, #ef4444)'
}

return (
<div style={{ position: 'relative', width: size, height: size, display: 'inline-flex', alignItems: 'center', justifyContent: 'center' }}>
<svg width={size} height={size} aria-hidden="true" focusable="false" style={{ transform: 'rotate(-90deg)' }}>
{/* Background track */}
<circle
cx={center}
cy={center}
r={radius}
fill="none"
stroke={bgStroke}
strokeWidth={strokeWidth}
/>
{/* Foreground progress */}
{validScore !== null && (
<circle
cx={center}
cy={center}
r={radius}
fill="none"
stroke={color}
strokeWidth={strokeWidth}
strokeDasharray={circumference}
strokeDashoffset={offset}
strokeLinecap="round"
style={{ transition: 'stroke-dashoffset 0.6s ease-out' }}
/>
)}
</svg>
<div style={{ position: 'absolute', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center' }}>
<span style={{ fontSize: size * 0.28, fontWeight: 700, color: validScore !== null ? color : 'var(--text2)', lineHeight: 1 }}>
{validScore !== null ? validScore : 'N/A'}
</span>
{validScore !== null && (
<span style={{ fontSize: size * 0.13, color: 'var(--text3)', marginTop: 2, fontWeight: 500 }}>
/ 100
</span>
)}
</div>
</div>
)
}
44 changes: 35 additions & 9 deletions src/context/AppContext.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createContext, useContext, useState, useCallback, useEffect, useMemo, useRef } from 'react'
import { fetchOrg, fetchRepos, fetchContributors, fetchIssues, fetchRateLimit, fetchPulls } from '../services/github'
import { buildAnalyticalModel, getTopRepositories } from '../services/analytics'
import { buildAnalyticalModel, getTopRepositories, computeRepoHealthScore } from '../services/analytics'
import { saveAnalysis, loadAnalysis } from '../services/cache'

const Ctx = createContext(null)
Expand Down Expand Up @@ -377,15 +377,41 @@ export function AppProvider({ children }) {
}).sort((a, b) => b.ratio - a.ratio)
}, [issuesData])

const repoScorecards = useMemo(() => {
if (!model || !model.totalRepos) return []
return model.totalRepos
.map(repo => {
const key = `${repo.orgLogin}/${repo.name}`
const issues = issuesData[key] || []
const pulls = pullsData[key] || []
return computeRepoHealthScore(repo, issues, pulls)
})
.sort((a, b) => {
if (a.overallScore === null && b.overallScore === null) return 0
if (a.overallScore === null) return 1
if (b.overallScore === null) return -1
return a.overallScore - b.overallScore
})
}, [model, issuesData, pullsData])

const ctxValue = useMemo(() => ({
pat, savePat, orgs, model, issuesData, pullsData,
rateLimit, loading, loadMsg, govLoading, error, totalRepo,
runAdvanceAnalytics, refreshRateLimit, advanceAnalyticsLoading, advanceAnalyticsComplete,
runFullAnalytics,
isComplete, auditComplete, lastOrgNames, hydrating,
explore, runFullExplore, runAudit, runGovernanceAnalysis, setError, staleRepoStats, repoScorecards
}), [
pat, savePat, orgs, model, issuesData, pullsData,
rateLimit, loading, loadMsg, govLoading, error, totalRepo,
runAdvanceAnalytics, refreshRateLimit, advanceAnalyticsLoading, advanceAnalyticsComplete,
runFullAnalytics,
isComplete, auditComplete, lastOrgNames, hydrating,
explore, runFullExplore, runAudit, runGovernanceAnalysis, setError, staleRepoStats, repoScorecards
])

return (
<Ctx.Provider value={{
pat, savePat, orgs, model, issuesData, pullsData,
rateLimit, loading, loadMsg, govLoading, error, totalRepo,
runAdvanceAnalytics, refreshRateLimit, advanceAnalyticsLoading, advanceAnalyticsComplete,
runFullAnalytics,
isComplete, auditComplete, lastOrgNames, hydrating,
explore, runFullExplore, runAudit, runGovernanceAnalysis, setError, staleRepoStats
}}>
<Ctx.Provider value={ctxValue}>
{children}
</Ctx.Provider>
)
Expand Down
Loading
Loading