fix: parsing error in stale PR workflow for workflow_dispatch (#26691)

* fix: fix parsing error and add token support for fork PRs in stale PR workflow

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix: keep only parsing error fix, remove token support for fork PRs

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Keith Williams
2026-01-10 15:00:52 -03:00
committed by GitHub
co-authored by Devin AI
parent 46b1bc3365
commit 7a9462b756
@@ -8,7 +8,7 @@ on:
pr_number:
description: 'PR number to complete'
required: true
type: number
type: string
permissions:
contents: read
@@ -27,6 +27,8 @@ jobs:
- name: Get PR details
id: pr
uses: actions/github-script@v7
env:
INPUT_PR_NUMBER: ${{ inputs.pr_number }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
@@ -34,7 +36,12 @@ jobs:
let pr;
if (context.eventName === 'workflow_dispatch') {
prNumber = ${{ inputs.pr_number || 0 }};
const inputPrNumber = process.env.INPUT_PR_NUMBER;
prNumber = parseInt(inputPrNumber, 10);
if (isNaN(prNumber) || prNumber <= 0) {
core.setFailed(`Invalid PR number provided: "${inputPrNumber}". Please enter a valid PR number.`);
return;
}
const { data } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
@@ -46,21 +53,13 @@ jobs:
prNumber = pr.number;
}
// Check if head repo still exists (can be null if fork was deleted)
if (!pr.head.repo) {
core.setFailed('Cannot complete this PR: the source repository (fork) has been deleted.');
return;
}
// Check if this is a fork PR
const isFork = pr.head.repo.fork || pr.head.repo.full_name !== pr.base.repo.full_name;
// For fork PRs, check if maintainer can modify (push to the branch)
const maintainerCanModify = pr.maintainer_can_modify;
// Determine if we can proceed
// - Non-fork PRs: always allowed (maintainers have push access)
// - Fork PRs: only if maintainer_can_modify is true
const canProceed = !isFork || maintainerCanModify;
if (!canProceed) {
@@ -68,11 +67,9 @@ jobs:
return;
}
// Get the clone URL for the head repo (fork or base)
const headRepoFullName = pr.head.repo.full_name;
const headRepoCloneUrl = pr.head.repo.clone_url;
// Set outputs for use in subsequent steps
core.setOutput('pr_number', prNumber);
core.setOutput('pr_title', pr.title);
core.setOutput('pr_author', pr.user.login);
@@ -102,7 +99,6 @@ jobs:
HEAD_REPO_FULL_NAME: ${{ steps.pr.outputs.head_repo_full_name }}
REPO_NAME: ${{ github.repository }}
run: |
# Build fork-specific instructions if this is a fork PR
if [ "$IS_FORK" = "true" ]; then
CLONE_INSTRUCTIONS="This is a fork PR. Clone from the fork repository: ${HEAD_REPO_FULL_NAME}