-
Notifications
You must be signed in to change notification settings - Fork 86
fix: time_in_draft calculation for pull requests initially created as drafts #587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: zkoppert <6935431+zkoppert@users.noreply.github.com>
Time in draft
for pull requests metrics is always None
Signed-off-by: Zack Koppert <zkoppert@github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug in the time_in_draft
calculation where pull requests initially created as drafts were returning None
instead of the actual time spent in draft state. The fix enhances the detection logic to handle PRs created as drafts from the beginning, not just those converted to draft status later.
Key changes:
- Enhanced the
measure_time_in_draft()
function to detect and calculate draft time for PRs initially created as drafts - Added comprehensive test coverage for the new draft detection scenarios
- Updated the function call in
issue_metrics.py
to pass the pull request object for better context
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
time_in_draft.py | Enhanced draft time calculation logic to handle PRs initially created as drafts |
test_time_in_draft.py | Added comprehensive test cases for initially-draft PR scenarios |
issue_metrics.py | Updated function call to pass pull request object parameter |
# Keep the real datetime class but only mock the now() method | ||
mock_datetime.fromisoformat = datetime.fromisoformat |
Copilot
AI
Sep 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach of selectively mocking datetime methods is fragile and could break if the implementation changes. Consider using freezegun
or a similar library for more robust datetime mocking in tests.
Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Zack Koppert <zkoppert@github.com>
The
time_in_draft
metric was returningNone
for all pull requests whenDRAFT_PR_TRACKING
was enabled, even for PRs that were actually in draft status or had previously been drafts.Root Cause
The
measure_time_in_draft()
function only tracked "converted_to_draft" events, which occur when a ready PR is converted back to draft. However, it missed the common case where pull requests are initially created as drafts. When a PR is created as a draft, there is no "converted_to_draft" event - it simply starts in that state.The Fix
Enhanced the function to detect and handle PRs initially created as drafts by:
Example
Before this fix, a PR created as draft on 2025-09-01 and marked ready on 2025-09-02 would show:
After this fix, the same PR correctly shows:
Changes Made
pull_request
parameter for better contextissue_metrics.py
The fix correctly handles:
Fixes #586.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.