I am trying to convert a pull-request back to a draft,
using github actions and gh.
But my action always fails when converting an open PR back to draft, with the log:
API call failed: GraphQL: github-actions[bot] does not have permission to convert the pull request PR_somenumbers to draft. (convertPullRequestToDraft)
Info:
At the time writing this question, GitHub faced an outage.
I tested again now one day later and the error still exists.
So it is not related to the GitHub outage.
My actions looks (trimmed) like so:
- On a new opened pull request do:
- checkout the repo
- Get the base branch of this pull request
- Search for open pull-requests, that have this base branch from 3. as head
- Iterate through the open pull-requests from 4. and if the base of this PR is my main branch, then:
- Set the PR status to ‘draft’ <- This is not working
name: Bot
on:
pull_request:
types:
- opened
jobs:
comment:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MAIN_BRANCH_NAME: 'main'
BASE_PR_REF: ${{ github.base_ref }}
steps:
- name: Check out repository code
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
- run: |
for base_pr_id in $(gh pr list --search "head:${{ env.BASE_PR_REF }}" --json number --jq '.[].number'); do
if [ ${{ env.MAIN_BRANCH_NAME }} == $( gh pr view $base_pr_id --json baseRefName --jq '.baseRefName') ]; then
gh pr ready $base_pr_id --undo <-- This won't work
fi
done
I also tried to add specific permissions, but none of them worked:
permissions:
pull-requests: write
contents: write
statuses: write
I also gave the actions read and write permissions in GitHub Settings.
No success. Any idea is highly welcome.
2
Answers
Have you tried running this workflow with a personal access token? It seems that the default user that is used by GitHub Actions does not have permission to do this conversation.
You can create a PAT here, store it in your repository secrets, and use it like so:
You can read here more about what to do if you need a token that requires permissions that aren’t available in the GITHUB_TOKEN.
Not every pull request on Github can be changed to a draft. For example free accounts on private repositories don’t have the option to put a pull request into draft status.
So if that is the case (private repository which does not allow drafts on pull requests), consider to upgrade the account or first of all create a public test repository for sandboxing as public repositories should allow draft status on pull requests.
This is easy to forget once the draft option is considered to be available.
Quoting from the OPs’ comment, user JacksOnF1re, who confirms the educated guess: