Skip to content

Commit

Permalink
fix: return pull number in create-pr (#132)
Browse files Browse the repository at this point in the history
* log the json result

* extract pull number

* cleanup

* chore: update tests
  • Loading branch information
aschwenn authored Feb 23, 2022
1 parent fb908b5 commit 8669962
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
5 changes: 4 additions & 1 deletion dist/150.index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/150.index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/helpers/create-pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ export const createPr = async ({ title, body }: CreatePR) => {
const {
data: { default_branch }
} = await octokit.repos.get({ ...context.repo });
return octokit.pulls.create({
const result = await octokit.pulls.create({
title,
head: context.ref.replace('refs/heads/', ''),
base: default_branch,
body,
maintainer_can_modify: true,
...context.repo
});
const pullNumber = result?.data?.number;
return pullNumber;
};
26 changes: 20 additions & 6 deletions test/helpers/create-pr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,29 @@ jest.mock('@actions/github', () => ({
default_branch: 'default branch'
}
}));
(octokit.pulls.create as unknown as Mocktokit).mockImplementation(async () => ({
data: {
number: 100
}
}));

describe('createPr', () => {
const title = 'title';
const body = 'body';

beforeEach(() => {
createPr({
it('should call repos get with correct params', async () => {
await createPr({
title,
body
});
});

it('should call repos get with correct params', () => {
expect(octokit.repos.get).toHaveBeenCalledWith({ ...context.repo });
});

it('should call create with correct params', () => {
it('should call create with correct params', async () => {
await createPr({
title,
body
});
expect(octokit.pulls.create).toHaveBeenCalledWith({
title,
head: 'source',
Expand All @@ -60,4 +66,12 @@ describe('createPr', () => {
...context.repo
});
});

it('should return the pull number', async () => {
const result = await createPr({
title,
body
});
expect(result).toBe(100);
});
});

0 comments on commit 8669962

Please sign in to comment.