From 3eb59a8d34b79006e33f9a22bf972f365aa73aaf Mon Sep 17 00:00:00 2001 From: Aaditya Srinivasan Date: Fri, 10 Jul 2026 16:38:27 +0530 Subject: [PATCH] GH-50379: Convert invalid PRs to draft automatically --- .github/workflows/dev_pr/title_check.js | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.github/workflows/dev_pr/title_check.js b/.github/workflows/dev_pr/title_check.js index 709a71428584..a986c8bc5f03 100644 --- a/.github/workflows/dev_pr/title_check.js +++ b/.github/workflows/dev_pr/title_check.js @@ -38,11 +38,41 @@ async function commentOpenGitHubIssue(github, context, pullRequestNumber) { }); } +/** + * Converts the pull request to draft. + * + * @param {Object} github + * @param {Object} context + */ +async function convertToDraft(github, context) { + if (context.payload.pull_request.draft) { + return; + } + + await github.graphql( + ` + mutation ($pullRequestId: ID!) { + convertPullRequestToDraft( + input: {pullRequestId: $pullRequestId} + ) { + pullRequest { + id + } + } + } + `, + { + pullRequestId: context.payload.pull_request.node_id, + }, + ); +} + module.exports = async ({github, context}) => { const pullRequestNumber = context.payload.number; const title = context.payload.pull_request.title; const issue = helpers.detectIssue(title) if (!issue) { await commentOpenGitHubIssue(github, context, pullRequestNumber); + await convertToDraft(github, context); } };