diff --git a/dist/150.index.js b/dist/150.index.js index 8ea69f661..5a28cb76f 100644 --- a/dist/150.index.js +++ b/dist/150.index.js @@ -44,8 +44,11 @@ class CreatePR { } } const createPr = ({ title, body }) => __awaiter(void 0, void 0, void 0, function* () { + var _a; const { data: { default_branch } } = yield _octokit__WEBPACK_IMPORTED_MODULE_1__/* .octokit.repos.get */ .K.repos.get(Object.assign({}, _actions_github__WEBPACK_IMPORTED_MODULE_0__.context.repo)); - return _octokit__WEBPACK_IMPORTED_MODULE_1__/* .octokit.pulls.create */ .K.pulls.create(Object.assign({ title, head: _actions_github__WEBPACK_IMPORTED_MODULE_0__.context.ref.replace('refs/heads/', ''), base: default_branch, body, maintainer_can_modify: true }, _actions_github__WEBPACK_IMPORTED_MODULE_0__.context.repo)); + const result = yield _octokit__WEBPACK_IMPORTED_MODULE_1__/* .octokit.pulls.create */ .K.pulls.create(Object.assign({ title, head: _actions_github__WEBPACK_IMPORTED_MODULE_0__.context.ref.replace('refs/heads/', ''), base: default_branch, body, maintainer_can_modify: true }, _actions_github__WEBPACK_IMPORTED_MODULE_0__.context.repo)); + const pullNumber = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.number; + return pullNumber; }); diff --git a/dist/150.index.js.map b/dist/150.index.js.map index 12810fca0..f2d92d40d 100644 --- a/dist/150.index.js.map +++ b/dist/150.index.js.map @@ -1 +1 @@ -{"version":3,"file":"150.index.js","mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;;;;;;;;;;AAEA;AACA;AAEA;AAAA;AACA;AACA;AACA;AAAA;AAEA;AACA;AAGA;AAQA;;;;;;;;;;;;;;;ACjCA;;;;;;;;;;;AAWA;AAEA;AAEA;AAEA","sources":["webpack://github-helpers/./src/helpers/create-pr.ts","webpack://github-helpers/./src/octokit.ts"],"sourcesContent":["/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\n\nexport class CreatePR {\n title = '';\n body = '';\n}\n\nexport const createPr = async ({ title, body }: CreatePR) => {\n const {\n data: { default_branch }\n } = await octokit.repos.get({ ...context.repo });\n return octokit.pulls.create({\n title,\n head: context.ref.replace('refs/heads/', ''),\n base: default_branch,\n body,\n maintainer_can_modify: true,\n ...context.repo\n });\n};\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport * as core from '@actions/core';\nimport { Octokit } from '@octokit/rest';\nimport { getOctokit } from '@actions/github';\n\nexport const octokit = getOctokit(core.getInput('github_token', { required: true })).rest as unknown as Octokit;\n"],"names":[],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"150.index.js","mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;;;;;;;;;;AAEA;AACA;AAEA;AAAA;AACA;AACA;AACA;AAAA;AAEA;;AACA;AAGA;AAQA;AACA;AACA;;;;;;;;;;;;;;;ACnCA;;;;;;;;;;;AAWA;AAEA;AAEA;AAEA","sources":["webpack://github-helpers/./src/helpers/create-pr.ts","webpack://github-helpers/./src/octokit.ts"],"sourcesContent":["/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\n\nexport class CreatePR {\n title = '';\n body = '';\n}\n\nexport const createPr = async ({ title, body }: CreatePR) => {\n const {\n data: { default_branch }\n } = await octokit.repos.get({ ...context.repo });\n const result = await octokit.pulls.create({\n title,\n head: context.ref.replace('refs/heads/', ''),\n base: default_branch,\n body,\n maintainer_can_modify: true,\n ...context.repo\n });\n const pullNumber = result?.data?.number;\n return pullNumber;\n};\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport * as core from '@actions/core';\nimport { Octokit } from '@octokit/rest';\nimport { getOctokit } from '@actions/github';\n\nexport const octokit = getOctokit(core.getInput('github_token', { required: true })).rest as unknown as Octokit;\n"],"names":[],"sourceRoot":""} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 98073cdfe..222234631 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,7 +4,6 @@ "requires": true, "packages": { "": { - "name": "github-helpers", "dependencies": { "@actions/core": "1.6.0", "@actions/github": "5.0.0", diff --git a/src/helpers/create-pr.ts b/src/helpers/create-pr.ts index c9a6ad14e..d7f704dab 100644 --- a/src/helpers/create-pr.ts +++ b/src/helpers/create-pr.ts @@ -23,7 +23,7 @@ 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, @@ -31,4 +31,6 @@ export const createPr = async ({ title, body }: CreatePR) => { maintainer_can_modify: true, ...context.repo }); + const pullNumber = result?.data?.number; + return pullNumber; }; diff --git a/test/helpers/create-pr.test.ts b/test/helpers/create-pr.test.ts index 7386f4282..0dd5472d8 100644 --- a/test/helpers/create-pr.test.ts +++ b/test/helpers/create-pr.test.ts @@ -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', @@ -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); + }); });