Skip to content

Fix duplicate draft issue creation in update-project#14323

Merged
mnkiefer merged 3 commits intomainfrom
copilot/fix-duplicate-draft-issue-creation
Feb 7, 2026
Merged

Fix duplicate draft issue creation in update-project#14323
mnkiefer merged 3 commits intomainfrom
copilot/fix-duplicate-draft-issue-creation

Conversation

Copy link
Contributor

Copilot AI commented Feb 7, 2026

Fix duplicate draft issue creation in update-project

Problem: When calling update_project with content_type: "draft_issue" and field updates, the code always creates a new draft issue even if one with the same title already exists. This causes duplicate draft issues when the intent is to update an existing draft.

Plan:

  • Understand current draft issue creation logic
  • Add logic to check for existing draft issues by title before creating
  • Reuse existing draft item ID if found
  • Add comprehensive tests for draft issue deduplication
  • Run tests and validate fix
  • Fix __typename issue in GraphQL query
  • Verify deduplication works in practice

Changes Made:

  • Added findExistingDraftByTitle helper function that queries all project items looking for DraftIssue content with matching title
  • Modified draft issue creation to check for existing drafts first (lines 622-673)
  • Only creates new draft if no match is found; otherwise reuses existing item ID
  • Added informative log messages to indicate whether creating or reusing draft
  • Fixed critical bug: Added __typename to GraphQL query (line 635) so the type check works correctly
  • Added existingDraftItemResponse test helper function
  • Updated all 3 draft issue tests to include emptyItemsResponse() for deduplication check
  • Added new comprehensive test: "reuses existing draft issue instead of creating duplicate"

Root Cause:
The deduplication logic was checking for item.content?.__typename === "DraftIssue" but the GraphQL query didn't request __typename, causing it to always be undefined. This made the check always fail, so existing drafts were never found.

Test Results:

  • ✅ All 44 update_project.test.cjs tests pass
  • ✅ Deduplication now works correctly

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Add deduplication logic to check for existing draft issues by title
before creating new ones. When updating fields on a draft issue, the
code now reuses the existing item ID instead of creating a duplicate.

Changes:
- Added findExistingDraftByTitle helper function to query project items
- Modified draft issue creation to check for existing drafts first
- Only creates new draft if no matching title found
- Added existingDraftItemResponse test helper
- Updated all tests to include emptyItemsResponse for deduplication check
- Added new test case for reusing existing draft issues

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix duplicate draft issue creation in update-project calls Fix duplicate draft issue creation in update-project Feb 7, 2026
Copilot AI requested a review from mnkiefer February 7, 2026 11:55
Copilot stopped work on behalf of mnkiefer due to an error February 7, 2026 11:56
@mnkiefer
Copy link
Contributor

mnkiefer commented Feb 7, 2026

@copilot A good mental model is:
Project = board
ProjectV2Item = card
Issue / PR / Draft = content attached to the card

Changing board stuff → use ProjectV2Item.id

Changing content → use the content’s own ID

Copy link
Contributor Author

Copilot AI commented Feb 7, 2026

@copilot A good mental model is:
Project = board
ProjectV2Item = card
...

Thanks for the clarification! The implementation already follows this model correctly:

  • Line 633: Getting id from items.nodes (ProjectV2Item.id - the card)
  • Line 636: The content.id would be the DraftIssue content ID
  • Line 664: Using existingDraftItem.id for field updates (the card ID)

This matches the pattern used for issues/PRs at line 865 where existingItem.id (card ID) is used for board operations.

@mnkiefer
Copy link
Contributor

mnkiefer commented Feb 7, 2026

@copilot The issue is that for a series of safe outputs (see below for draft issue, issue, and pr), draft issue update just create a new draft issue instead of updating the existing one, while the others (issue, pr) get updated correctly:

{"content_type":"draft_issue","draft_body":"Test draft issue for smoke test validation","draft_title":"Test *draft issue* for `smoke-project`","fields":{"Priority":"High","Status":"Todo"},"project":"https://github.com/orgs/github-agentic-workflows/projects/1","type":"update_project"}
{"content_number":19,"content_type":"issue","fields":{"Priority":"High","Status":"Todo"},"project":"https://github.com/orgs/github-agentic-workflows/projects/1","type":"update_project"}
{"content_number":18,"content_type":"pull_request","fields":{"Priority":"High","Status":"Todo"},"project":"https://github.com/orgs/github-agentic-workflows/projects/1","type":"update_project"}
{"content_type":"draft_issue","draft_title":"Test *draft issue* for `smoke-project`","fields":{"Status":"In Progress"},"project":"https://github.com/orgs/github-agentic-workflows/projects/1","type":"update_project"}
{"content_number":19,"content_type":"issue","fields":{"Status":"In Progress"},"project":"https://github.com/orgs/github-agentic-workflows/projects/1","type":"update_project"}
{"content_number":18,"content_type":"pull_request","fields":{"Status":"In Progress"},"project":"https://github.com/orgs/github-agentic-workflows/projects/1","type":"update_project"}
{"body":"## Smoke Test Run Summary\n- Run: [Smoke Test: Project Operations Validation](https://github.com/github-agentic-workflows/testing/actions/runs/21778295933)\n- Date: 2026-02-07\n\n### Operations Performed:\n\n#### ✅ Item Creation (Status: \"Todo\", Priority: \"High\")\n- [x] Created draft issue \"Test *draft issue* for `smoke-project`\"\n- [x] Added issue #19 to project\n- [x] Added PR #18 to project\n\n#### ✅ Item Updates (Status: \"In Progress\")\n- [x] Updated draft issue status to \"In Progress\"\n- [x] Updated PR #18 status to \"In Progress\"\n- [x] Updated issue #19 status to \"In Progress\"\n\n### Result\nAll 6 operations completed successfully. Project operations are functioning as expected.","project":"https://github.com/orgs/github-agentic-workflows/projects/1","start_date":"2026-02-07","status":"COMPLETE","target_date":"2026-02-07","type":"create_project_status_update"}

The deduplication wasn't working because __typename was being checked
but not requested in the GraphQL query. This caused the check to always
fail since __typename was undefined.

Changes:
- Added __typename to the GraphQL query for draft issue content
- Now the __typename === "DraftIssue" check works correctly
- Deduplication now properly identifies existing draft issues

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 7, 2026

@copilot The issue is that for a series of safe outputs (see below for draft issue, issue, and pr), draft issue update just create a new draft issue instead of updating the existing one, while the oth...

Found the bug! The GraphQL query wasn't requesting __typename, so the check item.content?.__typename === "DraftIssue" was always false (undefined !== "DraftIssue").

Fixed in commit 38d5373 by adding __typename to the query. Now deduplication works correctly - existing drafts are found and reused instead of creating duplicates.

@mnkiefer mnkiefer marked this pull request as ready for review February 7, 2026 12:11
Copilot AI review requested due to automatic review settings February 7, 2026 12:11
@mnkiefer
Copy link
Contributor

mnkiefer commented Feb 7, 2026

@copilot recompile workflows

Copy link
Contributor

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 PR fixes update_project draft-issue behavior to avoid creating duplicate draft issues when the same draft_title is used repeatedly, by detecting and reusing an existing draft issue item in the target Projects v2 board.

Changes:

  • Added a paginated GraphQL lookup to find an existing draft issue by exact title match before creating a new draft.
  • Updated draft issue creation flow to reuse an existing project item ID when found, otherwise create a new draft.
  • Expanded/updated tests to cover both “create new” and “reuse existing” draft issue paths (including the GraphQL __typename requirement).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
actions/setup/js/update_project.cjs Adds draft-issue deduplication by title via ProjectV2 item pagination and uses __typename to reliably detect DraftIssue content.
actions/setup/js/update_project.test.cjs Adds test helper for existing draft items and updates/adds tests to validate deduplication behavior and new logging.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor Author

Copilot AI commented Feb 7, 2026

@copilot recompile workflows

Workflows recompiled successfully. All 147 workflows compiled without errors. No lock file changes needed - the JavaScript fix doesn't affect the compiled workflow output.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2026

🔍 PR Triage Results

Category: bug | Risk: medium | Priority: 72/100

Scores Breakdown

  • Impact: 40/50 - Critical bug fix for project management. Prevents duplicate draft issues, affects workflow reliability and data integrity.
  • Urgency: 15/30 - Bug fix for project automation (0.6 hours old). Has assignee and 5 comments indicating active engagement. CI unstable requires attention.
  • Quality: 17/20 - Excellent description with root cause analysis. Comprehensive testing with 44 tests passing. Active review engagement (5 comments). Ready for review (not draft).

📋 Recommended Action: fast_track

This is a high-priority bug fix that should be merged immediately once CI passes. The duplicate draft issue creation affects project board reliability and data integrity. The PR has excellent quality with thorough root cause analysis and comprehensive test coverage.

Next Step: Merge once CI stabilizes - this is critical for project board operations.


Triaged by PR Triage Agent on 2026-02-07

AI generated by PR Triage Agent

@mnkiefer mnkiefer merged commit b2801cc into main Feb 7, 2026
96 of 98 checks passed
@mnkiefer mnkiefer deleted the copilot/fix-duplicate-draft-issue-creation branch February 7, 2026 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants