Skip to content

Commit

Permalink
fix: add check to make sure that the head and the base are different (#…
Browse files Browse the repository at this point in the history
…115)

Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
  • Loading branch information
tupe12334 and gr2m committed Jan 21, 2023
1 parent 42e275a commit 10e9a30
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/compose-create-pull-request.ts
Expand Up @@ -20,6 +20,11 @@ export async function composeCreatePullRequest(
update = false,
}: Options
) {
if (head === base) {
throw new Error(
'[octokit-plugin-create-pull-request] "head" cannot be the same value as "base"'
);
}
const changes = Array.isArray(changesOption)
? changesOption
: [changesOption];
Expand Down
31 changes: 31 additions & 0 deletions test/base-head-same-value.test.ts
@@ -0,0 +1,31 @@
import { Octokit as Core } from "@octokit/core";
import { createPullRequest } from "../src";

const Octokit = Core.plugin(createPullRequest);

test("Base and Head equality", async () => {
const octokit = new Octokit();

try {
await octokit.createPullRequest({
owner: "gr2m",
repo: "pull-request-test",
title: "One comes, one goes",
body: "because",
base: "patch",
head: "patch",
changes: {
files: {
"path/to/file1.txt": "Content for file1",
"path/to/file2.txt": "Content for file2",
},
commit: "why",
},
});
throw new Error("Should not resolve");
} catch (error) {
expect((error as Error).message).toEqual(
'[octokit-plugin-create-pull-request] "head" cannot be the same value as "base"'
);
}
});

0 comments on commit 10e9a30

Please sign in to comment.