From fa4d8cac0e297de92c4d69140e112922c5f51644 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Mar 2026 22:53:50 +0000 Subject: [PATCH 1/2] Initial plan From 0959d628fdc78d9d344f24cdc147add442ea8674 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Mar 2026 23:05:59 +0000 Subject: [PATCH 2/2] fix: create fallback issue with Create PR link when GitHub Actions lacks PR permissions When the create_pull_request safe output handler encounters the "GitHub Actions is not permitted to create or approve pull requests" error, instead of setting an error output for the conclusion job (which created a settings-fix issue), it now: 1. Creates a fallback issue (branch has already been pushed at this point) 2. Includes a link to GitHub's compare URL pre-populated with title and branch info so the user can create the PR with one click 3. Returns success=true with fallback_used=true (consistent with other fallback paths) 4. Properly URL-encodes all path segments in the compare URL If the fallback issue creation also fails, returns error_type: "permission_denied". Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com> --- actions/setup/js/create_pull_request.cjs | 65 ++++++++++++++++--- actions/setup/js/create_pull_request.test.cjs | 5 +- 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/actions/setup/js/create_pull_request.cjs b/actions/setup/js/create_pull_request.cjs index 58e48d0024e..9fff22b0f40 100644 --- a/actions/setup/js/create_pull_request.cjs +++ b/actions/setup/js/create_pull_request.cjs @@ -986,16 +986,61 @@ ${patchPreview}`; // Check if the error is the specific "GitHub actions is not permitted to create or approve pull requests" error if (errorMessage.includes("GitHub Actions is not permitted to create or approve pull requests")) { core.error("Permission error: GitHub Actions is not permitted to create or approve pull requests"); - // Set output variable for conclusion job to handle - core.setOutput( - "error_message", - "GitHub Actions is not permitted to create or approve pull requests. Please enable 'Allow GitHub Actions to create and approve pull requests' in repository settings: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository#preventing-github-actions-from-creating-or-approving-pull-requests" - ); - return { - success: false, - error: errorMessage, - error_type: "permission_denied", - }; + + // Branch has already been pushed - create a fallback issue with a link to create the PR via GitHub UI + const githubServer = process.env.GITHUB_SERVER_URL || "https://github.com"; + // Encode branch name path segments individually to preserve '/' while encoding other special characters + const encodedBase = baseBranch.split("/").map(encodeURIComponent).join("/"); + const encodedHead = branchName.split("/").map(encodeURIComponent).join("/"); + const createPrUrl = `${githubServer}/${repoParts.owner}/${repoParts.repo}/compare/${encodedBase}...${encodedHead}?expand=1&title=${encodeURIComponent(title)}`; + + // Read patch content for preview + let patchPreview = ""; + if (patchFilePath && fs.existsSync(patchFilePath)) { + const patchContent = fs.readFileSync(patchFilePath, "utf8"); + patchPreview = generatePatchPreview(patchContent); + } + + const fallbackBody = + `${body}\n\n---\n\n` + + `> [!NOTE]\n` + + `> This was originally intended as a pull request, but GitHub Actions is not permitted to create or approve pull requests in this repository.\n` + + `> The changes have been pushed to branch \`${branchName}\`.\n` + + `>\n` + + `> **[Click here to create the pull request](${createPrUrl})**\n\n` + + `To fix the permissions issue, go to **Settings** → **Actions** → **General** and enable **Allow GitHub Actions to create and approve pull requests**.` + + patchPreview; + + try { + const { data: issue } = await githubClient.rest.issues.create({ + owner: repoParts.owner, + repo: repoParts.repo, + title: title, + body: fallbackBody, + labels: mergeFallbackIssueLabels(labels), + }); + + core.info(`Created fallback issue #${issue.number}: ${issue.html_url}`); + + await updateActivationComment(github, context, core, issue.html_url, issue.number, "issue"); + + return { + success: true, + fallback_used: true, + issue_number: issue.number, + issue_url: issue.html_url, + branch_name: branchName, + repo: itemRepo, + }; + } catch (issueError) { + const error = `Failed to create pull request (permission denied) and failed to create fallback issue. PR error: ${errorMessage}. Issue error: ${issueError instanceof Error ? issueError.message : String(issueError)}`; + core.error(error); + return { + success: false, + error, + error_type: "permission_denied", + }; + } } if (!fallbackAsIssue) { diff --git a/actions/setup/js/create_pull_request.test.cjs b/actions/setup/js/create_pull_request.test.cjs index f2bf54491da..a36aefb7499 100644 --- a/actions/setup/js/create_pull_request.test.cjs +++ b/actions/setup/js/create_pull_request.test.cjs @@ -34,7 +34,7 @@ describe("create_pull_request - fallback-as-issue configuration", () => { const errorTypes = { push_failed: "Used when git push operation fails and fallback-as-issue is false", pr_creation_failed: "Used when PR creation fails (except permission errors) and fallback-as-issue is false", - permission_denied: "Used when GitHub Actions lacks permission to create/approve PRs (handled before fallback logic)", + permission_denied: "Used when GitHub Actions lacks permission to create/approve PRs AND fallback issue creation also fails", }; // Verify the error types are documented @@ -45,7 +45,8 @@ describe("create_pull_request - fallback-as-issue configuration", () => { // These error types should be returned in the corresponding code paths: // - push failure with fallback disabled: error_type: "push_failed" // - PR creation failure with fallback disabled: error_type: "pr_creation_failed" - // - Permission error (always): error_type: "permission_denied" + // - Permission error with successful fallback issue: success=true, fallback_used=true + // - Permission error when fallback issue also fails: error_type: "permission_denied" }); }); });