Skip to content

Commit fbb8ea1

Browse files
committed
github actions: Fix process-pull-request for forks
The process-pull-request workflow was failing for pull requests originating from forked repositories. The previous implementation incorrectly assumed the pull request branch existed on the base repository. This commit corrects the workflow to ensure the pull request branch is checked out from the correct source repository, while the base branch is fetched from the target repository.
1 parent 0da74d6 commit fbb8ea1

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

.github/workflows/process-git-request.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def process_git_request(fname, target_branch, source_branch, prj_dir)
2222
# puts "Working Dir : " + working_dir
2323
Dir.chdir working_dir
2424
# puts "pwd : " + Dir.pwd
25-
git_cmd = "git log --oneline --no-abbrev-commit origin/" + target_branch + ".." + "origin/" + source_branch
25+
git_cmd = "git log --oneline --no-abbrev-commit base_repo/" + target_branch + ".." + "origin/" + source_branch
2626
# puts git_cmd
2727
out, err, status = Open3.capture3(git_cmd)
2828
if status.exitstatus != 0

.github/workflows/process-pull-request.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
pull_request:
1010
branches:
1111
- '**'
12-
- '!mainline'
12+
- '!mainline'
1313

1414
permissions:
1515
contents: read
@@ -24,7 +24,18 @@ jobs:
2424
ruby-version: ['3.0']
2525

2626
steps:
27-
- uses: actions/checkout@v4
27+
- name: Checkout PR branch
28+
uses: actions/checkout@v4
29+
with:
30+
repository: ${{ github.event.pull_request.head.repo.full_name }}
31+
fetch-depth: 0
32+
ref: ${{ github.head_ref }}
33+
34+
- name: Checkout base branch
35+
run: |
36+
git remote add base_repo https://github.com/${{ github.repository }}.git
37+
git fetch base_repo ${{ github.base_ref }}:${{ github.base_ref }}
38+
2839
- name: Set up Ruby
2940
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
3041
# change this to (see https://github.com/ruby/setup-ruby#versioning):
@@ -39,8 +50,6 @@ jobs:
3950
run: |
4051
/usr/bin/pip3 install gitPython
4152
python -c "import sys; import git; print(sys.version)"
42-
git fetch origin ${{ github.base_ref }}
43-
git fetch origin ${{ github.head_ref }}
4453
git remote add linux https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
4554
git fetch --shallow-since="3 years ago" linux
4655
echo "Will run process-git-request.rb with:"

0 commit comments

Comments
 (0)