diff --git a/scripts/pr-lib/worktree.sh b/scripts/pr-lib/worktree.sh index 61508f8f3dbd..6341887bbebd 100644 --- a/scripts/pr-lib/worktree.sh +++ b/scripts/pr-lib/worktree.sh @@ -102,7 +102,7 @@ enter_worktree() { pr_meta_json() { local pr="$1" local metadata files expected_file_count actual_file_count head_before head_after - metadata=$(gh pr view "$pr" --json number,title,state,isDraft,author,baseRefName,headRefName,headRefOid,headRepository,headRepositoryOwner,url,body,labels,assignees,reviewRequests,changedFiles,additions,deletions,statusCheckRollup,files) + metadata=$(gh pr view "$pr" --json number,title,state,isDraft,author,baseRefName,headRefName,headRefOid,headRepository,headRepositoryOwner,url,body,labels,assignees,changedFiles,additions,deletions,statusCheckRollup,files) head_before=$(printf '%s\n' "$metadata" | jq -r .headRefOid) expected_file_count=$(printf '%s\n' "$metadata" | jq -r .changedFiles) diff --git a/test/scripts/pr-metadata.test.ts b/test/scripts/pr-metadata.test.ts index 1fc807df0da1..1d8fb0dee17d 100644 --- a/test/scripts/pr-metadata.test.ts +++ b/test/scripts/pr-metadata.test.ts @@ -17,6 +17,10 @@ set -euo pipefail if [ "$1" = "pr" ] && [ "$2" = "view" ]; then if [[ "$*" == *changedFiles* ]]; then + if [ "\${FAKE_REJECT_REVIEW_REQUESTS:-0}" = "1" ] && [[ "$*" == *reviewRequests* ]]; then + echo "GraphQL: Resource not accessible by integration (repository.pullRequest.reviewRequests.nodes.0.requestedReviewer)" >&2 + exit 1 + fi jq -nc --argjson changedFiles "\${FAKE_CHANGED_FILES:-101}" --argjson fileCount "\${FAKE_GRAPHQL_FILE_COUNT:-100}" --argjson includeChangeType "\${FAKE_GRAPHQL_CHANGE_TYPE:-true}" ' { number: 42, @@ -73,6 +77,7 @@ function readPrMetadata( graphqlChangeType?: boolean; graphqlFileCount?: string; headAfter?: string; + rejectReviewRequests?: boolean; restFileCount?: string; } = {}, ) { @@ -91,6 +96,7 @@ function readPrMetadata( FAKE_GRAPHQL_CHANGE_TYPE: options.graphqlChangeType === false ? "false" : "true", FAKE_GRAPHQL_FILE_COUNT: options.graphqlFileCount ?? "100", FAKE_HEAD_AFTER: options.headAfter ?? "head-a", + FAKE_REJECT_REVIEW_REQUESTS: options.rejectReviewRequests ? "1" : "0", FAKE_REST_FILE_COUNT: options.restFileCount ?? "101", OPENCLAW_GH_BIN: join(fakeGhDir, "gh"), PATH: `${fakeGhDir}:${process.env.PATH}`, @@ -107,6 +113,17 @@ afterEach(() => { }); describe("PR metadata", () => { + it("does not request reviewer metadata that GitHub App tokens cannot read", () => { + const result = readPrMetadata(createFakeGh(), { + changedFiles: "2", + graphqlFileCount: "2", + rejectReviewRequests: true, + }); + + expect(result.status).toBe(0); + expect(result.stderr).toBe(""); + }); + it("uses cacheable GraphQL file metadata when the complete list fits", () => { const result = readPrMetadata(createFakeGh(), { changedFiles: "2",