diff --git a/dist/950.index.js b/dist/950.index.js index b1f3984ec..fadc7c078 100644 --- a/dist/950.index.js +++ b/dist/950.index.js @@ -1,6 +1,6 @@ "use strict"; exports.id = 950; -exports.ids = [950]; +exports.ids = [950,61]; exports.modules = { /***/ 9042: @@ -216,6 +216,8 @@ const addDueDateComment = (deadline, createdDate, issue_number, numComments) => } }); +// EXTERNAL MODULE: ./src/helpers/remove-label.ts +var remove_label = __webpack_require__(61); ;// CONCATENATED MODULE: ./src/helpers/manage-issue-due-dates.ts /* Copyright 2023 Expedia, Inc. @@ -245,6 +247,7 @@ var manage_issue_due_dates_awaiter = (undefined && undefined.__awaiter) || funct + class ManageIssueDueDates extends generated/* HelperInputs */.s { } const manageIssueDueDates = ({ days = '7' }) => manage_issue_due_dates_awaiter(void 0, void 0, void 0, function* () { @@ -258,7 +261,7 @@ const manageIssueDueDates = ({ days = '7' }) => manage_issue_due_dates_awaiter(v const { labels, created_at, assignee, number: issue_number, comments } = issue; const priority = getFirstPriorityLabelFoundOnIssue(labels); const alreadyHasOverdueLabel = Boolean(labels.find(label => { - const overdueLabels = [constants/* OVERDUE_ISSUE */.wH, constants/* ALMOST_OVERDUE_ISSUE */.aT]; + const overdueLabels = [constants/* OVERDUE_ISSUE */.wH]; const labelName = typeof label === 'string' ? label : label.name || ''; return overdueLabels.includes(labelName); })); @@ -273,6 +276,9 @@ const manageIssueDueDates = ({ days = '7' }) => manage_issue_due_dates_awaiter(v yield octokit/* octokit.issues.createComment */.K.issues.createComment(Object.assign({ issue_number, body: `@${assignee.name || assignee.login}, this issue assigned to you is now ${labelToAdd.toLowerCase()}` }, github.context.repo)); } if (labelToAdd) { + if (labelToAdd === constants/* OVERDUE_ISSUE */.wH) { + (0,remove_label.removeLabelIfExists)(constants/* ALMOST_OVERDUE_ISSUE */.aT, issue_number); + } yield octokit/* octokit.issues.addLabels */.K.issues.addLabels(Object.assign({ labels: [labelToAdd], issue_number }, github.context.repo)); } yield addDueDateComment(deadline, createdDate, issue_number, comments); @@ -280,6 +286,67 @@ const manageIssueDueDates = ({ days = '7' }) => manage_issue_due_dates_awaiter(v }); +/***/ }), + +/***/ 61: +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "RemoveLabel": () => (/* binding */ RemoveLabel), +/* harmony export */ "removeLabel": () => (/* binding */ removeLabel), +/* harmony export */ "removeLabelIfExists": () => (/* binding */ removeLabelIfExists) +/* harmony export */ }); +/* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2186); +/* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_actions_core__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _types_generated__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(3476); +/* 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 RemoveLabel extends _types_generated__WEBPACK_IMPORTED_MODULE_3__/* .HelperInputs */ .s { + constructor() { + super(...arguments); + this.label = ''; + } +} +const removeLabel = ({ label }) => __awaiter(void 0, void 0, void 0, function* () { return removeLabelIfExists(label, _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.issue.number); }); +const removeLabelIfExists = (labelName, issue_number) => __awaiter(void 0, void 0, void 0, function* () { + try { + yield _octokit__WEBPACK_IMPORTED_MODULE_2__/* .octokit.issues.removeLabel */ .K.issues.removeLabel(Object.assign({ name: labelName, issue_number }, _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo)); + } + catch (error) { + if (error.status === 404) { + _actions_core__WEBPACK_IMPORTED_MODULE_0__.info('Label is not present on PR.'); + } + } +}); + + /***/ }), /***/ 6161: diff --git a/dist/950.index.js.map b/dist/950.index.js.map index ca2beb8f3..e0411c278 100644 --- a/dist/950.index.js.map +++ b/dist/950.index.js.map @@ -1 +1 @@ -{"version":3,"file":"950.index.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC3DA;;;;;;;;;;;AAWA;;;;;;;;;;AAGA;AACA;AACA;AACA;AAEA;AAGA;;AACA;AASA;AACA;AACA;AACA;AACA;;;ACpCA;;;;;;;;;;;AAWA;;;;;;;;;;AAGA;AACA;AAEA;;AACA;AAQA;AACA;AACA;AACA;AACA;;;AC9BA;;;;;;;;;;;AAWA;;;;;;;;;;AAGA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AAKA;AACA;;;AChCA;;;;;;;;;;;AAWA;;;;;;;;;;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;AAEA;AAEA;AAEA;AACA;AAEA;AAEA;AAGA;AACA;AACA;AAGA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAKA;AACA;AACA;AAKA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;AC1EA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AA2CA","sources":[".././src/constants.ts",".././src/utils/paginate-prioritized-issues.ts",".././src/utils/paginate-comments-on-issue.ts",".././src/utils/add-due-date-comment.ts",".././src/helpers/manage-issue-due-dates.ts",".././src/octokit.ts",".././src/types/generated.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 SECONDS_IN_A_DAY = 86400000;\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 LATE_REVIEW = 'Late Review';\nexport const OVERDUE_ISSUE = 'Overdue';\nexport const ALMOST_OVERDUE_ISSUE = 'Due Soon';\nexport const PRIORITY_1 = 'Priority: Critical';\nexport const PRIORITY_2 = 'Priority: High';\nexport const PRIORITY_3 = 'Priority: Medium';\nexport const PRIORITY_4 = 'Priority: Low';\nexport const PRIORITY_LABELS = [PRIORITY_1, PRIORITY_2, PRIORITY_3, PRIORITY_4] as const;\nexport const PRIORITY_TO_DAYS_MAP = {\n [PRIORITY_1]: 2,\n [PRIORITY_2]: 14,\n [PRIORITY_3]: 45,\n [PRIORITY_4]: 90\n};\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)((.*))?: .+$';\nexport const COPYRIGHT_HEADER = `/*\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","/*\nCopyright 2023 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 { IssueList } from '../types/github';\nimport { octokit } from '../octokit';\nimport { context } from '@actions/github';\nimport { PRIORITY_LABELS } from '../constants';\nimport { map } from 'bluebird';\n\nexport const paginateAllPrioritizedIssues = async () =>\n (await map(PRIORITY_LABELS, async label => await paginateIssuesOfSpecificPriority(label))).flat();\n\nexport const paginateIssuesOfSpecificPriority = async (label: string, page = 1): Promise => {\n const response = await octokit.issues.listForRepo({\n state: 'open',\n sort: 'created',\n direction: 'desc',\n per_page: 100,\n labels: label,\n page,\n ...context.repo\n });\n if (!response?.data?.length) {\n return [];\n }\n return response.data.concat(await paginateIssuesOfSpecificPriority(label, page + 1));\n};\n","/*\nCopyright 2023 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 { CommentList } from '../types/github';\nimport { octokit } from '../octokit';\nimport { context } from '@actions/github';\n\nexport const paginateAllCommentsOnIssue = async (issue_number: number, page = 1): Promise => {\n const response = await octokit.issues.listComments({\n issue_number,\n sort: 'created',\n direction: 'desc',\n per_page: 100,\n page,\n ...context.repo\n });\n if (!response?.data?.length) {\n return [];\n }\n return response.data.concat(await paginateAllCommentsOnIssue(issue_number, page + 1));\n};\n","/*\nCopyright 2023 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 { CommentList, SingleComment } from '../types/github';\nimport { paginateAllCommentsOnIssue } from './paginate-comments-on-issue';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\nimport { SECONDS_IN_A_DAY } from '../constants';\n\nexport const addDueDateComment = async (deadline: number, createdDate: Date, issue_number: number, numComments: number) => {\n const hasExistingComments = numComments > 0;\n const commentList: CommentList = hasExistingComments ? await paginateAllCommentsOnIssue(issue_number) : [];\n // Create due date comment if there are no existing comments or the comment list does not contain a due date comment\n if (!hasExistingComments || !commentList.find((comment: SingleComment) => comment.body?.startsWith('This issue is due on'))) {\n const dueDate = new Date(createdDate.getTime() + deadline * SECONDS_IN_A_DAY);\n\n await octokit.issues.createComment({\n issue_number,\n body: `This issue is due on ${dueDate.toDateString()}`,\n ...context.repo\n });\n }\n};\n","/*\nCopyright 2023 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 { OVERDUE_ISSUE, ALMOST_OVERDUE_ISSUE, PRIORITY_LABELS, PRIORITY_TO_DAYS_MAP, SECONDS_IN_A_DAY } from '../constants';\nimport { HelperInputs } from '../types/generated';\nimport { paginateAllPrioritizedIssues } from '../utils/paginate-prioritized-issues';\nimport { addDueDateComment } from '../utils/add-due-date-comment';\nimport { IssueList, IssueLabels } from '../types/github';\nimport { map } from 'bluebird';\nimport { octokit } from '../octokit';\nimport { context } from '@actions/github';\n\nexport class ManageIssueDueDates extends HelperInputs {\n days?: string;\n}\n\nexport const manageIssueDueDates = async ({ days = '7' }: ManageIssueDueDates) => {\n const openIssues: IssueList = await paginateAllPrioritizedIssues();\n\n const warningThreshold = Number(days);\n\n const getFirstPriorityLabelFoundOnIssue = (issueLabels: IssueLabels) =>\n PRIORITY_LABELS.find(priorityLabel =>\n issueLabels.some(issueLabel => {\n const labelName = typeof issueLabel === 'string' ? issueLabel : issueLabel.name;\n return labelName === priorityLabel;\n })\n );\n\n await map(openIssues, async issue => {\n const { labels, created_at, assignee, number: issue_number, comments } = issue;\n const priority = getFirstPriorityLabelFoundOnIssue(labels);\n const alreadyHasOverdueLabel = Boolean(\n labels.find(label => {\n const overdueLabels = [OVERDUE_ISSUE, ALMOST_OVERDUE_ISSUE];\n const labelName: string = typeof label === 'string' ? label : label.name || '';\n return overdueLabels.includes(labelName);\n })\n );\n\n if (!priority || alreadyHasOverdueLabel) {\n return;\n }\n const createdDate = new Date(created_at);\n const daysSinceCreation = Math.ceil((Date.now() - createdDate.getTime()) / SECONDS_IN_A_DAY);\n const deadline = PRIORITY_TO_DAYS_MAP[priority];\n const labelToAdd =\n daysSinceCreation > deadline ? OVERDUE_ISSUE : daysSinceCreation > deadline - warningThreshold ? ALMOST_OVERDUE_ISSUE : undefined;\n if (assignee && labelToAdd) {\n await octokit.issues.createComment({\n issue_number,\n body: `@${assignee.name || assignee.login}, this issue assigned to you is now ${labelToAdd.toLowerCase()}`,\n ...context.repo\n });\n }\n if (labelToAdd) {\n await octokit.issues.addLabels({\n labels: [labelToAdd],\n issue_number,\n ...context.repo\n });\n }\n await addDueDateComment(deadline, createdDate, issue_number, comments);\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 { getOctokit } from '@actions/github';\n\nconst githubToken = core.getInput('github_token', { required: true });\nexport const { rest: octokit, graphql: octokitGraphql } = getOctokit(githubToken, { request: { fetch } });\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\nexport class HelperInputs {\n helper?: string;\n github_token?: string;\n body?: string;\n project_name?: string;\n project_destination_column_name?: string;\n note?: string;\n project_origin_column_name?: string;\n sha?: string;\n context?: string;\n state?: string;\n description?: string;\n target_url?: string;\n environment?: string;\n environment_url?: string;\n label?: string;\n labels?: string;\n paths?: string;\n ignore_globs?: string;\n extensions?: string;\n override_filter_paths?: string;\n batches?: string;\n pattern?: string;\n teams?: string;\n login?: string;\n paths_no_filter?: string;\n slack_webhook_url?: string;\n number_of_assignees?: string;\n number_of_reviewers?: string;\n globs?: string;\n override_filter_globs?: string;\n title?: string;\n seconds?: string;\n pull_number?: string;\n base?: string;\n head?: string;\n days?: string;\n no_evict_upon_conflict?: string;\n skip_if_already_set?: string;\n delimiter?: string;\n team?: string;\n ignore_deleted?: string;\n return_full_payload?: string;\n}\n"],"names":[],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"950.index.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC3DA;;;;;;;;;;;AAWA;;;;;;;;;;AAGA;AACA;AACA;AACA;AAEA;AAGA;;AACA;AASA;AACA;AACA;AACA;AACA;;;ACpCA;;;;;;;;;;;AAWA;;;;;;;;;;AAGA;AACA;AAEA;;AACA;AAQA;AACA;AACA;AACA;AACA;;;AC9BA;;;;;;;;;;;AAWA;;;;;;;;;;AAGA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AAKA;AACA;;;;;AChCA;;;;;;;;;;;AAWA;;;;;;;;;;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AAEA;AAEA;AACA;AAEA;AAEA;AAGA;AACA;AACA;AAGA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAKA;AACA;AACA;AACA;AACA;AACA;AAKA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;AC9EA;;;;;;;;;;;AAWA;;;;;;;;;;AAEA;AAEA;AACA;AACA;AAEA;AAAA;;AACA;AACA;AAAA;AAEA;AAEA;AACA;AACA;AAKA;AAAA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;ACrCA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AA2CA","sources":[".././src/constants.ts",".././src/utils/paginate-prioritized-issues.ts",".././src/utils/paginate-comments-on-issue.ts",".././src/utils/add-due-date-comment.ts",".././src/helpers/manage-issue-due-dates.ts",".././src/helpers/remove-label.ts",".././src/octokit.ts",".././src/types/generated.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 SECONDS_IN_A_DAY = 86400000;\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 LATE_REVIEW = 'Late Review';\nexport const OVERDUE_ISSUE = 'Overdue';\nexport const ALMOST_OVERDUE_ISSUE = 'Due Soon';\nexport const PRIORITY_1 = 'Priority: Critical';\nexport const PRIORITY_2 = 'Priority: High';\nexport const PRIORITY_3 = 'Priority: Medium';\nexport const PRIORITY_4 = 'Priority: Low';\nexport const PRIORITY_LABELS = [PRIORITY_1, PRIORITY_2, PRIORITY_3, PRIORITY_4] as const;\nexport const PRIORITY_TO_DAYS_MAP = {\n [PRIORITY_1]: 2,\n [PRIORITY_2]: 14,\n [PRIORITY_3]: 45,\n [PRIORITY_4]: 90\n};\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)((.*))?: .+$';\nexport const COPYRIGHT_HEADER = `/*\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","/*\nCopyright 2023 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 { IssueList } from '../types/github';\nimport { octokit } from '../octokit';\nimport { context } from '@actions/github';\nimport { PRIORITY_LABELS } from '../constants';\nimport { map } from 'bluebird';\n\nexport const paginateAllPrioritizedIssues = async () =>\n (await map(PRIORITY_LABELS, async label => await paginateIssuesOfSpecificPriority(label))).flat();\n\nexport const paginateIssuesOfSpecificPriority = async (label: string, page = 1): Promise => {\n const response = await octokit.issues.listForRepo({\n state: 'open',\n sort: 'created',\n direction: 'desc',\n per_page: 100,\n labels: label,\n page,\n ...context.repo\n });\n if (!response?.data?.length) {\n return [];\n }\n return response.data.concat(await paginateIssuesOfSpecificPriority(label, page + 1));\n};\n","/*\nCopyright 2023 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 { CommentList } from '../types/github';\nimport { octokit } from '../octokit';\nimport { context } from '@actions/github';\n\nexport const paginateAllCommentsOnIssue = async (issue_number: number, page = 1): Promise => {\n const response = await octokit.issues.listComments({\n issue_number,\n sort: 'created',\n direction: 'desc',\n per_page: 100,\n page,\n ...context.repo\n });\n if (!response?.data?.length) {\n return [];\n }\n return response.data.concat(await paginateAllCommentsOnIssue(issue_number, page + 1));\n};\n","/*\nCopyright 2023 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 { CommentList, SingleComment } from '../types/github';\nimport { paginateAllCommentsOnIssue } from './paginate-comments-on-issue';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\nimport { SECONDS_IN_A_DAY } from '../constants';\n\nexport const addDueDateComment = async (deadline: number, createdDate: Date, issue_number: number, numComments: number) => {\n const hasExistingComments = numComments > 0;\n const commentList: CommentList = hasExistingComments ? await paginateAllCommentsOnIssue(issue_number) : [];\n // Create due date comment if there are no existing comments or the comment list does not contain a due date comment\n if (!hasExistingComments || !commentList.find((comment: SingleComment) => comment.body?.startsWith('This issue is due on'))) {\n const dueDate = new Date(createdDate.getTime() + deadline * SECONDS_IN_A_DAY);\n\n await octokit.issues.createComment({\n issue_number,\n body: `This issue is due on ${dueDate.toDateString()}`,\n ...context.repo\n });\n }\n};\n","/*\nCopyright 2023 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 { OVERDUE_ISSUE, ALMOST_OVERDUE_ISSUE, PRIORITY_LABELS, PRIORITY_TO_DAYS_MAP, SECONDS_IN_A_DAY } from '../constants';\nimport { HelperInputs } from '../types/generated';\nimport { paginateAllPrioritizedIssues } from '../utils/paginate-prioritized-issues';\nimport { addDueDateComment } from '../utils/add-due-date-comment';\nimport { IssueList, IssueLabels } from '../types/github';\nimport { map } from 'bluebird';\nimport { octokit } from '../octokit';\nimport { context } from '@actions/github';\nimport { removeLabelIfExists } from './remove-label';\n\nexport class ManageIssueDueDates extends HelperInputs {\n days?: string;\n}\n\nexport const manageIssueDueDates = async ({ days = '7' }: ManageIssueDueDates) => {\n const openIssues: IssueList = await paginateAllPrioritizedIssues();\n\n const warningThreshold = Number(days);\n\n const getFirstPriorityLabelFoundOnIssue = (issueLabels: IssueLabels) =>\n PRIORITY_LABELS.find(priorityLabel =>\n issueLabels.some(issueLabel => {\n const labelName = typeof issueLabel === 'string' ? issueLabel : issueLabel.name;\n return labelName === priorityLabel;\n })\n );\n\n await map(openIssues, async issue => {\n const { labels, created_at, assignee, number: issue_number, comments } = issue;\n const priority = getFirstPriorityLabelFoundOnIssue(labels);\n const alreadyHasOverdueLabel = Boolean(\n labels.find(label => {\n const overdueLabels = [OVERDUE_ISSUE];\n const labelName: string = typeof label === 'string' ? label : label.name || '';\n return overdueLabels.includes(labelName);\n })\n );\n\n if (!priority || alreadyHasOverdueLabel) {\n return;\n }\n const createdDate = new Date(created_at);\n const daysSinceCreation = Math.ceil((Date.now() - createdDate.getTime()) / SECONDS_IN_A_DAY);\n const deadline = PRIORITY_TO_DAYS_MAP[priority];\n const labelToAdd =\n daysSinceCreation > deadline ? OVERDUE_ISSUE : daysSinceCreation > deadline - warningThreshold ? ALMOST_OVERDUE_ISSUE : undefined;\n if (assignee && labelToAdd) {\n await octokit.issues.createComment({\n issue_number,\n body: `@${assignee.name || assignee.login}, this issue assigned to you is now ${labelToAdd.toLowerCase()}`,\n ...context.repo\n });\n }\n if (labelToAdd) {\n if (labelToAdd === OVERDUE_ISSUE) {\n removeLabelIfExists(ALMOST_OVERDUE_ISSUE, issue_number);\n }\n await octokit.issues.addLabels({\n labels: [labelToAdd],\n issue_number,\n ...context.repo\n });\n }\n await addDueDateComment(deadline, createdDate, issue_number, comments);\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 { GithubError } from '../types/github';\nimport { HelperInputs } from '../types/generated';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\n\nexport class RemoveLabel extends HelperInputs {\n label = '';\n}\n\nexport const removeLabel = async ({ label }: RemoveLabel) => removeLabelIfExists(label, context.issue.number);\n\nexport const removeLabelIfExists = async (labelName: string, issue_number: number) => {\n try {\n await octokit.issues.removeLabel({\n name: labelName,\n issue_number,\n ...context.repo\n });\n } catch (error) {\n if ((error as GithubError).status === 404) {\n core.info('Label is not present on PR.');\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 { getOctokit } from '@actions/github';\n\nconst githubToken = core.getInput('github_token', { required: true });\nexport const { rest: octokit, graphql: octokitGraphql } = getOctokit(githubToken, { request: { fetch } });\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\nexport class HelperInputs {\n helper?: string;\n github_token?: string;\n body?: string;\n project_name?: string;\n project_destination_column_name?: string;\n note?: string;\n project_origin_column_name?: string;\n sha?: string;\n context?: string;\n state?: string;\n description?: string;\n target_url?: string;\n environment?: string;\n environment_url?: string;\n label?: string;\n labels?: string;\n paths?: string;\n ignore_globs?: string;\n extensions?: string;\n override_filter_paths?: string;\n batches?: string;\n pattern?: string;\n teams?: string;\n login?: string;\n paths_no_filter?: string;\n slack_webhook_url?: string;\n number_of_assignees?: string;\n number_of_reviewers?: string;\n globs?: string;\n override_filter_globs?: string;\n title?: string;\n seconds?: string;\n pull_number?: string;\n base?: string;\n head?: string;\n days?: string;\n no_evict_upon_conflict?: string;\n skip_if_already_set?: string;\n delimiter?: string;\n team?: string;\n ignore_deleted?: string;\n return_full_payload?: string;\n}\n"],"names":[],"sourceRoot":""} \ No newline at end of file diff --git a/src/helpers/manage-issue-due-dates.ts b/src/helpers/manage-issue-due-dates.ts index e57aa7ec3..07401de18 100644 --- a/src/helpers/manage-issue-due-dates.ts +++ b/src/helpers/manage-issue-due-dates.ts @@ -19,6 +19,7 @@ import { IssueList, IssueLabels } from '../types/github'; import { map } from 'bluebird'; import { octokit } from '../octokit'; import { context } from '@actions/github'; +import { removeLabelIfExists } from './remove-label'; export class ManageIssueDueDates extends HelperInputs { days?: string; @@ -42,7 +43,7 @@ export const manageIssueDueDates = async ({ days = '7' }: ManageIssueDueDates) = const priority = getFirstPriorityLabelFoundOnIssue(labels); const alreadyHasOverdueLabel = Boolean( labels.find(label => { - const overdueLabels = [OVERDUE_ISSUE, ALMOST_OVERDUE_ISSUE]; + const overdueLabels = [OVERDUE_ISSUE]; const labelName: string = typeof label === 'string' ? label : label.name || ''; return overdueLabels.includes(labelName); }) @@ -64,6 +65,9 @@ export const manageIssueDueDates = async ({ days = '7' }: ManageIssueDueDates) = }); } if (labelToAdd) { + if (labelToAdd === OVERDUE_ISSUE) { + removeLabelIfExists(ALMOST_OVERDUE_ISSUE, issue_number); + } await octokit.issues.addLabels({ labels: [labelToAdd], issue_number, diff --git a/test/helpers/manage-issue-due-dates.test.ts b/test/helpers/manage-issue-due-dates.test.ts index d3404b082..130c939bd 100644 --- a/test/helpers/manage-issue-due-dates.test.ts +++ b/test/helpers/manage-issue-due-dates.test.ts @@ -16,12 +16,16 @@ import { context } from '@actions/github'; import { octokit } from '../../src/octokit'; import { Mocktokit } from '../types'; import { ALMOST_OVERDUE_ISSUE, OVERDUE_ISSUE, PRIORITY_1, PRIORITY_2, PRIORITY_3, PRIORITY_4, PRIORITY_LABELS } from '../../src/constants'; +import { removeLabelIfExists } from '../../src/helpers/remove-label'; +jest.mock('../../src/helpers/remove-label'); jest.mock('@actions/core'); jest.mock('@actions/github', () => ({ context: { repo: { repo: 'repo', owner: 'owner' } }, getOctokit: jest.fn(() => ({ - rest: { issues: { addLabels: jest.fn(), listForRepo: jest.fn(), createComment: jest.fn(), listComments: jest.fn() } } + rest: { + issues: { addLabels: jest.fn(), listForRepo: jest.fn(), createComment: jest.fn(), listComments: jest.fn() } + } })) })); @@ -108,7 +112,7 @@ describe('manageIssueDueDates', () => { data: [ { number: 123, - labels: [PRIORITY_2], + labels: [PRIORITY_2, ALMOST_OVERDUE_ISSUE], created_at: '2023-09-06T20:09:21Z', assignee: { login: 'octocat' } } @@ -129,6 +133,7 @@ describe('manageIssueDueDates', () => { }) ); + expect(removeLabelIfExists).toHaveBeenCalledWith(ALMOST_OVERDUE_ISSUE, 123); expect(octokit.issues.addLabels).toHaveBeenCalledWith({ labels: [OVERDUE_ISSUE], issue_number: 123, ...context.repo }); expect(octokit.issues.createComment).toHaveBeenCalledWith({ body: '@octocat, this issue assigned to you is now overdue',