From 7a9462b756bc221159f0d4a674154fd3cd37d053 Mon Sep 17 00:00:00 2001 From: Keith Williams Date: Sat, 10 Jan 2026 15:00:52 -0300 Subject: [PATCH] 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> --- .../workflows/stale-pr-devin-completion.yml | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/.github/workflows/stale-pr-devin-completion.yml b/.github/workflows/stale-pr-devin-completion.yml index 38a3000fdc..d04b4ed1ed 100644 --- a/.github/workflows/stale-pr-devin-completion.yml +++ b/.github/workflows/stale-pr-devin-completion.yml @@ -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}