Skip to content

Commit

Permalink
feat(prepare): remove merge on opened PR by default
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-guibert committed Apr 7, 2024
1 parent ca2c1cb commit 361c83c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 42 deletions.
92 changes: 52 additions & 40 deletions __tests__/prepare.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,14 +686,7 @@ describe("main()", () => {
expect(octokit.rest.repos.generateReleaseNotes).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.getBranch).toHaveBeenCalledTimes(0);
expect(octokit.rest.git.createRef).toHaveBeenCalledTimes(0);
expect(octokit.rest.repos.merge).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.merge).toHaveBeenCalledWith({
owner: "owner",
repo: "repository",
base: "releases/next",
head: "main",
commit_message: 'chore(main): merge "main"',
});
expect(octokit.rest.repos.merge).toHaveBeenCalledTimes(0);
expect(fileSystem.readFileSync).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.getContent).toHaveBeenCalledTimes(0);
expect(
Expand Down Expand Up @@ -760,14 +753,7 @@ describe("main()", () => {
expect(octokit.rest.repos.generateReleaseNotes).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.getBranch).toHaveBeenCalledTimes(0);
expect(octokit.rest.git.createRef).toHaveBeenCalledTimes(0);
expect(octokit.rest.repos.merge).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.merge).toHaveBeenCalledWith({
owner: "owner",
repo: "repository",
base: "releases/next",
head: "main",
commit_message: 'chore(main): merge "main"',
});
expect(octokit.rest.repos.merge).toHaveBeenCalledTimes(0);
expect(fileSystem.readFileSync).toHaveBeenCalledTimes(2);
expect(fileSystem.readFileSync).toHaveBeenNthCalledWith(
2,
Expand Down Expand Up @@ -844,14 +830,7 @@ describe("main()", () => {
expect(octokit.rest.repos.generateReleaseNotes).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.getBranch).toHaveBeenCalledTimes(0);
expect(octokit.rest.git.createRef).toHaveBeenCalledTimes(0);
expect(octokit.rest.repos.merge).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.merge).toHaveBeenCalledWith({
owner: "owner",
repo: "repository",
base: "releases/next",
head: "main",
commit_message: 'chore(main): merge "main"',
});
expect(octokit.rest.repos.merge).toHaveBeenCalledTimes(0);
expect(fileSystem.readFileSync).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.getContent).toHaveBeenCalledTimes(0);
expect(
Expand Down Expand Up @@ -911,14 +890,7 @@ describe("main()", () => {
expect(octokit.rest.repos.generateReleaseNotes).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.getBranch).toHaveBeenCalledTimes(0);
expect(octokit.rest.git.createRef).toHaveBeenCalledTimes(0);
expect(octokit.rest.repos.merge).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.merge).toHaveBeenCalledWith({
owner: "owner",
repo: "repository",
base: "releases/next",
head: "main",
commit_message: 'chore(main): merge "main"',
});
expect(octokit.rest.repos.merge).toHaveBeenCalledTimes(0);
expect(fileSystem.readFileSync).toHaveBeenCalledTimes(2);
expect(octokit.rest.repos.getContent).toHaveBeenCalledTimes(1);
expect(
Expand Down Expand Up @@ -985,14 +957,7 @@ describe("main()", () => {
expect(octokit.rest.repos.generateReleaseNotes).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.getBranch).toHaveBeenCalledTimes(0);
expect(octokit.rest.git.createRef).toHaveBeenCalledTimes(0);
expect(octokit.rest.repos.merge).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.merge).toHaveBeenCalledWith({
owner: "owner",
repo: "repository",
base: "releases/next",
head: "main",
commit_message: 'chore(main): merge "main"',
});
expect(octokit.rest.repos.merge).toHaveBeenCalledTimes(0);
expect(fileSystem.readFileSync).toHaveBeenCalledTimes(2);
expect(fileSystem.readFileSync).toHaveBeenNthCalledWith(
2,
Expand All @@ -1014,5 +979,52 @@ describe("main()", () => {
});
expect(octokit.rest.issues.createComment).toHaveBeenCalledTimes(0);
});

it("should prepare when PR update requested", async () => {
mockPullRequestLists({
openRelease: pullRequests.openRelease,
changes: [
{
number: 7,
title: "title",
state: "closed",
labels: [
{ name: "label" },
{ name: "type: feature" },
{ name: "breaking" },
],
},
...changes,
],
});
inputs.keepPullRequestUpdated = true;

await main();

expect(core.setFailed).toHaveBeenCalledTimes(0);
expect(core.error).toHaveBeenCalledTimes(0);
expect(core.warning).toHaveBeenCalledTimes(0);
expect(core.notice).toHaveBeenCalledTimes(3);
expect(core.setOutput).toHaveBeenCalledTimes(5);
expect(octokit.rest.repos.generateReleaseNotes).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.getBranch).toHaveBeenCalledTimes(0);
expect(octokit.rest.git.createRef).toHaveBeenCalledTimes(0);
expect(octokit.rest.repos.merge).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.merge).toHaveBeenCalledWith({
owner: "owner",
repo: "repository",
base: "releases/next",
head: "main",
commit_message: 'chore(main): merge "main"',
});
expect(fileSystem.readFileSync).toHaveBeenCalledTimes(2);
expect(octokit.rest.repos.getContent).toHaveBeenCalledTimes(1);
expect(
octokit.rest.repos.createOrUpdateFileContents,
).toHaveBeenCalledTimes(1);
expect(octokit.rest.pulls.create).toHaveBeenCalledTimes(0);
expect(octokit.rest.pulls.update).toHaveBeenCalledTimes(1);
expect(octokit.rest.issues.createComment).toHaveBeenCalledTimes(0);
});
});
});
2 changes: 2 additions & 0 deletions src/libs/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const inputsSchema = z.object({
}),
}),
skipPullRequestCreation: z.boolean().default(false),
keepPullRequestUpdated: z.boolean().default(false),
});

export function parseEnvironment() {
Expand Down Expand Up @@ -130,6 +131,7 @@ export function parseInputs() {
release: getInput("branch-release"),
},
skipPullRequestCreation: getBooleanInput("skip-pr-creation"),
keepPullRequestUpdated: getBooleanInput("keep-pr-updated"),
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ export async function prepare(
isManualVersion: boolean,
) {
core.info(`Preparing new release...`);
if (releasePullRequest) {
if (releasePullRequest && inputs.keepPullRequestUpdated) {
await mergeIntoReleaseBranch();
} else {
} else if (!releasePullRequest) {
await mergeIntoOrTryCreateReleaseBranch();
}

Expand Down

0 comments on commit 361c83c

Please sign in to comment.