From 18e6131826d8cd821a4af3bce08c4da9b4d5f0ee Mon Sep 17 00:00:00 2001 From: ludeeus Date: Fri, 29 Sep 2023 22:41:40 +0000 Subject: [PATCH] Add convert to draft helper --- src/plugins/newDefaultOpened.ts | 3 +++ src/utils/convertToDraft.ts | 10 ++++++++++ 2 files changed, 13 insertions(+) create mode 100644 src/utils/convertToDraft.ts diff --git a/src/plugins/newDefaultOpened.ts b/src/plugins/newDefaultOpened.ts index fcf6d84..c18947c 100644 --- a/src/plugins/newDefaultOpened.ts +++ b/src/plugins/newDefaultOpened.ts @@ -5,6 +5,7 @@ import { PullPayload } from '../types' import { extractOwnerRepo } from '../utils/extractOwnerRepo' import { senderIsBot } from '../utils/filter' import { extractTasks } from '../utils/tasks' +import { convertPullRequestToDraft } from '../utils/convertToDraft' export default async (app: App, payload: PullPayload): Promise => { if ( @@ -78,6 +79,7 @@ export default async (app: App, payload: PullPayload): Promise => { event: 'REQUEST_CHANGES', body: "Do not use 'HACS' as a part of your repository name.", }) + await convertPullRequestToDraft(app, payload.pull_request.node_id) return } @@ -90,6 +92,7 @@ export default async (app: App, payload: PullPayload): Promise => { event: 'REQUEST_CHANGES', body: `The submitted name \`${newRepo}\` does not match what GitHub returns for the repository (\`${repoInfo.full_name}\`).`, }) + await convertPullRequestToDraft(app, payload.pull_request.node_id) return } diff --git a/src/utils/convertToDraft.ts b/src/utils/convertToDraft.ts new file mode 100644 index 0000000..1f8d148 --- /dev/null +++ b/src/utils/convertToDraft.ts @@ -0,0 +1,10 @@ +import { App } from 'octokit' + +export const convertPullRequestToDraft = async ( + app: App, + nodeId: string, +): Promise => { + await app.octokit.graphql({ + query: `mutation { convertPullRequestToDraft(input: {pullRequestId: "${nodeId}"}) {clientMutationId}}`, + }) +}