61 lines
2.0 KiB
YAML
61 lines
2.0 KiB
YAML
# 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
|
|
env:
|
|
MOVE_PR_TO_DRAFT_TOKEN_ENV: ${{ secrets.MOVE_PR_TO_DRAFT_TOKEN }}
|
|
if: ${{ env.MOVE_PR_TO_DRAFT_TOKEN_ENV != '' }}
|
|
run: |
|
|
echo ${{ env.MOVE_PR_TO_DRAFT_TOKEN_ENV }} | 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
|
|
}
|
|
}
|
|
}
|
|
'
|