-
Notifications
You must be signed in to change notification settings - Fork 146
fix: replace github search api with graphql in success lifecycle method #857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 31 commits
8929f7e
ce1c3e4
d24079c
76a2cd1
b9bbd1f
ca0bc4a
f3be681
1516ea3
1eaffe0
c58c3e2
6714074
0299e79
e229ad3
813969b
b7963d7
0d1f44f
d8b5396
703f7bb
c4f5df3
5585c3b
d336aa8
4b7c9a9
69e67cf
c909ed7
96f5e3a
db42a89
d97754d
d268e51
6ca26fc
791dc93
5ebd038
61eea50
9b2a923
9c58e02
737fd05
807c400
53c8024
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,6 @@ import debugFactory from "debug"; | |
| import parseGithubUrl from "./parse-github-url.js"; | ||
| import resolveConfig from "./resolve-config.js"; | ||
| import { toOctokitOptions } from "./octokit.js"; | ||
| import getSearchQueries from "./get-search-queries.js"; | ||
| import getSuccessComment from "./get-success-comment.js"; | ||
| import findSRIssues from "./find-sr-issues.js"; | ||
| import { RELEASE_NAME } from "./definitions/constants.js"; | ||
|
|
@@ -65,44 +64,38 @@ export default async function success(pluginConfig, context, { Octokit }) { | |
| const releaseInfos = releases.filter((release) => Boolean(release.name)); | ||
| const shas = commits.map(({ hash }) => hash); | ||
|
|
||
| const searchQueries = getSearchQueries( | ||
| `repo:${owner}/${repo}+type:pr+is:merged`, | ||
| shas, | ||
| ).map( | ||
| async (q) => | ||
| (await octokit.request("GET /search/issues", { q })).data.items, | ||
| const { repository } = await octokit.graphql( | ||
| buildAssociatedPRsQuery(shas), | ||
| { owner, repo }, | ||
| ); | ||
|
|
||
| const searchQueriesResults = await Promise.all(searchQueries); | ||
| const uniqueSearchQueriesResults = uniqBy( | ||
| flatten(searchQueriesResults), | ||
| "number", | ||
| const associatedPRs = Object.values(repository).map( | ||
| (item) => item.associatedPullRequests.nodes, | ||
| ); | ||
| const prs = await pFilter( | ||
| uniqueSearchQueriesResults, | ||
| async ({ number }) => { | ||
| const commits = await octokit.paginate( | ||
| "GET /repos/{owner}/{repo}/pulls/{pull_number}/commits", | ||
| { | ||
| owner, | ||
| repo, | ||
| pull_number: number, | ||
| }, | ||
| ); | ||
| const matchingCommit = commits.find(({ sha }) => shas.includes(sha)); | ||
| if (matchingCommit) return matchingCommit; | ||
|
|
||
| const { data: pullRequest } = await octokit.request( | ||
| "GET /repos/{owner}/{repo}/pulls/{pull_number}", | ||
| { | ||
| owner, | ||
| repo, | ||
| pull_number: number, | ||
| }, | ||
| ); | ||
| return shas.includes(pullRequest.merge_commit_sha); | ||
| }, | ||
| ); | ||
| const uniqueAssociatedPRs = uniqBy(flatten(associatedPRs), "number"); | ||
|
|
||
| const prs = await pFilter(uniqueAssociatedPRs, async ({ number }) => { | ||
| const commits = await octokit.paginate( | ||
| "GET /repos/{owner}/{repo}/pulls/{pull_number}/commits", | ||
| { | ||
| owner, | ||
| repo, | ||
| pull_number: number, | ||
| }, | ||
| ); | ||
| const matchingCommit = commits.find(({ sha }) => shas.includes(sha)); | ||
| if (matchingCommit) return matchingCommit; | ||
|
|
||
| const { data: pullRequest } = await octokit.request( | ||
| "GET /repos/{owner}/{repo}/pulls/{pull_number}", | ||
| { | ||
| owner, | ||
| repo, | ||
| pull_number: number, | ||
| }, | ||
| ); | ||
| return shas.includes(pullRequest.merge_commit_sha); | ||
| }); | ||
|
|
||
| debug( | ||
| "found pull requests: %O", | ||
|
|
@@ -250,3 +243,31 @@ export default async function success(pluginConfig, context, { Octokit }) { | |
| throw new AggregateError(errors); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Builds GraphQL query for fetching associated PRs to a list of commit hash (sha) | ||
| * @param {Array<string>} shas | ||
| * @returns {string} | ||
| */ | ||
| export function buildAssociatedPRsQuery(shas) { | ||
| return `#graphql | ||
| query getAssociatedPRs($owner: String!, $repo: String!) { | ||
| repository(owner: $owner, name: $repo) { | ||
| ${shas | ||
| .map((sha) => { | ||
| return `"commit${sha.slice(0, 6)}": object(oid: ${sha}) { | ||
| ...on Commit { | ||
| associatedPullRequests(first: 100) { | ||
| nodes { | ||
| url | ||
| number | ||
| } | ||
| } | ||
| } | ||
| }`; | ||
| }) | ||
| .join("")} | ||
| } | ||
| } | ||
|
Comment on lines
+254
to
+272
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unfortunately this is happening on an internal repo but ill do my best! @babblebey There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @babblebey im not able to reliable reproduce it at this point since re-running so will hold off on logging an issue. will revisit if it reappears!
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm currently working on a fix in regard the edge case here #892
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just capturing the relation to #867 (comment) as well |
||
| `; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.