From 192c6d5761e735cc3c7a936e79016308e1548359 Mon Sep 17 00:00:00 2001 From: sjh9714 <163989462+sjh9714@users.noreply.github.com> Date: Fri, 4 Sep 2026 10:30:04 +0900 Subject: [PATCH] fix: ignore cross-repository associated pull requests --- lib/success.js | 14 ++++++++++++-- test/success.test.js | 11 +++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/success.js b/lib/success.js index 48246f29..8a7ac812 100644 --- a/lib/success.js +++ b/lib/success.js @@ -74,6 +74,8 @@ export default async function success(pluginConfig, context, { Octokit }) { ); const releaseInfos = releases.filter((release) => Boolean(release.name)); const shas = commits.map(({ hash }) => hash); + const isSameRepository = ({ repository }) => + !repository || repository.nameWithOwner === `${owner}/${repo}`; // Get associatedPRs const associatedPRs = await inChunks(shas, 100, async (chunk) => { @@ -88,7 +90,9 @@ export default async function success(pluginConfig, context, { Octokit }) { for (const { nodes, pageInfo } of responseAssociatedPRs) { if (nodes.length === 0) continue; - responsePRs.push(...buildIssuesOrPRsFromResponseNode(nodes)); + responsePRs.push( + ...buildIssuesOrPRsFromResponseNode(nodes.filter(isSameRepository)), + ); if (pageInfo.hasNextPage) { let cursor = pageInfo.endCursor; let hasNextPage = true; @@ -100,7 +104,7 @@ export default async function success(pluginConfig, context, { Octokit }) { const { associatedPullRequests } = repository.commit; responsePRs.push( ...buildIssuesOrPRsFromResponseNode( - associatedPullRequests.nodes, + associatedPullRequests.nodes.filter(isSameRepository), "PR", ), ); @@ -467,6 +471,9 @@ function buildAssociatedPRsQuery(shas) { } nodes { ${baseFields} + repository { + nameWithOwner + } mergeable changedFiles mergedAt @@ -506,6 +513,9 @@ const loadSingleCommitAssociatedPRs = `#graphql } nodes { ${baseFields} + repository { + nameWithOwner + } mergeable changedFiles mergedAt diff --git a/test/success.test.js b/test/success.test.js index e88e1b70..ff68168f 100644 --- a/test/success.test.js +++ b/test/success.test.js @@ -1306,7 +1306,7 @@ test("Do not add comment and labels for unrelated PR returned by search (compare t.true(fetch.done()); }); -test("Do not add comment and labels if no PR is associated with release commits", async (t) => { +test("Do not add comment and labels for PRs from another repository", async (t) => { const owner = "test_user"; const repo = "test_repo"; const env = { GITHUB_TOKEN: "github_token" }; @@ -1344,7 +1344,14 @@ test("Do not add comment and labels if no PR is associated with release commits" endCursor: "NI", hasNextPage: false, }, - nodes: [], + nodes: [ + { + number: 1, + __typename: "PullRequest", + state: "closed", + repository: { nameWithOwner: "other/repository" }, + }, + ], }, }, },