From 3a936ab73e6d50cf75eb0637a4da5781eedd28b0 Mon Sep 17 00:00:00 2001 From: Dan Adajian Date: Fri, 13 May 2022 10:22:37 -0500 Subject: [PATCH] fix(notify-pipeline-complete): no longer set deployment status (#198) --- dist/101.index.js | 75 ++----------------- dist/101.index.js.map | 2 +- src/helpers/notify-pipeline-complete.ts | 25 ++----- test/helpers/notify-pipeline-complete.test.ts | 12 +-- 4 files changed, 16 insertions(+), 98 deletions(-) diff --git a/dist/101.index.js b/dist/101.index.js index 868501fbf..6f817572c 100644 --- a/dist/101.index.js +++ b/dist/101.index.js @@ -1,6 +1,6 @@ "use strict"; exports.id = 101; -exports.ids = [101,807]; +exports.ids = [101]; exports.modules = { /***/ 9042: @@ -70,7 +70,6 @@ __webpack_require__.r(__webpack_exports__); /* harmony import */ var bluebird__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8710); /* harmony import */ var bluebird__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(bluebird__WEBPACK_IMPORTED_MODULE_2__); /* harmony import */ var _octokit__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(6161); -/* harmony import */ var _set_deployment_status__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(2807); /* Copyright 2021 Expedia, Inc. Licensed under the Apache License, Version 2.0 (the "License"); @@ -96,78 +95,16 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume - class NotifyPipelineComplete { } const notifyPipelineComplete = ({ context = _constants__WEBPACK_IMPORTED_MODULE_0__/* .DEFAULT_PIPELINE_STATUS */ .$9, description = _constants__WEBPACK_IMPORTED_MODULE_0__/* .DEFAULT_PIPELINE_DESCRIPTION */ .Km, target_url }) => __awaiter(void 0, void 0, void 0, function* () { const { data } = yield _octokit__WEBPACK_IMPORTED_MODULE_3__/* .octokit.pulls.list */ .K.pulls.list(Object.assign({ state: 'open', per_page: 100 }, _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo)); const commitHashes = data.map(pullRequest => pullRequest.head.sha); - return Promise.all([ - (0,bluebird__WEBPACK_IMPORTED_MODULE_2__.map)(commitHashes, (sha) => __awaiter(void 0, void 0, void 0, function* () { - return _octokit__WEBPACK_IMPORTED_MODULE_3__/* .octokit.repos.createCommitStatus */ .K.repos.createCommitStatus(Object.assign({ sha, - context, state: 'success', description, - target_url }, _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo)); - })), - (0,_set_deployment_status__WEBPACK_IMPORTED_MODULE_4__.setDeploymentStatus)(Object.assign({ description: _constants__WEBPACK_IMPORTED_MODULE_0__/* .DEFAULT_PIPELINE_DESCRIPTION */ .Km, environment: _constants__WEBPACK_IMPORTED_MODULE_0__/* .PRODUCTION_ENVIRONMENT */ .Hc, state: 'success' }, _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo)) - ]); -}); - - -/***/ }), - -/***/ 2807: -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ "SetDeploymentStatus": () => (/* binding */ SetDeploymentStatus), -/* harmony export */ "setDeploymentStatus": () => (/* binding */ setDeploymentStatus) -/* harmony export */ }); -/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9042); -/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5438); -/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_actions_github__WEBPACK_IMPORTED_MODULE_1__); -/* harmony import */ var _octokit__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6161); -/* -Copyright 2021 Expedia, Inc. -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - https://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; - - - -class SetDeploymentStatus { - constructor() { - this.state = ''; - this.environment = ''; - } -} -const setDeploymentStatus = ({ sha, state, environment, description, target_url, environment_url }) => __awaiter(void 0, void 0, void 0, function* () { - var _a; - const { data } = yield _octokit__WEBPACK_IMPORTED_MODULE_2__/* .octokit.repos.listDeployments */ .K.repos.listDeployments(Object.assign(Object.assign({ sha, - environment }, _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo), _constants__WEBPACK_IMPORTED_MODULE_0__/* .GITHUB_OPTIONS */ .Cc)); - const deployment_id = (_a = data.find(Boolean)) === null || _a === void 0 ? void 0 : _a.id; - if (deployment_id) { - return _octokit__WEBPACK_IMPORTED_MODULE_2__/* .octokit.repos.createDeploymentStatus */ .K.repos.createDeploymentStatus(Object.assign(Object.assign({ state: state, deployment_id, - description, - target_url, - environment_url }, _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo), _constants__WEBPACK_IMPORTED_MODULE_0__/* .GITHUB_OPTIONS */ .Cc)); - } + return (0,bluebird__WEBPACK_IMPORTED_MODULE_2__.map)(commitHashes, (sha) => __awaiter(void 0, void 0, void 0, function* () { + return _octokit__WEBPACK_IMPORTED_MODULE_3__/* .octokit.repos.createCommitStatus */ .K.repos.createCommitStatus(Object.assign({ sha, + context, state: 'success', description, + target_url }, _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo)); + })); }); diff --git a/dist/101.index.js.map b/dist/101.index.js.map index 90d6c00e8..857410dea 100644 --- a/dist/101.index.js.map +++ b/dist/101.index.js.map @@ -1 +1 @@ -{"version":3,"file":"101.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;;;;;;;;;;AAEA;AACA;AACA;AACA;AACA;AAEA;AAIA;AAEA;AAKA;AAKA;AACA;AACA;AACA;AAEA;AAGA;AAEA;AAEA;AAMA;AACA;;;;;;;;;;;;;;;;;ACtDA;;;;;;;;;;;AAWA;;;;;;;;;;AAGA;AACA;AACA;AAEA;AAAA;AACA;AACA;AAKA;AAAA;AAEA;;AACA;AAEA;AAIA;AACA;AACA;AAGA;AACA;AACA;AAIA;AACA;;;;;;;;;;;;;;;;;AC9CA;;;;;;;;;;;AAWA;AAEA;AACA;AAEA;AAEA;AACA","sources":["webpack://github-helpers/./src/constants.ts","webpack://github-helpers/./src/helpers/notify-pipeline-complete.ts","webpack://github-helpers/./src/helpers/set-deployment-status.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 { DEFAULT_PIPELINE_DESCRIPTION, DEFAULT_PIPELINE_STATUS, PRODUCTION_ENVIRONMENT } from '../constants';\nimport { context as githubContext } from '@actions/github';\nimport { map } from 'bluebird';\nimport { octokit } from '../octokit';\nimport { setDeploymentStatus } from './set-deployment-status';\n\nexport class NotifyPipelineComplete {\n context?: string;\n description?: string;\n target_url?: string;\n}\n\nexport const notifyPipelineComplete = async ({\n context = DEFAULT_PIPELINE_STATUS,\n description = DEFAULT_PIPELINE_DESCRIPTION,\n target_url\n}: NotifyPipelineComplete) => {\n const { data } = await octokit.pulls.list({\n state: 'open',\n per_page: 100,\n ...githubContext.repo\n });\n const commitHashes = data.map(pullRequest => pullRequest.head.sha);\n return Promise.all([\n map(commitHashes, async sha =>\n octokit.repos.createCommitStatus({\n sha,\n context,\n state: 'success',\n description,\n target_url,\n ...githubContext.repo\n })\n ),\n setDeploymentStatus({\n description: DEFAULT_PIPELINE_DESCRIPTION,\n environment: PRODUCTION_ENVIRONMENT,\n state: 'success',\n ...githubContext.repo\n })\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 { DeploymentState } from '../types';\nimport { GITHUB_OPTIONS } from '../constants';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\n\nexport class SetDeploymentStatus {\n state = '';\n environment = '';\n sha?: string;\n description?: string;\n target_url?: string;\n environment_url?: string;\n}\n\nexport const setDeploymentStatus = async ({ sha, state, environment, description, target_url, environment_url }: SetDeploymentStatus) => {\n const { data } = await octokit.repos.listDeployments({\n sha,\n environment,\n ...context.repo,\n ...GITHUB_OPTIONS\n });\n const deployment_id = data.find(Boolean)?.id;\n if (deployment_id) {\n return octokit.repos.createDeploymentStatus({\n state: state as DeploymentState,\n deployment_id,\n description,\n target_url,\n environment_url,\n ...context.repo,\n ...GITHUB_OPTIONS\n });\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":"101.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;;;;;;;;;;AAEA;AACA;AACA;AACA;AAEA;AAIA;AAEA;AAKA;AAKA;AACA;AACA;AAEA;AAGA;AAEA;AAEA;;;;;;;;;;;;;;;;;AC7CA;;;;;;;;;;;AAWA;AAEA;AACA;AAEA;AAEA;AACA","sources":["webpack://github-helpers/./src/constants.ts","webpack://github-helpers/./src/helpers/notify-pipeline-complete.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 { DEFAULT_PIPELINE_DESCRIPTION, DEFAULT_PIPELINE_STATUS } from '../constants';\nimport { context as githubContext } from '@actions/github';\nimport { map } from 'bluebird';\nimport { octokit } from '../octokit';\n\nexport class NotifyPipelineComplete {\n context?: string;\n description?: string;\n target_url?: string;\n}\n\nexport const notifyPipelineComplete = async ({\n context = DEFAULT_PIPELINE_STATUS,\n description = DEFAULT_PIPELINE_DESCRIPTION,\n target_url\n}: NotifyPipelineComplete) => {\n const { data } = await octokit.pulls.list({\n state: 'open',\n per_page: 100,\n ...githubContext.repo\n });\n const commitHashes = data.map(pullRequest => pullRequest.head.sha);\n return map(commitHashes, async sha =>\n octokit.repos.createCommitStatus({\n sha,\n context,\n state: 'success',\n description,\n target_url,\n ...githubContext.repo\n })\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 diff --git a/src/helpers/notify-pipeline-complete.ts b/src/helpers/notify-pipeline-complete.ts index ed14d730a..209ac79bb 100644 --- a/src/helpers/notify-pipeline-complete.ts +++ b/src/helpers/notify-pipeline-complete.ts @@ -11,11 +11,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { DEFAULT_PIPELINE_DESCRIPTION, DEFAULT_PIPELINE_STATUS, PRODUCTION_ENVIRONMENT } from '../constants'; +import { DEFAULT_PIPELINE_DESCRIPTION, DEFAULT_PIPELINE_STATUS } from '../constants'; import { context as githubContext } from '@actions/github'; import { map } from 'bluebird'; import { octokit } from '../octokit'; -import { setDeploymentStatus } from './set-deployment-status'; export class NotifyPipelineComplete { context?: string; @@ -34,22 +33,14 @@ export const notifyPipelineComplete = async ({ ...githubContext.repo }); const commitHashes = data.map(pullRequest => pullRequest.head.sha); - return Promise.all([ - map(commitHashes, async sha => - octokit.repos.createCommitStatus({ - sha, - context, - state: 'success', - description, - target_url, - ...githubContext.repo - }) - ), - setDeploymentStatus({ - description: DEFAULT_PIPELINE_DESCRIPTION, - environment: PRODUCTION_ENVIRONMENT, + return map(commitHashes, async sha => + octokit.repos.createCommitStatus({ + sha, + context, state: 'success', + description, + target_url, ...githubContext.repo }) - ]); + ); }; diff --git a/test/helpers/notify-pipeline-complete.test.ts b/test/helpers/notify-pipeline-complete.test.ts index 7bfd2462a..f5cd9113f 100644 --- a/test/helpers/notify-pipeline-complete.test.ts +++ b/test/helpers/notify-pipeline-complete.test.ts @@ -11,12 +11,11 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { DEFAULT_PIPELINE_DESCRIPTION, DEFAULT_PIPELINE_STATUS, PRODUCTION_ENVIRONMENT } from '../../src/constants'; +import { DEFAULT_PIPELINE_STATUS } from '../../src/constants'; import { Mocktokit } from '../types'; import { context } from '@actions/github'; import { notifyPipelineComplete } from '../../src/helpers/notify-pipeline-complete'; import { octokit } from '../../src/octokit'; -import { setDeploymentStatus } from '../../src/helpers/set-deployment-status'; jest.mock('@actions/core'); jest.mock('@actions/github', () => ({ @@ -72,13 +71,4 @@ describe('setOpenPullRequestStatus', () => { ...context.repo }); }); - - it('should call setDeploymentStatus with correct params', () => { - expect(setDeploymentStatus).toHaveBeenCalledWith({ - state: 'success', - environment: PRODUCTION_ENVIRONMENT, - description: DEFAULT_PIPELINE_DESCRIPTION, - ...context.repo - }); - }); });