Skip to content

Commit 4d43566

Browse files
committed
Now request all issue and review comments from PRs…
1 parent 603d399 commit 4d43566

File tree

2 files changed

+23
-27
lines changed

2 files changed

+23
-27
lines changed

app/src/lib/api.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ export class API {
11681168
}
11691169
}
11701170

1171-
/** Fetches all comments from a given pull request. */
1171+
/** Fetches all review comments from a given pull request. */
11721172
public async fetchPullRequestComments(
11731173
owner: string,
11741174
name: string,
@@ -1187,6 +1187,25 @@ export class API {
11871187
}
11881188
}
11891189

1190+
/** Fetches all comments from a given issue. */
1191+
public async fetchIssueComments(
1192+
owner: string,
1193+
name: string,
1194+
issueNumber: string
1195+
) {
1196+
try {
1197+
const path = `/repos/${owner}/${name}/issues/${issueNumber}/comments`
1198+
const response = await this.request('GET', path)
1199+
return await parsedResponse<IAPIComment[]>(response)
1200+
} catch (e) {
1201+
log.debug(
1202+
`failed fetching issue comments for ${owner}/${name}/issues/${issueNumber}`,
1203+
e
1204+
)
1205+
return []
1206+
}
1207+
}
1208+
11901209
/**
11911210
* Get the combined status for the given ref.
11921211
*/

app/src/lib/stores/notifications-debug-store.ts

+3-26
Original file line numberDiff line numberDiff line change
@@ -76,42 +76,19 @@ export class NotificationsDebugStore {
7676

7777
const ghRepository = repository.gitHubRepository
7878

79-
const issueComments = await api.fetchPullRequestComments(
79+
const issueComments = await api.fetchIssueComments(
8080
ghRepository.owner.login,
8181
ghRepository.name,
8282
pullRequestNumber.toString()
8383
)
8484

85-
const issueCommentIds = new Set(issueComments.map(c => c.id))
86-
87-
// Fetch review comments of type COMMENTED and with no body
88-
const allReviews = await api.fetchPullRequestReviews(
85+
const reviewComments = await api.fetchPullRequestComments(
8986
ghRepository.owner.login,
9087
ghRepository.name,
9188
pullRequestNumber.toString()
9289
)
9390

94-
const commentedReviewsWithNoBody = allReviews.filter(
95-
review => review.state === 'COMMENTED' && !review.body
96-
)
97-
98-
const allReviewComments = await Promise.all(
99-
commentedReviewsWithNoBody.map(review =>
100-
api.fetchPullRequestReviewComments(
101-
ghRepository.owner.login,
102-
ghRepository.name,
103-
pullRequestNumber.toString(),
104-
review.id.toString()
105-
)
106-
)
107-
)
108-
109-
// Only reviews with one comment, and that comment is not an issue comment
110-
const singleReviewComments = allReviewComments
111-
.flatMap(comments => (comments.length === 1 ? comments : []))
112-
.filter(comment => !issueCommentIds.has(comment.id))
113-
114-
return [...issueComments, ...singleReviewComments]
91+
return [...issueComments, ...reviewComments]
11592
}
11693

11794
/** Simulate a notification for the given pull request review. */

0 commit comments

Comments
 (0)