From 58b7698569b242ca28c39233956268bd84ea89a4 Mon Sep 17 00:00:00 2001 From: Felipe Gasper Date: Thu, 28 Mar 2024 10:08:50 -0400 Subject: [PATCH 1/3] Accept PRs from forks. --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a1a2d0d..5b40015 100644 --- a/index.js +++ b/index.js @@ -26,6 +26,7 @@ class Variables { mainBranch: core.getInput("main-branch", { required: false }) || "main", octokit: github.getOctokit(token), pullRequestAuthor: pullRequest.user.login, + pullRequestHeadUrl: pullRequest.head.repo.clone_url, pullRequestBranch: pullRequest.head.ref, pullRequestNumber: pullRequest.number, quiet, @@ -85,7 +86,9 @@ async function setup() { execSync(`git config user.email "action@github.com"`); execSync(`git config user.name "GitHub Action"`); - execSync(`git fetch origin ${mainBranch}:${mainBranch}`); + execSync(`git remote add prSource ${variables.get("pullRequestHeadUrl")}`); + + execSync(`git fetch prSource ${mainBranch}:${mainBranch}`); // Fetch PR branches into temporary refs execSync( From 94ab5cb78efcfe78a9b00e106fff429e5c2f95f1 Mon Sep 17 00:00:00 2001 From: Felipe Gasper Date: Thu, 28 Mar 2024 10:11:09 -0400 Subject: [PATCH 2/3] Update index.js --- index.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 5b40015..747be78 100644 --- a/index.js +++ b/index.js @@ -86,17 +86,16 @@ async function setup() { execSync(`git config user.email "action@github.com"`); execSync(`git config user.name "GitHub Action"`); - execSync(`git remote add prSource ${variables.get("pullRequestHeadUrl")}`); - - execSync(`git fetch prSource ${mainBranch}:${mainBranch}`); + execSync(`git fetch origin ${mainBranch}:${mainBranch}`); // Fetch PR branches into temporary refs + execSync(`git remote add prSource ${variables.get("pullRequestHeadUrl")}`); execSync( - `git fetch origin ${pullRequestBranch}:refs/remotes/origin/tmp_${pullRequestBranch}` + `git fetch prSource ${pullRequestBranch}:refs/remotes/prSource/tmp_${pullRequestBranch}` ); // Merge main into pull request branch in memory - execSync(`git checkout refs/remotes/origin/tmp_${pullRequestBranch}`); + execSync(`git checkout refs/remotes/prSource/tmp_${pullRequestBranch}`); execSync(`git merge ${mainBranch} --no-commit --no-ff`); execSync(`git reset --hard HEAD`); } catch (error) { From 6c41d80f5b206ddd0ad67ad8ab939ee7ef12fe64 Mon Sep 17 00:00:00 2001 From: Felipe Gasper Date: Thu, 28 Mar 2024 12:59:00 -0400 Subject: [PATCH 3/3] more logging --- index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/index.js b/index.js index 747be78..8c48308 100644 --- a/index.js +++ b/index.js @@ -82,10 +82,13 @@ async function setup() { const pullRequestBranch = variables.get("pullRequestBranch"); try { + core.info("Configuring local git repository"); + // Configure Git with a dummy user identity execSync(`git config user.email "action@github.com"`); execSync(`git config user.name "GitHub Action"`); + core.info(`Fetching branch: ${mainBranch}`); execSync(`git fetch origin ${mainBranch}:${mainBranch}`); // Fetch PR branches into temporary refs @@ -294,7 +297,11 @@ async function attemptMerge(otherPullRequestBranch) { debug( `Attempting to merge #${otherPullRequestBranch} into #${pullRequestBranch}` ); + core.info( + `Attempting to merge #${otherPullRequestBranch} into #${pullRequestBranch}` + ); + core.info(`Fetching branch: ${otherPullRequestBranch}`); execSync( `git fetch origin ${otherPullRequestBranch}:refs/remotes/origin/tmp_${otherPullRequestBranch}` );