diff --git a/.changeset/clean-bees-count.md b/.changeset/clean-bees-count.md new file mode 100644 index 00000000..27f95943 --- /dev/null +++ b/.changeset/clean-bees-count.md @@ -0,0 +1,5 @@ +--- +"@changesets/action": patch +--- + +Ensure the PR remains open when updated diff --git a/.changeset/green-eels-appear.md b/.changeset/green-eels-appear.md new file mode 100644 index 00000000..f2d1609f --- /dev/null +++ b/.changeset/green-eels-appear.md @@ -0,0 +1,5 @@ +--- +"@changesets/action": patch +--- + +Switch to cheaper API for querying existing PRs diff --git a/src/run.test.ts b/src/run.test.ts index ff9ccfdf..15d2e096 100644 --- a/src/run.test.ts +++ b/src/run.test.ts @@ -33,11 +33,9 @@ jest.mock("@actions/github/lib/utils", () => ({ jest.mock("./gitUtils"); let mockedGithubMethods = { - search: { - issuesAndPullRequests: jest.fn(), - }, pulls: { create: jest.fn(), + list: jest.fn(), }, repos: { createRelease: jest.fn(), @@ -65,9 +63,7 @@ describe("version", () => { let cwd = f.copy("simple-project"); linkNodeModules(cwd); - mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce( - () => ({ data: { items: [] } }) - ); + mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] })); mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({ data: { number: 123 }, @@ -104,9 +100,7 @@ describe("version", () => { let cwd = f.copy("simple-project"); linkNodeModules(cwd); - mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce( - () => ({ data: { items: [] } }) - ); + mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] })); mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({ data: { number: 123 }, @@ -139,9 +133,7 @@ describe("version", () => { let cwd = f.copy("ignored-package"); linkNodeModules(cwd); - mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce( - () => ({ data: { items: [] } }) - ); + mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] })); mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({ data: { number: 123 }, @@ -174,9 +166,7 @@ describe("version", () => { let cwd = f.copy("simple-project"); linkNodeModules(cwd); - mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce( - () => ({ data: { items: [] } }) - ); + mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] })); mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({ data: { number: 123 }, @@ -233,9 +223,7 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis. let cwd = f.copy("simple-project"); linkNodeModules(cwd); - mockedGithubMethods.search.issuesAndPullRequests.mockImplementationOnce( - () => ({ data: { items: [] } }) - ); + mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] })); mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({ data: { number: 123 }, diff --git a/src/run.ts b/src/run.ts index ea346bf6..326b9618 100644 --- a/src/run.ts +++ b/src/run.ts @@ -342,9 +342,11 @@ export async function runVersion({ }); } - let searchQuery = `repo:${repo}+state:open+head:${versionBranch}+base:${branch}+is:pull-request`; - let searchResultPromise = octokit.rest.search.issuesAndPullRequests({ - q: searchQuery, + const existingPullRequestsPromise = octokit.rest.pulls.list({ + ...github.context.repo, + state: "open", + head: `${github.context.repo.owner}:${versionBranch}`, + base: branch, }); let changedPackages = await getChangedPackages(cwd, versionsByDirectory); let changedPackagesInfoPromises = Promise.all( @@ -376,8 +378,8 @@ export async function runVersion({ await gitUtils.push(versionBranch, { force: true }); - let searchResult = await searchResultPromise; - core.info(JSON.stringify(searchResult.data, null, 2)); + let existingPullRequests = await existingPullRequestsPromise; + core.info(JSON.stringify(existingPullRequests.data, null, 2)); const changedPackagesInfo = (await changedPackagesInfoPromises) .filter((x) => x) @@ -391,7 +393,7 @@ export async function runVersion({ prBodyMaxCharacters, }); - if (searchResult.data.items.length === 0) { + if (existingPullRequests.data.length === 0) { core.info("creating pull request"); const { data: newPullRequest } = await octokit.rest.pulls.create({ base: branch, @@ -405,7 +407,7 @@ export async function runVersion({ pullRequestNumber: newPullRequest.number, }; } else { - const [pullRequest] = searchResult.data.items; + const [pullRequest] = existingPullRequests.data; core.info(`updating found pull request #${pullRequest.number}`); await octokit.rest.pulls.update({ @@ -413,6 +415,7 @@ export async function runVersion({ title: finalPrTitle, body: prBody, ...github.context.repo, + state: "open", }); return {