Skip to content
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

fix: replace github search api with graphql in success lifecycle method #857

Merged
merged 37 commits into from
Jul 1, 2024
Merged
Changes from 3 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
8929f7e
chore: add `loadAssociatedPRsQuery` helper to generate gql query
babblebey Jun 13, 2024
ce1c3e4
feat: implement graphql in associatedPRs fetch
babblebey Jun 13, 2024
d24079c
Merge branch 'master' into refactor/replace-search-api
babblebey Jun 13, 2024
76a2cd1
build: add `assert` to devDeps
babblebey Jun 13, 2024
b9bbd1f
do: extracted `loadAssociatedPRsQuery` to separate function
babblebey Jun 13, 2024
ca0bc4a
do (test): current attemption situation
babblebey Jun 13, 2024
f3be681
nits: prepend string `commit` to gal query aliases
babblebey Jun 14, 2024
1516ea3
nits: rename associatedPRs gql query builder helper
babblebey Jun 14, 2024
1eaffe0
Merge branch 'master' into refactor/replace-search-api
babblebey Jun 14, 2024
c58c3e2
fix: typo in `success.js`
babblebey Jun 14, 2024
6714074
fix: address test case `Add comment and labels to PRs associated with…
babblebey Jun 14, 2024
0299e79
do: address test case `Add comment and labels to PRs associated with …
babblebey Jun 14, 2024
e229ad3
do: address test case `Do not add comment and labels for unrelated PR…
babblebey Jun 14, 2024
813969b
do: address test case `Do not add comment and labels if no PR is asso…
babblebey Jun 14, 2024
b7963d7
do: address test case `Do not add comment and labels to PR/issues fro…
babblebey Jun 14, 2024
0d1f44f
do: address test case `Ignore missing and forbidden issues/PRs`
babblebey Jun 14, 2024
d8b5396
do: address test case `Add custom comment and labels`
babblebey Jun 14, 2024
703f7bb
do: address test case `Add custom label`
babblebey Jun 14, 2024
c4f5df3
do: address test case `Comment on issue/PR without ading a label`
babblebey Jun 14, 2024
5585c3b
do: address test case `Editing the release to include all release lin…
babblebey Jun 14, 2024
d336aa8
do: address test case `Editing the release to include all release lin…
babblebey Jun 14, 2024
4b7c9a9
do: address test case `Editing the release to include all release lin…
babblebey Jun 14, 2024
69e67cf
do: address other test case except "Make multiple search queries if n…
babblebey Jun 14, 2024
c909ed7
Merge branch 'refactor/replace-search-api' of https://github.com/sema…
babblebey Jun 14, 2024
96f5e3a
fix: address test case `Make multiple search queries if necessary`
babblebey Jun 14, 2024
db42a89
nits: make tiny changes in `success.js`
babblebey Jun 14, 2024
d97754d
fix: address `integration` tests
babblebey Jun 14, 2024
d268e51
Revert "build: add `assert` to devDeps"
babblebey Jun 14, 2024
6ca26fc
refactor: replace `isArray` method with `Object.values`
babblebey Jun 14, 2024
791dc93
fix(build): fix lint issues
babblebey Jun 14, 2024
5ebd038
chore: drop `getSearchQueries` integration from `success.js` and depr…
babblebey Jun 14, 2024
61eea50
Merge branch 'master' into refactor/replace-search-api
babblebey Jun 19, 2024
9b2a923
chore: remove deprecated `getSearchQueries` helper
babblebey Jun 19, 2024
9c58e02
fix: modify `buildAssociatedPRsQuery` returned string
babblebey Jun 21, 2024
737fd05
Merge branch 'master' into refactor/replace-search-api
babblebey Jun 24, 2024
807c400
feat: retrieve `body` property for `associatedPRs`
babblebey Jun 24, 2024
53c8024
Merge branch 'master' into refactor/replace-search-api
gr2m Jul 1, 2024
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
86 changes: 73 additions & 13 deletions lib/success.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isNil, uniqBy, template, flatten, isEmpty } from "lodash-es";
import { isNil, uniqBy, template, flatten, isEmpty, toArray } from "lodash-es";
import pFilter from "p-filter";
import AggregateError from "aggregate-error";
import issueParser from "issue-parser";
Expand Down Expand Up @@ -65,21 +65,81 @@ 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 loadAssociatedPRsQuery = (shas) => `#graphql
query getAssociatedPRs($owner: String!, $repo: String!) {
repository(owner: $owner, name: $repo) {
${shas.map((sha) => {
return `"${sha.slice(0, 6)}": object(oid: ${sha}) {
...on Commit {
associatedPullRequests(first: 100) {
nodes {
url
number
}
}
}
}`
}).join("")}
}
}
`;

babblebey marked this conversation as resolved.
Show resolved Hide resolved
// MOCK ONLY
// const mockReponse = {
// "data": {
// "repository": {
// "com1": {
// "associatedPullRequests": {
// "nodes": [
// {
// "number": 2
// }
// ]
// }
// },
// "com2": {
// "associatedPullRequests": {
// "nodes": [
// {
// "number": 1
// }
// ]
// }
// }
// }
// }
// };
// console.log(somedata)

const searchQueriesResults = await Promise.all(searchQueries);
const uniqueSearchQueriesResults = uniqBy(
flatten(searchQueriesResults),
const { data } = await octokit.graphql(loadAssociatedPRsQuery(shas), { owner, repo });

const associatedPRs = toArray(mockReponse.data.repository).map((item) => item.associatedPullRequests.nodes);
// console.log("norm: ", mockPRNodes);
babblebey marked this conversation as resolved.
Show resolved Hide resolved
babblebey marked this conversation as resolved.
Show resolved Hide resolved

// const searchQueries = getSearchQueries(
// `repo:${owner}/${repo}+type:pr+is:merged`,
// shas,
// ).map(
// async (q) =>
// (await octokit.request("GET /search/issues", { q })).data.items,
// );

// const searchQueriesResults = await Promise.all(searchQueries);
// console.log("searchQueriesResults: ", searchQueriesResults);
// const uniqueSearchQueriesResults = uniqBy(
// flatten(searchQueriesResults),
// "number",
// );
// console.log("uniqueSearchQueriesResults: ", uniqueSearchQueriesResults);

const uniqueAssociatedPRs = uniqBy(
flatten(associatedPRs),
"number",
);
// console.log(uniquePRs);

const prs = await pFilter(
uniqueSearchQueriesResults,
uniqueAssociatedPRs,
async ({ number }) => {
const commits = await octokit.paginate(
"GET /repos/{owner}/{repo}/pulls/{pull_number}/commits",
Expand Down Expand Up @@ -249,4 +309,4 @@ export default async function success(pluginConfig, context, { Octokit }) {
if (errors.length > 0) {
throw new AggregateError(errors);
}
}
}
Loading