Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 3, 2025

This pull request updates the logic and tests for measuring the time a pull request spends in draft state. The main changes include standardizing the event name for draft conversions, improving compatibility with iterator-based event sources, updating test data types, and rounding the output for consistency.

Bug fixes and compatibility improvements:

  • Standardized the event name from "converted_to_draft" to "convert_to_draft" throughout both the implementation and all test cases, ensuring consistency with the real GitHub API event names. [1] [2] [3] [4] [5] [6] [7] [8] [9]

  • Modified the measure_time_in_draft function to convert the events iterator to a list at the start, ensuring compatibility with the real GitHub API, which returns an iterator that can only be consumed once.

Test enhancements:

  • Added a new test (test_time_in_draft_with_iterator_events) to verify that measure_time_in_draft works correctly when the events method returns an iterator, simulating real-world API behavior.

  • Updated test setup to use datetime objects for created_at instead of ISO-formatted strings, aligning with the rest of the code and improving clarity. [1] [2]

Accuracy improvements:

  • The result of measure_time_in_draft is now rounded to the nearest second for improved accuracy and consistency.

  • Updated variable names in the implementation for clarity (e.g., converted_to_draft_eventsconvert_to_draft_events). [1] [2]

These changes improve reliability, maintainability, and correctness of the draft time measurement logic and its associated tests. fixes #608

Co-authored-by: zkoppert <6935431+zkoppert@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Fix draft pull request metrics returning None Fix time_in_draft iterator exhaustion causing None values Oct 3, 2025
@Copilot Copilot AI requested a review from zkoppert October 3, 2025 18:15
Copilot finished work on behalf of zkoppert October 3, 2025 18:15
@github-actions github-actions bot added the fix label Oct 3, 2025
@zkoppert zkoppert changed the title Fix time_in_draft iterator exhaustion causing None values fix: Fix time_in_draft iterator exhaustion causing None values Oct 3, 2025
- Change event name from converted_to_draft to convert_to_draft to match actual GitHub timeline events
- Remove problematic datetime parsing that was causing type errors
- Update time calculation logic to properly handle draft state transitions
- Make issue_metrics.py executable
- Update corresponding test cases to use correct event names

This fixes the draft PR metrics functionality to work with the actual GitHub API events.

Signed-off-by: Zack Koppert <zkoppert@github.com>
@zkoppert zkoppert changed the title fix: Fix time_in_draft iterator exhaustion causing None values fix: Fix time_in_draft iterator exhaustion and misnamed event Oct 4, 2025
@zkoppert zkoppert marked this pull request as ready for review October 4, 2025 05:06
@zkoppert zkoppert requested a review from a team as a code owner October 4, 2025 05:06
@Copilot Copilot AI review requested due to automatic review settings October 4, 2025 05:06
Copy link
Contributor

@Copilot Copilot AI left a 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 pull request fixes bugs in the draft time measurement functionality by correcting the GitHub API event name and improving compatibility with iterator-based event sources. The changes ensure the code works correctly with the real GitHub API.

  • Standardized event name from "converted_to_draft" to "convert_to_draft" throughout code and tests
  • Fixed iterator exhaustion issue by converting events to a list upfront
  • Added test coverage for iterator-based events and improved test data consistency

Reviewed Changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
time_in_draft.py Updated event name, fixed iterator handling, and added result rounding
test_time_in_draft.py Updated all test cases with correct event name and added iterator test

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Zack Koppert <zkoppert@github.com>
@zkoppert zkoppert merged commit 4860492 into main Oct 4, 2025
34 checks passed
@zkoppert zkoppert deleted the copilot/fix-draft-pr-metrics-issue branch October 4, 2025 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Time in draft for pull requests metrics is always None v2

3 participants