[BUG]: Average PR Merge Time is underestimated when a merged PR has an invalid or negative duration
I maintainer di solito rispondono entro 4 giorni
@g-k-s-03 ci sta già lavorando.
Dal 21/10/2026.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 84/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- javascript, react
Direzione di ricerca
Leggi src/hooks/useSortedData.js, concentrandoti su useAdvancedMetrics e sul calcolo di avgMergeHours. Aggiungi o adatta un test unitario con una durata di PR unita valida e una non valida, quindi eseguilo con npx vitest run. Il lavoro è completato quando la media considera solo le PR con durate valide e non negative, mentre il conteggio delle PR unite visualizzato rimane invariato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Bug Description
Summary
The "Average PR Merge Time" on the Analytics page is underestimated whenever one or more merged pull requests have a duration that cannot be computed.
Root cause
In src/hooks/useSortedData.js, useAdvancedMetrics skips merged PRs with an invalid duration when summing merge times, but still counts them when dividing:
const totalMergeTime = mergedPRs.reduce((sum, pr) => {
const duration = new Date(pr.merged_at).getTime() - new Date(pr.created_at).getTime()
return Number.isFinite(duration) && duration >= 0 ? sum + duration : sum
}, 0)
const avgMergeHours =
mergedPRs.length === 0
? 0
: (totalMergeTime / mergedPRs.length / (1000 * 60 * 60)) || 0
A duration is treated as invalid when either timestamp cannot be parsed, or when merged_at is earlier than created_at. These PRs contribute nothing to totalMergeTime, but they are still included in mergedPRs.length. As a result, the total is divided by more PRs than it was calculated from, and the average is lower than the actual value.
Impact
- The Analytics page shows a lower average merge time than the real value.
- The merge-time gauge and its status label (e.g. "Fast" / "Slow") can be misleading.
- Because the result is a plausible number rather than an error, the inaccuracy is easy to miss.
This only occurs when the PR data contains invalid or inconsistent timestamps.
Proposed fix
Track how many PRs actually contribute a valid duration, and divide totalMergeTime by that count instead of mergedPRs.length. The "Merged" count displayed in the UI does not need to change.
I'd be happy to work on this if that's okay.
Steps to Reproduce
The issue can be reproduced with a unit test against the current main branch:
import { renderHook } from '@testing-library/react'
import { useAdvancedMetrics } from './useSortedData'
it('averages only PRs with a valid duration', () => {
const pulls = [
{ state: 'closed', created_at: '2024-01-01T00:00:00Z', merged_at: '2024-01-01T10:00:00Z' }, // 10 hours
{ state: 'closed', created_at: '2024-01-02T00:00:00Z', merged_at: 'not-a-date' }, // invalid
]
const { result } = renderHook(() => useAdvancedMetrics(pulls))
expect(result.current.avgMergeHours).toBe(10)
})
Result:
AssertionError: expected 5 to be 10
Only one PR has a valid duration (10 hours), but the total is divided by two merged PRs, giving 5 hours. The same occurs when merged_at is earlier than created_at.
Expected: the average is calculated only from PRs with a valid duration (10 hours).
Actual: PRs with an invalid duration are included in the divisor, so the average is underestimated (5 hours).
Logs and Screenshots
Test output from npx vitest run:
FAIL src/hooks/mergeTime.check.test.js > avgMergeHours with an invalid merged PR > should average only PRs with a usable duration
AssertionError: expected 5 to be 10 // Object.is equality
- Expected
+ Received
- 10
+ 5
Environment Details
- Branch: upstream
main(as of 21 October 2026) - Reproduced with:
npx vitest run - File:
src/hooks/useSortedData.js(useAdvancedMetrics)
Impact
Critical - Application is unusable
Code of Conduct
- I have joined the Discord server and will post updates there
- I have searched existing issues to avoid duplicates
- Lingua principale
- JavaScript
- Stelle
- 45
- Fork
- 148
- Merge medio
- 5g 14h
- PR unite (30g)
- 30
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di AOSSIE-Org/OrgExplorer
-
[BUG]: Overview "Language Distribution" percentages are relative to the top-7 languages, not all reposForse già presa @Rohit270406 l’ha presa 2 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
AOSSIE-Org/OrgExplorer#402 · 1 commento ·
I maintainer di solito rispondono entro 4 giorni
-
[BUG]: "Delete" PAT button is gated on the input field, so a saved token can't be removed when the field is emptyForse già presa @riyanshbhosale l’ha presa 1 giorno fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
AOSSIE-Org/OrgExplorer#401 · 1 commento ·
I maintainer di solito rispondono entro 4 giorni
-
[BUG]: Overview wrongly lists a successfully-loaded org as "could not be loaded" (case / duplicate)Forse già presa @dhruvbit l’ha presa 2 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
AOSSIE-Org/OrgExplorer#400 · 1 commento ·
I maintainer di solito rispondono entro 4 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
AOSSIE-Org/OrgExplorer#399 · 1 commento ·
I maintainer di solito rispondono entro 4 giorni
-
[BUG]: Governance "Issue Resolution Rate" counts pull requests as issuesForse già presa @amangupta-12 l’ha presa 1 giorno fa. Apertabug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
AOSSIE-Org/OrgExplorer#398 · 1 commento ·
I maintainer di solito rispondono entro 4 giorni
Tutte le issue di AOSSIE-Org/OrgExplorer
Issue simili
-
bug require-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
expressjs/expressjs.com#2549 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
vercel-labs/agent-skills#348 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
NanmiCoder/dsh-agent-teams#289 ·
I maintainer di solito rispondono entro 1 giorno