Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/success.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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;
Expand All @@ -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",
),
);
Expand Down Expand Up @@ -467,6 +471,9 @@ function buildAssociatedPRsQuery(shas) {
}
nodes {
${baseFields}
repository {
nameWithOwner
}
mergeable
changedFiles
mergedAt
Expand Down Expand Up @@ -506,6 +513,9 @@ const loadSingleCommitAssociatedPRs = `#graphql
}
nodes {
${baseFields}
repository {
nameWithOwner
}
mergeable
changedFiles
mergedAt
Expand Down
11 changes: 9 additions & 2 deletions test/success.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand Down Expand Up @@ -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" },
},
],
},
},
},
Expand Down