ci+docs: Add draft PR enforcement#5867
Conversation
Add workflow to auto-convert non-draft PRs to draft on open/reopen. Add Pull Requests section to CONTRIBUTING.md documenting the draft requirement and linking to the code submission standard. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Langchain
Internal Changes 🔧Langchain
Other
Other
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 9.08s All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 14386 uncovered lines. Generated by Codecov Action |
Co-authored-by: sentry-warden[bot] <258096371+sentry-warden[bot]@users.noreply.github.com>
Adds a label to PRs that were auto-converted to draft, enabling maintainers to filter and track how often the rule is violated. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
alexander-alderman-webb
left a comment
There was a problem hiding this comment.
Thank you!
| await github.rest.issues.addLabels({ | ||
| ...repo, | ||
| issue_number: pullRequest.number, | ||
| labels: ['converted-to-draft'], | ||
| }); |
There was a problem hiding this comment.
Bug: The addLabels call lacks error handling. If it fails, the workflow will terminate silently without posting its explanatory comment.
Severity: MEDIUM
Suggested Fix
Wrap the addLabels call in a try/catch block to handle potential errors gracefully. This ensures that the script can continue execution or log a meaningful error, preventing a silent failure. Consider also programmatically ensuring the label exists or documenting it as a prerequisite.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: .github/workflows/enforce-draft-pr.yml#L42-L46
Potential issue: The call to `github.rest.issues.addLabels` is not wrapped in any error
handling. If this operation fails, for example, due to the `"converted-to-draft"` label
not existing in the repository or because of insufficient permissions (potentially
requiring `issues: write`), the script will terminate prematurely. This silent failure
would prevent the subsequent, explanatory comment from being posted to the pull request,
undermining the workflow's goal of educating the contributor about the draft conversion.
Did we get this right? 👍 / 👎 to inform future reviews.
Add a GitHub Actions workflow that automatically converts non-draft PRs to draft on open/reopen, and document the draft PR requirement in CONTRIBUTING.md.
Motivation: Our code submission standard says PRs must start as drafts, but this wasn't enforced. Non-draft PRs trigger review notifications prematurely and signal readiness when the author may not be done. This workflow nudges contributors to open as draft by automatically converting non-draft PRs and posting a comment explaining the policy.
What's included:
.github/workflows/enforce-draft-pr.yml— triggers onpull_request_target(opened, reopened), uses the GraphQLconvertPullRequestToDraftmutation. Includes error handling and comment deduplication on reopen.CONTRIBUTING.md— new "Pull Requests" section documenting the draft requirement and linking to the code submission standard.Limitations: GitHub has no pre-creation hook, so the initial CI run and review notifications still fire before the conversion. The value is in training contributors and ensuring draft state before a maintainer picks up the PR.
No exemptions — applies to everyone (maintainers, internal, external contributors).