[BUG]: Average PR Merge Time is underestimated when a merged PR has an invalid or negative duration
维护者通常 4 天内回复
@g-k-s-03 已经在做这个了。
开始于 2026年10月21日。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 84/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript, react
调研方向
阅读 src/hooks/useSortedData.js,重点关注 useAdvancedMetrics及其avgMergeHours计算。添加或调整一个单元测试,其中包含一个有效和一个无效的已合并 PR 时长,然后使用 npx vitest run运行测试。完成标准是:平均值只计算时长有效且非负的 PR,同时显示的已合并 PR 数量保持不变。
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- JavaScript
- 星标
- 45
- 派生
- 148
- 平均合并
- 5 天 14 小时
- 30 天内合并 PR
- 30
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
AOSSIE-Org/OrgExplorer 的其他 Issue
-
[BUG]: Overview "Language Distribution" percentages are relative to the top-7 languages, not all repos可能已有人在做 @Rohit270406 于 2 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 76/100
AOSSIE-Org/OrgExplorer#402 · 1 条评论 ·
维护者通常 4 天内回复
-
[BUG]: "Delete" PAT button is gated on the input field, so a saved token can't be removed when the field is empty可能已有人在做 @riyanshbhosale 于 1 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 88/100
AOSSIE-Org/OrgExplorer#401 · 1 条评论 ·
维护者通常 4 天内回复
-
[BUG]: Overview wrongly lists a successfully-loaded org as "could not be loaded" (case / duplicate)可能已有人在做 @dhruvbit 于 2 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 82/100
AOSSIE-Org/OrgExplorer#400 · 1 条评论 ·
维护者通常 4 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
AOSSIE-Org/OrgExplorer#399 · 1 条评论 ·
维护者通常 4 天内回复
-
[BUG]: Governance "Issue Resolution Rate" counts pull requests as issues可能已有人在做 @amangupta-12 于 1 天前认领。 未关闭bug
难度 1/5 1 小时以内 新手友好度 86/100
AOSSIE-Org/OrgExplorer#398 · 1 条评论 ·
维护者通常 4 天内回复
查看 AOSSIE-Org/OrgExplorer 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
bigcapitalhq/bigcapital#1544 · 1 条评论 ·
维护者通常 1 天内回复
-
help wanted kind/bug
难度 2/5 1-3 小时 新手友好度 78/100
meshery/meshery.io#3112 ·
维护者通常 2 天内回复
-
area:docs type:chore
难度 2/5 1-3 小时 新手友好度 82/100
bulkhead-labs/tailsuite#31 ·
-
dependencies javascript
难度 2/5 1-3 小时 新手友好度 70/100
gems-uff/noworkflow#470 ·
维护者通常 3 天内回复
-
product / auth product / console product / sites product / storage
难度 1/5 1 小时以内 新手友好度 84/100
维护者通常 1 天内回复