mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
fix(scripts): tolerate restricted PR metadata tokens (#121848)
Amp-Thread-ID: https://ampcode.com/threads/T-019feaaa-c7ed-769e-9f29-a3612bec72e7 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
committed by
GitHub
parent
9df9cc2228
commit
c8571daa2f
@@ -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)
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user