From 48e18c66f6ca928e2e8dc0352e1dd937be60074a Mon Sep 17 00:00:00 2001 From: bubkoo Date: Mon, 30 Jan 2023 13:15:03 +0800 Subject: [PATCH] fix: try to fix "Cannot read properties of undefined (reading 'length')" fix getState results re #11 --- package.json | 12 ++++++------ src/index.ts | 8 ++++---- src/inputs.ts | 2 +- src/util.ts | 26 ++++++++++++++++---------- yarn.lock | 45 +++++++++++++++++++++++++-------------------- 5 files changed, 52 insertions(+), 41 deletions(-) diff --git a/package.json b/package.json index c538cbd..3cdd5ca 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "dependencies": { "@actions/core": "^1.10.0", "@actions/github": "^5.1.1", - "@wow-actions/parse-inputs": "^1.2.0", + "@wow-actions/parse-inputs": "^2.0.1", "lodash.samplesize": "^4.2.0" }, "devDependencies": { @@ -40,14 +40,14 @@ "@bubkoo/tsconfig": "^1.1.0", "@types/lodash.samplesize": "^4.2.7", "@types/node": "^18.11.18", - "@vercel/ncc": "^0.36.0", - "eslint": "^8.31.0", - "husky": "^8.0.2", + "@vercel/ncc": "^0.36.1", + "eslint": "^8.33.0", + "husky": "^8.0.3", "is-ci": "^3.0.1", "npm-run-all": "^4.1.5", - "prettier": "^2.8.1", + "prettier": "^2.8.3", "pretty-quick": "^3.1.3", - "rimraf": "^3.0.2", + "rimraf": "^4.1.2", "typescript": "^4.9.4" } } diff --git a/src/index.ts b/src/index.ts index 474f6e7..d5cf624 100644 --- a/src/index.ts +++ b/src/index.ts @@ -36,22 +36,22 @@ async function run() { const octokit = util.getOctokit() const checkIncludings = - inputs.includeLabels != null && inputs.includeLabels.length > 0 + inputs.includeLabels && inputs.includeLabels.length > 0 const checkExcludings = - inputs.excludeLabels != null && inputs.excludeLabels.length > 0 + inputs.excludeLabels && inputs.excludeLabels.length > 0 if (checkIncludings || checkExcludings) { const labels = await util.getIssueLabels(octokit, payload.number) const hasAny = (arr: string[]) => labels.some((l) => arr.includes(l)) if (checkIncludings) { - const any = hasAny(inputs.includeLabels!) + const any = hasAny(inputs.includeLabels) if (!any) { return util.skip(`is not labeled with any of the "includeLabels"`) } } if (checkExcludings) { - const any = hasAny(inputs.excludeLabels!) + const any = hasAny(inputs.excludeLabels) if (any) { return util.skip(`is labeled with one of the "excludeLabels"`) } diff --git a/src/inputs.ts b/src/inputs.ts index 7a2c69f..a5f581c 100644 --- a/src/inputs.ts +++ b/src/inputs.ts @@ -2,7 +2,7 @@ import parseInputs from '@wow-actions/parse-inputs' export function getInputs() { return parseInputs({ - skipDraft: { type: 'boolean' }, + skipDraft: { type: 'boolean', defaultValue: true }, addReviewers: { type: 'boolean', defaultValue: true }, addAssignees: { type: 'boolean', defaultValue: true }, reviewers: { type: 'words' }, diff --git a/src/util.ts b/src/util.ts index 2f36ce7..4b44497 100644 --- a/src/util.ts +++ b/src/util.ts @@ -64,29 +64,35 @@ export async function getState(octokit: Octokit) { const { context } = github const pr = context.payload.pull_request const issue = context.payload.issue - let assignees: string[] - let teams: string[] - let reviewers: string[] + let teams: string[] = [] + let reviewers: string[] = [] + let assignees: string[] = [] if (pr) { const { data } = await octokit.rest.pulls.get({ ...context.repo, pull_number: pr.number, }) - teams = data.requested_teams ? data.requested_teams.map((t) => t.slug) : [] - reviewers = data.requested_reviewers - ? data.requested_reviewers.map((u) => u.login) - : [] - assignees = data.assignees ? data.assignees.map((u) => u.login) : [] + if (data.requested_teams) { + teams = data.requested_teams.map((t) => t.slug) + } + if (data.requested_reviewers) { + reviewers = data.requested_reviewers.map((u) => u.login) + } + if (data.assignees) { + assignees = data.assignees.map((u) => u.login) + } } else if (issue) { const { data } = await octokit.rest.issues.get({ ...context.repo, issue_number: issue.number, }) - assignees = data.assignees ? data.assignees.map((u) => u.login) : [] + if (data.assignees) { + assignees = data.assignees.map((u) => u.login) + } } - return { assignees: assignees!, teams: teams!, reviewers: reviewers! } + return { assignees, teams, reviewers } } function chooseUsers(candidates: string[], count: number, filterUser: string) { diff --git a/yarn.lock b/yarn.lock index e4360b5..447a024 100644 --- a/yarn.lock +++ b/yarn.lock @@ -728,15 +728,15 @@ "@typescript-eslint/types" "5.47.0" eslint-visitor-keys "^3.3.0" -"@vercel/ncc@^0.36.0": - version "0.36.0" - resolved "https://registry.npmmirror.com/@vercel/ncc/-/ncc-0.36.0.tgz#1f262b86fc4f0770bbc0fc1d331d5aaa1bd47334" - integrity sha512-/ZTUJ/ZkRt694k7KJNimgmHjtQcRuVwsST2Z6XfYveQIuBbHR+EqkTc1jfgPkQmMyk/vtpxo3nVxe8CNuau86A== +"@vercel/ncc@^0.36.1": + version "0.36.1" + resolved "https://registry.npmmirror.com/@vercel/ncc/-/ncc-0.36.1.tgz#d4c01fdbbe909d128d1bf11c7f8b5431654c5b95" + integrity sha512-S4cL7Taa9yb5qbv+6wLgiKVZ03Qfkc4jGRuiUQMQ8HGBD5pcNRnHeYM33zBvJE4/zJGjJJ8GScB+WmTsn9mORw== -"@wow-actions/parse-inputs@^1.2.0": - version "1.2.0" - resolved "https://registry.npmmirror.com/@wow-actions/parse-inputs/-/parse-inputs-1.2.0.tgz#d974ee426da7efc136a72e33368725fcd0c4de30" - integrity sha512-gKAVjSlMiNn9vwwcFHZWFzZZsW60wqPsyfNWCKmsacG/1mjIDfoPpjfi3/M2S2KDSa4FwiZL+F9EV7yurzVe1w== +"@wow-actions/parse-inputs@^2.0.1": + version "2.0.1" + resolved "https://registry.npmmirror.com/@wow-actions/parse-inputs/-/parse-inputs-2.0.1.tgz#755bdb7130e1ddbf4efd70685b11448e1e7765e2" + integrity sha512-8fS+ZcmKwequ7cR9sE0o78IwVVcER2t09aTmKUoxQ9atzEycPIQeNPuyigVpMekmgThucFdmSWESLukt9XEl3g== dependencies: js-yaml "^4.1.0" lodash.camelcase "^4.3.0" @@ -1477,10 +1477,10 @@ eslint-visitor-keys@^3.3.0: resolved "https://registry.npmmirror.com/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz#f6480fa6b1f30efe2d1968aa8ac745b862469826" integrity sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA== -eslint@^8.31.0: - version "8.31.0" - resolved "https://registry.npmmirror.com/eslint/-/eslint-8.31.0.tgz#75028e77cbcff102a9feae1d718135931532d524" - integrity sha512-0tQQEVdmPZ1UtUKXjX7EMm9BlgJ08G90IhWh0PKDCb3ZLsgAOHI8fYSIzYVZej92zsgq+ft0FGsxhJ3xo2tbuA== +eslint@^8.33.0: + version "8.33.0" + resolved "https://registry.npmmirror.com/eslint/-/eslint-8.33.0.tgz#02f110f32998cb598c6461f24f4d306e41ca33d7" + integrity sha512-WjOpFQgKK8VrCnAtl8We0SUOy/oVZ5NHykyMiagV1M9r8IFpIJX7DduK6n1mpfhlG7T1NLWm2SuD8QB7KFySaA== dependencies: "@eslint/eslintrc" "^1.4.1" "@humanwhocodes/config-array" "^0.11.8" @@ -1852,10 +1852,10 @@ human-signals@^1.1.1: resolved "https://registry.npmjs.org/human-signals/-/human-signals-1.1.1.tgz#c5b1cd14f50aeae09ab6c59fe63ba3395fe4dfa3" integrity sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw== -husky@^8.0.2: - version "8.0.2" - resolved "https://registry.npmmirror.com/husky/-/husky-8.0.2.tgz#5816a60db02650f1f22c8b69b928fd6bcd77a236" - integrity sha512-Tkv80jtvbnkK3mYWxPZePGFpQ/tT3HNSs/sasF9P2YfkMezDl3ON37YN6jUUI4eTg5LcyVynlb6r4eyvOmspvg== +husky@^8.0.3: + version "8.0.3" + resolved "https://registry.npmmirror.com/husky/-/husky-8.0.3.tgz#4936d7212e46d1dea28fef29bb3a108872cd9184" + integrity sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg== ignore@^5.0.5, ignore@^5.1.4: version "5.1.8" @@ -2664,10 +2664,10 @@ prettier-linter-helpers@^1.0.0: dependencies: fast-diff "^1.1.2" -prettier@^2.8.1: - version "2.8.1" - resolved "https://registry.npmmirror.com/prettier/-/prettier-2.8.1.tgz#4e1fd11c34e2421bc1da9aea9bd8127cd0a35efc" - integrity sha512-lqGoSJBQNJidqCHE80vqZJHWHRFoNYsSpP9AjFhlhi9ODCJA541svILes/+/1GM3VaL/abZi7cpFzOpdR9UPKg== +prettier@^2.8.3: + version "2.8.3" + resolved "https://registry.npmmirror.com/prettier/-/prettier-2.8.3.tgz#ab697b1d3dd46fb4626fbe2f543afe0cc98d8632" + integrity sha512-tJ/oJ4amDihPoufT5sM0Z1SKEuKay8LfVAMlbbhnnkvt6BUserZylqo2PN+p9KeljLr0OHa2rXHU1T8reeoTrw== pretty-quick@^3.1.3: version "3.1.3" @@ -2820,6 +2820,11 @@ rimraf@^3.0.2: dependencies: glob "^7.1.3" +rimraf@^4.1.2: + version "4.1.2" + resolved "https://registry.npmmirror.com/rimraf/-/rimraf-4.1.2.tgz#20dfbc98083bdfaa28b01183162885ef213dbf7c" + integrity sha512-BlIbgFryTbw3Dz6hyoWFhKk+unCcHMSkZGrTFVAx2WmttdBSonsdtRlwiuTbDqTKr+UlXIUqJVS4QT5tUzGENQ== + run-parallel@^1.1.9: version "1.2.0" resolved "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz#66d1368da7bdf921eb9d95bd1a9229e7f21a43ee"