Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7cde776

Browse filesBrowse files
babblebeygr2m
andauthored
fix(success): PRs not recognized as resolved issues (#960)
* feat(success): enhance `buildRelatedIssuesQuery` to include additional fields for `PullRequest` * feat(success): refactor `buildIssuesOrPRsFromResponseNode` to remove `type` parameter and include `__typename` in queries to use in its place * update doc * fix(success): correct `buildRelatedIssuesQuery` to use `issueOrPullRequest` for improved query flexibility * feat(tests): add `__typename` field to issues and pull requests in success tests for improved type handling * feat(tests): update test data to include `__typename` for PullRequest in integration tests --------- Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
1 parent 0128403 commit 7cde776
Copy full SHA for 7cde776

File tree

3 files changed

+73
-40
lines changed
Filter options

3 files changed

+73
-40
lines changed

‎lib/success.js

Copy file name to clipboardExpand all lines: lib/success.js
+24-7Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export default async function success(pluginConfig, context, { Octokit }) {
8888
for (const { nodes, pageInfo } of responseAssociatedPRs) {
8989
if (nodes.length === 0) continue;
9090

91-
responsePRs.push(...buildIssuesOrPRsFromResponseNode(nodes, "PR"));
91+
responsePRs.push(...buildIssuesOrPRsFromResponseNode(nodes));
9292
if (pageInfo.hasNextPage) {
9393
let cursor = pageInfo.endCursor;
9494
let hasNextPage = true;
@@ -171,7 +171,7 @@ export default async function success(pluginConfig, context, { Octokit }) {
171171
if (!isEmpty(parsedIssues)) {
172172
const uniqueParsedIssues = uniqBy(flatten(parsedIssues), "number");
173173

174-
// Get relatedIssues
174+
// Get relatedIssues (or relatedPRs i.e. Issues/PRs that are closed by an associatedPR)
175175
issues = await inChunks(uniqueParsedIssues, 100, async (chunk) => {
176176
const { repository } = await octokit.graphql(
177177
buildRelatedIssuesQuery(chunk.map((issue) => issue.number)),
@@ -360,6 +360,7 @@ async function inChunks(items, chunkSize, callback) {
360360
* Fields common accross PRs and Issue
361361
*/
362362
const baseFields = `
363+
__typename
363364
id
364365
title
365366
body
@@ -420,8 +421,25 @@ function buildRelatedIssuesQuery(numbers) {
420421
repository(owner: $owner, name: $repo) {
421422
${numbers
422423
.map((num) => {
423-
return `issue${num}: issue(number: ${num}) {
424-
${baseFields}
424+
return `issue${num}: issueOrPullRequest(number: ${num}) {
425+
... on Issue {
426+
${baseFields}
427+
}
428+
... on PullRequest {
429+
${baseFields}
430+
mergeable
431+
changedFiles
432+
mergedAt
433+
isDraft
434+
mergedBy {
435+
login
436+
avatarUrl
437+
url
438+
}
439+
commits {
440+
totalCount
441+
}
442+
}
425443
}`;
426444
})
427445
.join("")}
@@ -513,10 +531,9 @@ const loadSingleCommitAssociatedPRs = `#graphql
513531
/**
514532
* Build associatedPRs or RelatedIssues object (into issue-like object with `pull_request` property) from the GraphQL repository response
515533
* @param {object} responseNodes
516-
* @param {"ISSUE" | "PR"} type
517534
* @returns {object[]}
518535
*/
519-
function buildIssuesOrPRsFromResponseNode(responseNodes, type = "ISSUE") {
536+
function buildIssuesOrPRsFromResponseNode(responseNodes) {
520537
const resultArray = [];
521538
for (const node of responseNodes) {
522539
let baseProps = {
@@ -569,7 +586,7 @@ function buildIssuesOrPRsFromResponseNode(responseNodes, type = "ISSUE") {
569586

570587
let result = baseProps;
571588

572-
if (type === "PR") {
589+
if (node.__typename === "PullRequest") {
573590
const prProps = {
574591
pull_request: true,
575592
mergeable: node.mergeable,

‎test/integration.test.js

Copy file name to clipboardExpand all lines: test/integration.test.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ test("Comment and add labels on PR included in the releases", async (t) => {
433433
const repo = "test_repo";
434434
const env = { GITHUB_TOKEN: "github_token" };
435435
const failTitle = "The automated release is failing 🚨";
436-
const prs = [{ number: 1, pull_request: true, state: "closed" }];
436+
const prs = [{ number: 1, __typename: "PullRequest", state: "closed" }];
437437
const options = {
438438
repositoryUrl: `https://github.com/${owner}/${repo}.git`,
439439
};

‎test/success.test.js

Copy file name to clipboardExpand all lines: test/success.test.js
+48-32Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ test("Add comment and labels to PRs associated with release commits and issues s
3333
const failTitle = "The automated release is failing 🚨";
3434
const pluginConfig = { failTitle };
3535
const prs = [
36-
{ number: 1, pull_request: true, state: "closed" },
37-
{ number: 2, pull_request: true, body: "Fixes #3", state: "closed" },
36+
{ number: 1, __typename: "PullRequest", state: "closed" },
37+
{ number: 2, __typename: "PullRequest", body: "Fixes #3", state: "closed" },
3838
];
3939
const options = {
4040
branch: "master",
@@ -103,6 +103,7 @@ test("Add comment and labels to PRs associated with release commits and issues s
103103
data: {
104104
repository: {
105105
issue3: {
106+
__typename: "Issue",
106107
id: "I_kw",
107108
title: "issue title",
108109
body: "",
@@ -139,6 +140,7 @@ test("Add comment and labels to PRs associated with release commits and issues s
139140
locked: false,
140141
},
141142
issue4: {
143+
__typename: "Issue",
142144
id: "I_kw",
143145
title: "issue title",
144146
body: "",
@@ -317,10 +319,10 @@ test("Add comment and labels to PRs associated with release commits and issues (
317319
const failTitle = "The automated release is failing 🚨";
318320
const pluginConfig = { failTitle };
319321
const prs = [
320-
{ number: 1, pull_request: true, state: "closed" },
321-
{ number: 2, pull_request: true, body: "Fixes #3", state: "closed" },
322-
{ number: 5, pull_request: true, state: "closed" },
323-
{ number: 6, pull_request: true, state: "closed" },
322+
{ number: 1, __typename: "PullRequest", state: "closed" },
323+
{ number: 2, __typename: "PullRequest", body: "Fixes #3", state: "closed" },
324+
{ number: 5, __typename: "PullRequest", state: "closed" },
325+
{ number: 6, __typename: "PullRequest", state: "closed" },
324326
];
325327
const options = {
326328
branch: "master",
@@ -414,6 +416,7 @@ test("Add comment and labels to PRs associated with release commits and issues (
414416
data: {
415417
repository: {
416418
issue3: {
419+
__typename: "Issue",
417420
id: "I_kw",
418421
title: "issue title",
419422
body: "",
@@ -450,6 +453,7 @@ test("Add comment and labels to PRs associated with release commits and issues (
450453
locked: false,
451454
},
452455
issue4: {
456+
__typename: "Issue",
453457
id: "I_kw",
454458
title: "issue title",
455459
body: "",
@@ -607,8 +611,8 @@ test("Add comment and labels to PRs associated with release commits and issues c
607611
const failTitle = "The automated release is failing 🚨";
608612
const pluginConfig = { failTitle };
609613
const prs = [
610-
{ number: 1, pull_request: true, state: "closed" },
611-
{ number: 2, pull_request: true, body: "Fixes #3", state: "closed" },
614+
{ number: 1, __typename: "PullRequest", state: "closed" },
615+
{ number: 2, __typename: "PullRequest", body: "Fixes #3", state: "closed" },
612616
];
613617
const options = {
614618
branch: "master",
@@ -671,6 +675,7 @@ test("Add comment and labels to PRs associated with release commits and issues c
671675
data: {
672676
repository: {
673677
issue3: {
678+
__typename: "Issue",
674679
id: "I_kw",
675680
title: "issue title",
676681
body: "",
@@ -707,6 +712,7 @@ test("Add comment and labels to PRs associated with release commits and issues c
707712
locked: false,
708713
},
709714
issue4: {
715+
__typename: "Issue",
710716
id: "I_kw",
711717
title: "issue title",
712718
body: "",
@@ -905,12 +911,12 @@ test("Make multiple search queries if necessary", async (t) => {
905911
const failTitle = "The automated release is failing 🚨";
906912
const pluginConfig = { failTitle };
907913
const prs = [
908-
{ number: 1, pull_request: true, state: "closed" },
909-
{ number: 2, pull_request: true, state: "closed" },
910-
{ number: 3, pull_request: true, state: "closed" },
911-
{ number: 4, pull_request: true, state: "closed" },
912-
{ number: 5, pull_request: true, state: "closed" },
913-
{ number: 6, pull_request: true, state: "closed" },
914+
{ number: 1, __typename: "PullRequest", state: "closed" },
915+
{ number: 2, __typename: "PullRequest", state: "closed" },
916+
{ number: 3, __typename: "PullRequest", state: "closed" },
917+
{ number: 4, __typename: "PullRequest", state: "closed" },
918+
{ number: 5, __typename: "PullRequest", state: "closed" },
919+
{ number: 6, __typename: "PullRequest", state: "closed" },
914920
];
915921
const options = {
916922
branch: "master",
@@ -1210,8 +1216,8 @@ test("Do not add comment and labels for unrelated PR returned by search (compare
12101216
const failTitle = "The automated release is failing 🚨";
12111217
const pluginConfig = { failTitle };
12121218
const prs = [
1213-
{ number: 1, pull_request: true, state: "closed" },
1214-
{ number: 2, pull_request: true, state: "closed" },
1219+
{ number: 1, __typename: "PullRequest", state: "closed" },
1220+
{ number: 2, __typename: "PullRequest", state: "closed" },
12151221
];
12161222
const options = {
12171223
branch: "master",
@@ -1677,9 +1683,9 @@ test("Ignore missing and forbidden issues/PRs", async (t) => {
16771683
const failTitle = "The automated release is failing 🚨";
16781684
const pluginConfig = { failTitle };
16791685
const prs = [
1680-
{ number: 1, pull_request: true, state: "closed" },
1681-
{ number: 2, pull_request: true, body: "Fixes #4", state: "closed" },
1682-
{ number: 3, pull_request: true, body: "Fixes #5", state: "closed" },
1686+
{ number: 1, __typename: "PullRequest", state: "closed" },
1687+
{ number: 2, __typename: "PullRequest", body: "Fixes #4", state: "closed" },
1688+
{ number: 3, __typename: "PullRequest", body: "Fixes #5", state: "closed" },
16831689
];
16841690
const options = {
16851691
branch: "master",
@@ -1750,6 +1756,7 @@ test("Ignore missing and forbidden issues/PRs", async (t) => {
17501756
data: {
17511757
repository: {
17521758
issue4: {
1759+
__typename: "Issue",
17531760
id: "I_kw",
17541761
title: "issue title",
17551762
body: "",
@@ -1786,6 +1793,7 @@ test("Ignore missing and forbidden issues/PRs", async (t) => {
17861793
locked: false,
17871794
},
17881795
issue5: {
1796+
__typename: "Issue",
17891797
id: "I_kw",
17901798
title: "issue title",
17911799
body: "",
@@ -1822,6 +1830,7 @@ test("Ignore missing and forbidden issues/PRs", async (t) => {
18221830
locked: false,
18231831
},
18241832
issue1: {
1833+
__typename: "Issue",
18251834
id: "I_kw",
18261835
title: "issue title",
18271836
body: "",
@@ -2008,7 +2017,7 @@ test("Add custom comment and labels", async (t) => {
20082017
],
20092018
};
20102019
const prs = [
2011-
{ number: 1, prop: "PR prop", pull_request: true, state: "closed" },
2020+
{ number: 1, prop: "PR prop", __typename: "PullRequest", state: "closed" },
20122021
];
20132022
const options = { repositoryUrl: `https://github.com/${owner}/${repo}.git` };
20142023
const lastRelease = { version: "1.0.0" };
@@ -2129,7 +2138,7 @@ test("Add custom label", async (t) => {
21292138
const env = { GITHUB_TOKEN: "github_token" };
21302139
const failTitle = "The automated release is failing 🚨";
21312140
const pluginConfig = { releasedLabels: ["custom label"], failTitle };
2132-
const prs = [{ number: 1, pull_request: true, state: "closed" }];
2141+
const prs = [{ number: 1, __typename: "PullRequest", state: "closed" }];
21332142
const options = { repositoryUrl: `https://github.com/${owner}/${repo}.git` };
21342143
const lastRelease = { version: "1.0.0" };
21352144
const commits = [{ hash: "123", message: "Commit 1 message" }];
@@ -2242,7 +2251,7 @@ test("Comment on issue/PR without ading a label", async (t) => {
22422251
const env = { GITHUB_TOKEN: "github_token" };
22432252
const failTitle = "The automated release is failing 🚨";
22442253
const pluginConfig = { releasedLabels: false, failTitle };
2245-
const prs = [{ number: 1, pull_request: true, state: "closed" }];
2254+
const prs = [{ number: 1, __typename: "PullRequest", state: "closed" }];
22462255
const options = { repositoryUrl: `https://github.com/${owner}/${repo}.git` };
22472256
const lastRelease = { version: "1.0.0" };
22482257
const commits = [{ hash: "123", message: "Commit 1 message" }];
@@ -2347,7 +2356,7 @@ test("Editing the release to include all release links at the bottom", async (t)
23472356
const env = { GITHUB_TOKEN: "github_token" };
23482357
const failTitle = "The automated release is failing 🚨";
23492358
const pluginConfig = { releasedLabels: false, addReleases: "bottom" };
2350-
const prs = [{ number: 1, pull_request: true, state: "closed" }];
2359+
const prs = [{ number: 1, __typename: "PullRequest", state: "closed" }];
23512360
const options = {
23522361
repositoryUrl: `https://github.com/${owner}/${repo}.git`,
23532362
};
@@ -2478,7 +2487,7 @@ test("Editing the release to include all release links at the top", async (t) =>
24782487
const env = { GITHUB_TOKEN: "github_token" };
24792488
const failTitle = "The automated release is failing 🚨";
24802489
const pluginConfig = { releasedLabels: false, addReleases: "top" };
2481-
const prs = [{ number: 1, pull_request: true, state: "closed" }];
2490+
const prs = [{ number: 1, __typename: "PullRequest", state: "closed" }];
24822491
const options = {
24832492
repositoryUrl: `https://github.com/${owner}/${repo}.git`,
24842493
};
@@ -2609,7 +2618,7 @@ test("Editing the release to include all release links with no additional releas
26092618
const env = { GITHUB_TOKEN: "github_token" };
26102619
const failTitle = "The automated release is failing 🚨";
26112620
const pluginConfig = { releasedLabels: false, addReleases: "top" };
2612-
const prs = [{ number: 1, pull_request: true, state: "closed" }];
2621+
const prs = [{ number: 1, __typename: "PullRequest", state: "closed" }];
26132622
const options = {
26142623
repositoryUrl: `https://github.com/${owner}/${repo}.git`,
26152624
};
@@ -2726,7 +2735,7 @@ test("Editing the release to include all release links with no additional releas
27262735
const env = { GITHUB_TOKEN: "github_token" };
27272736
const failTitle = "The automated release is failing 🚨";
27282737
const pluginConfig = { releasedLabels: false, addReleases: "bottom" };
2729-
const prs = [{ number: 1, pull_request: true, state: "closed" }];
2738+
const prs = [{ number: 1, __typename: "PullRequest", state: "closed" }];
27302739
const options = {
27312740
repositoryUrl: `https://github.com/${owner}/${repo}.git`,
27322741
};
@@ -2843,7 +2852,7 @@ test("Editing the release to include all release links with no releases", async
28432852
const env = { GITHUB_TOKEN: "github_token" };
28442853
const failTitle = "The automated release is failing 🚨";
28452854
const pluginConfig = { releasedLabels: false, addReleases: "bottom" };
2846-
const prs = [{ number: 1, pull_request: true, state: "closed" }];
2855+
const prs = [{ number: 1, __typename: "PullRequest", state: "closed" }];
28472856
const options = {
28482857
repositoryUrl: `https://github.com/${owner}/${repo}.git`,
28492858
};
@@ -2953,7 +2962,7 @@ test("Editing the release with no ID in the release", async (t) => {
29532962
const env = { GITHUB_TOKEN: "github_token" };
29542963
const failTitle = "The automated release is failing 🚨";
29552964
const pluginConfig = { releasedLabels: false, addReleases: "bottom" };
2956-
const prs = [{ number: 1, pull_request: true, state: "closed" }];
2965+
const prs = [{ number: 1, __typename: "PullRequest", state: "closed" }];
29572966
const options = { repositoryUrl: `https://github.com/${owner}/${repo}.git` };
29582967
const nextRelease = {
29592968
version: "2.0.0",
@@ -3071,8 +3080,8 @@ test("Ignore errors when adding comments and closing issues", async (t) => {
30713080
{ number: 3, body: `Issue 3 body\n\n${ISSUE_ID}`, title: failTitle },
30723081
];
30733082
const prs = [
3074-
{ number: 1, pull_request: true, state: "closed" },
3075-
{ number: 2, pull_request: true, state: "closed" },
3083+
{ number: 1, __typename: "PullRequest", state: "closed" },
3084+
{ number: 2, __typename: "PullRequest", state: "closed" },
30763085
];
30773086
const options = {
30783087
repositoryUrl: `https://github.com/${owner}/${repo}.git`,
@@ -3524,6 +3533,7 @@ test('Add comment and label to found issues/associatedPR using the "successComme
35243533

35253534
const prs = [
35263535
{
3536+
__typename: "PullRequest",
35273537
id: "PR_kwDOMLlZj85z_R2M",
35283538
title: "fix: will semantic-release recognize the associated issue ",
35293539
body: "",
@@ -3574,6 +3584,7 @@ test('Add comment and label to found issues/associatedPR using the "successComme
35743584
},
35753585
},
35763586
{
3587+
__typename: "PullRequest",
35773588
id: "PR_kwDOMLlZj85z_R2M",
35783589
title: "fix: will semantic-release recognize the associated issue ",
35793590
body: "",
@@ -3775,6 +3786,7 @@ test('Does not comment/label associatedPR and relatedIssues created by "Bots"',
37753786
];
37763787
const prs = [
37773788
{
3789+
__typename: "PullRequest",
37783790
number: 2,
37793791
id: "PR_kwDOMLlZj851SZzc",
37803792
title: "pr title",
@@ -3823,6 +3835,7 @@ test('Does not comment/label associatedPR and relatedIssues created by "Bots"',
38233835
},
38243836
},
38253837
{
3838+
__typename: "PullRequest",
38263839
number: 3,
38273840
id: "PR_kwDOMLlZj851SZzc",
38283841
title: "pr title",
@@ -3916,6 +3929,7 @@ test('Does not comment/label associatedPR and relatedIssues created by "Bots"',
39163929
data: {
39173930
repository: {
39183931
issue4: {
3932+
__typename: "Issue",
39193933
id: "I_kw",
39203934
title: "issue title",
39213935
body: "",
@@ -3952,6 +3966,7 @@ test('Does not comment/label associatedPR and relatedIssues created by "Bots"',
39523966
locked: false,
39533967
},
39543968
issue5: {
3969+
__typename: "Issue",
39553970
id: "I_kw",
39563971
title: "issue title",
39573972
body: "",
@@ -4120,8 +4135,8 @@ test('Does not comment/label "associatedPR" when "successCommentCondition" disab
41204135
},
41214136
];
41224137
const prs = [
4123-
{ number: 2, pull_request: true, body: "Fixes #4", state: "closed" },
4124-
{ number: 3, pull_request: true, state: "closed" },
4138+
{ number: 2, __typename: "PullRequest", body: "Fixes #4", state: "closed" },
4139+
{ number: 3, __typename: "PullRequest", state: "closed" },
41254140
];
41264141

41274142
const fetch = fetchMock
@@ -4168,6 +4183,7 @@ test('Does not comment/label "associatedPR" when "successCommentCondition" disab
41684183
data: {
41694184
repository: {
41704185
issue4: {
4186+
__typename: "Issue",
41714187
id: "I_kw",
41724188
title: "issue title",
41734189
body: "",

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.