Skip to content

Commit

Permalink
Add convert to draft helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Sep 29, 2023
1 parent 446e334 commit 18e6131
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/plugins/newDefaultOpened.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
if (
Expand Down Expand Up @@ -78,6 +79,7 @@ export default async (app: App, payload: PullPayload): Promise<void> => {
event: 'REQUEST_CHANGES',
body: "Do not use 'HACS' as a part of your repository name.",
})
await convertPullRequestToDraft(app, payload.pull_request.node_id)
return
}

Expand All @@ -90,6 +92,7 @@ export default async (app: App, payload: PullPayload): Promise<void> => {
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
}

Expand Down
10 changes: 10 additions & 0 deletions src/utils/convertToDraft.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { App } from 'octokit'

export const convertPullRequestToDraft = async (
app: App,
nodeId: string,
): Promise<void> => {
await app.octokit.graphql({
query: `mutation { convertPullRequestToDraft(input: {pullRequestId: "${nodeId}"}) {clientMutationId}}`,
})
}

0 comments on commit 18e6131

Please sign in to comment.