Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept PRs from forks. #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -81,19 +82,23 @@ 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 "[email protected]"`);
execSync(`git config user.name "GitHub Action"`);

core.info(`Fetching branch: ${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) {
Expand Down Expand Up @@ -292,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}`
);
Expand Down