Skip to content

Commit

Permalink
fix: try to fix "Cannot read properties of undefined (reading 'length')"
Browse files Browse the repository at this point in the history
fix getState results

re #11
  • Loading branch information
bubkoo committed Jan 30, 2023
1 parent 29f1129 commit 48e18c6
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 41 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
}
}
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"`)
}
Expand Down
2 changes: 1 addition & 1 deletion src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
26 changes: 16 additions & 10 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
45 changes: 25 additions & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 48e18c6

Please sign in to comment.