diff --git a/dist/420.index.js b/dist/420.index.js index f2155bda3..57cc19078 100644 --- a/dist/420.index.js +++ b/dist/420.index.js @@ -101,11 +101,12 @@ class InitiateDeployment { const initiateDeployment = ({ sha, state = 'in_progress', environment, environment_url, description, target_url }) => __awaiter(void 0, void 0, void 0, function* () { const { data } = yield _octokit__WEBPACK_IMPORTED_MODULE_2__/* .octokit.repos.createDeployment */ .K.repos.createDeployment(Object.assign(Object.assign({ ref: sha, environment, auto_merge: false, required_contexts: [] }, _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo), _constants__WEBPACK_IMPORTED_MODULE_0__/* .GITHUB_OPTIONS */ .Cc)); const deployment_id = data.id; - return _octokit__WEBPACK_IMPORTED_MODULE_2__/* .octokit.repos.createDeploymentStatus */ .K.repos.createDeploymentStatus(Object.assign(Object.assign({ state, + yield _octokit__WEBPACK_IMPORTED_MODULE_2__/* .octokit.repos.createDeploymentStatus */ .K.repos.createDeploymentStatus(Object.assign(Object.assign({ state, deployment_id, description, environment_url, target_url }, _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo), _constants__WEBPACK_IMPORTED_MODULE_0__/* .GITHUB_OPTIONS */ .Cc)); + return deployment_id; }); diff --git a/dist/420.index.js.map b/dist/420.index.js.map index e309a55dc..2a0c4c739 100644 --- a/dist/420.index.js.map +++ b/dist/420.index.js.map @@ -1 +1 @@ -{"version":3,"file":"420.index.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;AChCA;;;;;;;;;;;AAWA;;;;;;;;;;AAGA;AACA;AACA;AAEA;AAAA;AACA;AACA;AAKA;AAAA;AAEA;AAQA;AAQA;AACA;AAEA;AACA;AACA;AACA;AAIA;;;;;;;;;;;;;;;;;ACrDA;;;;;;;;;;;AAWA;AAEA;AACA;AAEA;AAEA;AACA","sources":["webpack://github-helpers/./src/constants.ts","webpack://github-helpers/./src/helpers/initiate-deployment.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\n// These extra headers are for experimental API features on Github Enterprise. See https://docs.github.com/en/enterprise-server@3.0/rest/overview/api-previews for details.\nconst PREVIEWS = ['ant-man', 'flash', 'groot', 'inertia', 'starfox'];\nexport const GITHUB_OPTIONS = {\n headers: {\n accept: PREVIEWS.map(preview => `application/vnd.github.${preview}-preview+json`).join()\n }\n};\n\nexport const DEFAULT_EXEMPT_DESCRIPTION = 'Passed in case the check is exempt.';\nexport const DEFAULT_PIPELINE_STATUS = 'Pipeline Status';\nexport const DEFAULT_PIPELINE_DESCRIPTION = 'Pipeline clear.';\nexport const PRODUCTION_ENVIRONMENT = 'production';\nexport const CORE_APPROVED_PR_LABEL = 'CORE APPROVED';\nexport const PEER_APPROVED_PR_LABEL = 'PEER APPROVED';\nexport const READY_FOR_MERGE_PR_LABEL = 'READY FOR MERGE';\nexport const MERGE_QUEUE_STATUS = 'QUEUE CHECKER';\nexport const QUEUED_FOR_MERGE_PREFIX = 'QUEUED FOR MERGE';\nexport const FIRST_QUEUED_PR_LABEL = `${QUEUED_FOR_MERGE_PREFIX} #1`;\nexport const JUMP_THE_QUEUE_PR_LABEL = 'JUMP THE QUEUE';\nexport const DEFAULT_PR_TITLE_REGEX = '^(build|ci|chore|docs|feat|fix|perf|refactor|style|test|revert|Revert|BREAKING CHANGE)((.*))?: .+$';\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 { CreateDeploymentResponse, DeploymentState } from '../types';\nimport { GITHUB_OPTIONS } from '../constants';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\n\nexport class InitiateDeployment {\n sha = '';\n environment = '';\n state?: DeploymentState;\n environment_url?: string;\n description?: string;\n target_url?: string;\n}\n\nexport const initiateDeployment = async ({\n sha,\n state = 'in_progress',\n environment,\n environment_url,\n description,\n target_url\n}: InitiateDeployment) => {\n const { data } = await octokit.repos.createDeployment({\n ref: sha,\n environment,\n auto_merge: false,\n required_contexts: [],\n ...context.repo,\n ...GITHUB_OPTIONS\n });\n const deployment_id = (data as CreateDeploymentResponse).id;\n return octokit.repos.createDeploymentStatus({\n state,\n deployment_id,\n description,\n environment_url,\n target_url,\n ...context.repo,\n ...GITHUB_OPTIONS\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 * as fetch from '@adobe/node-fetch-retry';\nimport { Octokit } from '@octokit/rest';\nimport { getOctokit } from '@actions/github';\n\nconst githubToken = core.getInput('github_token', { required: true });\nexport const octokit = getOctokit(githubToken, { request: { fetch } }).rest as unknown as Octokit;\n"],"names":[],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"420.index.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;AChCA;;;;;;;;;;;AAWA;;;;;;;;;;AAGA;AACA;AACA;AAEA;AAAA;AACA;AACA;AAKA;AAAA;AAEA;AAQA;AAQA;AACA;AAEA;AACA;AACA;AACA;AAKA;AACA;;;;;;;;;;;;;;;;;ACvDA;;;;;;;;;;;AAWA;AAEA;AACA;AAEA;AAEA;AACA","sources":["webpack://github-helpers/./src/constants.ts","webpack://github-helpers/./src/helpers/initiate-deployment.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\n// These extra headers are for experimental API features on Github Enterprise. See https://docs.github.com/en/enterprise-server@3.0/rest/overview/api-previews for details.\nconst PREVIEWS = ['ant-man', 'flash', 'groot', 'inertia', 'starfox'];\nexport const GITHUB_OPTIONS = {\n headers: {\n accept: PREVIEWS.map(preview => `application/vnd.github.${preview}-preview+json`).join()\n }\n};\n\nexport const DEFAULT_EXEMPT_DESCRIPTION = 'Passed in case the check is exempt.';\nexport const DEFAULT_PIPELINE_STATUS = 'Pipeline Status';\nexport const DEFAULT_PIPELINE_DESCRIPTION = 'Pipeline clear.';\nexport const PRODUCTION_ENVIRONMENT = 'production';\nexport const CORE_APPROVED_PR_LABEL = 'CORE APPROVED';\nexport const PEER_APPROVED_PR_LABEL = 'PEER APPROVED';\nexport const READY_FOR_MERGE_PR_LABEL = 'READY FOR MERGE';\nexport const MERGE_QUEUE_STATUS = 'QUEUE CHECKER';\nexport const QUEUED_FOR_MERGE_PREFIX = 'QUEUED FOR MERGE';\nexport const FIRST_QUEUED_PR_LABEL = `${QUEUED_FOR_MERGE_PREFIX} #1`;\nexport const JUMP_THE_QUEUE_PR_LABEL = 'JUMP THE QUEUE';\nexport const DEFAULT_PR_TITLE_REGEX = '^(build|ci|chore|docs|feat|fix|perf|refactor|style|test|revert|Revert|BREAKING CHANGE)((.*))?: .+$';\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 { CreateDeploymentResponse, DeploymentState } from '../types';\nimport { GITHUB_OPTIONS } from '../constants';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\n\nexport class InitiateDeployment {\n sha = '';\n environment = '';\n state?: DeploymentState;\n environment_url?: string;\n description?: string;\n target_url?: string;\n}\n\nexport const initiateDeployment = async ({\n sha,\n state = 'in_progress',\n environment,\n environment_url,\n description,\n target_url\n}: InitiateDeployment) => {\n const { data } = await octokit.repos.createDeployment({\n ref: sha,\n environment,\n auto_merge: false,\n required_contexts: [],\n ...context.repo,\n ...GITHUB_OPTIONS\n });\n const deployment_id = (data as CreateDeploymentResponse).id;\n await octokit.repos.createDeploymentStatus({\n state,\n deployment_id,\n description,\n environment_url,\n target_url,\n ...context.repo,\n ...GITHUB_OPTIONS\n });\n\n return deployment_id;\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 * as fetch from '@adobe/node-fetch-retry';\nimport { Octokit } from '@octokit/rest';\nimport { getOctokit } from '@actions/github';\n\nconst githubToken = core.getInput('github_token', { required: true });\nexport const octokit = getOctokit(githubToken, { request: { fetch } }).rest as unknown as Octokit;\n"],"names":[],"sourceRoot":""} \ No newline at end of file diff --git a/src/helpers/initiate-deployment.ts b/src/helpers/initiate-deployment.ts index 2fe8b6ed7..592b0271b 100644 --- a/src/helpers/initiate-deployment.ts +++ b/src/helpers/initiate-deployment.ts @@ -42,7 +42,7 @@ export const initiateDeployment = async ({ ...GITHUB_OPTIONS }); const deployment_id = (data as CreateDeploymentResponse).id; - return octokit.repos.createDeploymentStatus({ + await octokit.repos.createDeploymentStatus({ state, deployment_id, description, @@ -51,4 +51,6 @@ export const initiateDeployment = async ({ ...context.repo, ...GITHUB_OPTIONS }); + + return deployment_id; }; diff --git a/test/helpers/initiate-deployment.test.ts b/test/helpers/initiate-deployment.test.ts index 3e90a7cd0..252c5251a 100644 --- a/test/helpers/initiate-deployment.test.ts +++ b/test/helpers/initiate-deployment.test.ts @@ -44,16 +44,13 @@ describe('initiateDeployment', () => { const target_url = 'url'; const auto_merge = false; - beforeEach(() => { - initiateDeployment({ + it('should call createDeployment with correct params', async () => { + await initiateDeployment({ sha, environment, description, target_url }); - }); - - it('should call createDeployment with correct params', () => { expect(octokit.repos.createDeployment).toHaveBeenCalledWith({ ref: sha, environment, @@ -64,7 +61,13 @@ describe('initiateDeployment', () => { }); }); - it('should call createDeploymentStatus with correct params', () => { + it('should call createDeploymentStatus with correct params', async () => { + await initiateDeployment({ + sha, + environment, + description, + target_url + }); expect(octokit.repos.createDeploymentStatus).toHaveBeenCalledWith({ state: 'in_progress', deployment_id, @@ -74,4 +77,14 @@ describe('initiateDeployment', () => { ...GITHUB_OPTIONS }); }); + + it('should return deployment id as output', async () => { + const result = await initiateDeployment({ + sha, + environment, + description, + target_url + }); + expect(result).toEqual(deployment_id); + }); });