Skip to content

Commit c28aa2c

Browse files
committed
Determine the target repository for the PR
1 parent 620f833 commit c28aa2c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

.github/workflows/generate-release-maintenance.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ jobs:
4949
VERSION=${TAG%%-*}
5050
BRANCH_NAME="${VERSION}-maintenance"
5151
52+
# Determine the target repository for the PR (upstream if fork, else current)
53+
TARGET_REPO=$(gh repo view --json parent --jq '.parent.nameWithOwner')
54+
if [[ -z "$TARGET_REPO" || "$TARGET_REPO" == "null" ]]; then
55+
TARGET_REPO="${{ github.repository }}"
56+
fi
57+
export GH_REPO="$TARGET_REPO"
58+
echo "Targeting repository: $GH_REPO"
59+
5260
if git ls-remote --heads origin "$VERSION" | grep -q "$VERSION"; then
5361
BASE_BRANCH="$VERSION"
5462
else
@@ -65,7 +73,7 @@ jobs:
6573
git remote add fork "https://x-access-token:${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/${FORK_OWNER}/rancher-product-docs.git"
6674
git push -f fork "$BRANCH_NAME"
6775
68-
PR_NUMBER=$(gh pr list --head "${FORK_OWNER}:${BRANCH_NAME}" --base "$BASE_BRANCH" --json number --jq '.[0].number')
76+
PR_NUMBER=$(gh pr list --head "$BRANCH_NAME" --base "$BASE_BRANCH" --json number,headRepositoryOwner --jq ".[] | select(.headRepositoryOwner.login == \"$FORK_OWNER\") | .number" | head -n 1)
6977
7078
if [[ -n "$PR_NUMBER" && "$PR_NUMBER" != "null" ]]; then
7179
gh pr edit "$PR_NUMBER" \

0 commit comments

Comments
 (0)