Skip to content

Move PR to Draft

Move PR to Draft #73

Workflow file for this run

# Marks all changed PR as draft
name: Move PR to Draft
on:
workflow_run:
workflows: [Draft on Synchronize]
types:
- completed
jobs:
actually-move-to-draft:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: 'Download artifact'
uses: actions/github-script@v7
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr_number"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr_number.zip`, Buffer.from(download.data));
- name: 'Unzip artifact'
run: unzip pr_number.zip
- name: 'Extract PR node id'
shell: bash
run: |
(echo -n "PR_NUMBER=" | cat - pr_number) >> $GITHUB_ENV
- name: 'Actually move to draft'
shell: bash
run: |
echo ${{ secrets.MOVE_PR_TO_DRAFT_TOKEN }} | gh auth login --with-token
gh api graphql -F id=${{ env.PR_NUMBER }} -f query='
mutation($id: ID!) {
convertPullRequestToDraft(input: { pullRequestId: $id }) {
pullRequest {
id
number
isDraft
}
}
}
'