From 3e443caaa345b42a4138a620ccb656d7cc32c6ef Mon Sep 17 00:00:00 2001 From: koleok Date: Tue, 12 Jul 2022 00:41:47 -0400 Subject: [PATCH] Support outputing multiple issues as json --- action.yml | 2 ++ dist/index.js | 20 ++++++++--- package.json | 5 ++- src/main.ts | 26 ++++++++++++--- yarn.lock | 91 --------------------------------------------------- 5 files changed, 40 insertions(+), 104 deletions(-) diff --git a/action.yml b/action.yml index 351e375..38564e4 100644 --- a/action.yml +++ b/action.yml @@ -5,6 +5,8 @@ inputs: description: "Linear API key generated from https://linear.app/settings/api . (e.g. `lin_api_*)`" required: true outputs: + multiple: + description: "Find multiple issues and output a json array of results" linear-issue-id: description: "The unique identifier of the Linear issue. (UUID)" linear-issue-identifier: diff --git a/dist/index.js b/dist/index.js index 855d1e7..35c7b93 100644 --- a/dist/index.js +++ b/dist/index.js @@ -95,14 +95,14 @@ const main = async () => { return; } for (const team of teams) { - // TODO: Iterate over multiple matches and not just first match - const regexString = `${team.key}-(?\\d+)`; + const regexString = `${team.key}-(\\d+)`; const regex = new RegExp(regexString, "gim"); const haystack = prBranch + " " + prTitle + " " + prBody; (0, core_1.debug)(`Checking PR for indentifier "${regexString}" in "${haystack}"`); - const check = regex.exec(haystack); - const issueNumber = check?.groups?.issueNumber; - if (issueNumber) { + const outputMultiple = (0, core_1.getInput)("output-multiple"); + const matches = haystack.match(regex); + if (!outputMultiple && matches?.length) { + const issueNumber = matches[0].split("-")[1]; (0, core_1.debug)(`Found issue number: ${issueNumber}`); const issue = await (0, getIssueByTeamAndNumber_1.default)(linearClient, team, Number(issueNumber)); if (issue) { @@ -114,6 +114,16 @@ const main = async () => { (0, core_1.setOutput)("linear-issue-url", issue.url); (0, core_1.setOutput)("linear-issue-title", issue.title); (0, core_1.setOutput)("linear-issue-description", issue.description); + } + } + if (outputMultiple && matches?.length) { + const issueNumbers = matches.map((match) => match.split("-")[1]); + (0, core_1.debug)(`Found issue numbers: ${issueNumbers.toString()}`); + const issues = await Promise.all(issueNumbers.map((issueNumber) => (0, getIssueByTeamAndNumber_1.default)(linearClient, team, Number(issueNumber)))); + if (issues.length) { + (0, core_1.setOutput)("linear-team-id", team.id); + (0, core_1.setOutput)("linear-team-key", team.key); + (0, core_1.setOutput)("linear-issues", JSON.stringify(issues)); return; } } diff --git a/package.json b/package.json index a612782..d55cd65 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "action-create-linear-issue", - "version": "1.0.0", + "version": "0.0.3", "description": "", "main": "lib/main.js", "private": true, @@ -21,7 +21,6 @@ "devDependencies": { "@vercel/ncc": "^0.33.4", "prettier": "^2.6.2", - "typescript": "^4.6.4", - "ts-node": "^10.7.0" + "typescript": "^4.6.4" } } diff --git a/src/main.ts b/src/main.ts index 074ca97..638a4f8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -36,15 +36,15 @@ const main = async () => { } for (const team of teams) { - // TODO: Iterate over multiple matches and not just first match - const regexString = `${team.key}-(?\\d+)`; + const regexString = `${team.key}-(\\d+)`; const regex = new RegExp(regexString, "gim"); const haystack = prBranch + " " + prTitle + " " + prBody; debug(`Checking PR for indentifier "${regexString}" in "${haystack}"`); - const check = regex.exec(haystack); - const issueNumber = check?.groups?.issueNumber; + const outputMultiple = getInput("output-multiple"); + const matches = haystack.match(regex); - if (issueNumber) { + if (!outputMultiple && matches?.length) { + const issueNumber = matches[0].split("-")[1]; debug(`Found issue number: ${issueNumber}`); const issue = await getIssueByTeamAndNumber( linearClient, @@ -60,6 +60,22 @@ const main = async () => { setOutput("linear-issue-url", issue.url); setOutput("linear-issue-title", issue.title); setOutput("linear-issue-description", issue.description); + } + } + + if (outputMultiple && matches?.length) { + const issueNumbers = matches.map((match) => match.split("-")[1]); + debug(`Found issue numbers: ${issueNumbers.toString()}`); + const issues = await Promise.all( + issueNumbers.map((issueNumber) => + getIssueByTeamAndNumber(linearClient, team, Number(issueNumber)) + ) + ); + + if (issues.length) { + setOutput("linear-team-id", team.id); + setOutput("linear-team-key", team.key); + setOutput("linear-issues", JSON.stringify(issues)); return; } } diff --git a/yarn.lock b/yarn.lock index 4c24e26..83ee11b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -26,18 +26,6 @@ dependencies: tunnel "0.0.6" -"@cspotcode/source-map-consumer@0.8.0": - version "0.8.0" - resolved "https://registry.yarnpkg.com/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz#33bf4b7b39c178821606f669bbc447a6a629786b" - integrity sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg== - -"@cspotcode/source-map-support@0.7.0": - version "0.7.0" - resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.7.0.tgz#4789840aa859e46d2f3173727ab707c66bf344f5" - integrity sha512-X4xqRHqN8ACt2aHVe51OxeA2HjbcL4MqFqXkrmQszJ1NOUuUu5u6Vqx/0lZSVNku7velL5FC/s5uEAj1lsBMhA== - dependencies: - "@cspotcode/source-map-consumer" "0.8.0" - "@graphql-typed-document-node/core@^3.1.0": version "3.1.1" resolved "https://registry.yarnpkg.com/@graphql-typed-document-node/core/-/core-3.1.1.tgz#076d78ce99822258cf813ecc1e7fa460fa74d052" @@ -138,66 +126,21 @@ dependencies: "@octokit/openapi-types" "^11.2.0" -"@tsconfig/node10@^1.0.7": - version "1.0.8" - resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.8.tgz#c1e4e80d6f964fbecb3359c43bd48b40f7cadad9" - integrity sha512-6XFfSQmMgq0CFLY1MslA/CPUfhIL919M1rMsa5lP2P097N2Wd1sSX0tx1u4olM16fLNhtHZpRhedZJphNJqmZg== - -"@tsconfig/node12@^1.0.7": - version "1.0.9" - resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.9.tgz#62c1f6dee2ebd9aead80dc3afa56810e58e1a04c" - integrity sha512-/yBMcem+fbvhSREH+s14YJi18sp7J9jpuhYByADT2rypfajMZZN4WQ6zBGgBKp53NKmqI36wFYDb3yaMPurITw== - -"@tsconfig/node14@^1.0.0": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.1.tgz#95f2d167ffb9b8d2068b0b235302fafd4df711f2" - integrity sha512-509r2+yARFfHHE7T6Puu2jjkoycftovhXRqW328PDXTVGKihlb1P8Z9mMZH04ebyajfRY7dedfGynlrFHJUQCg== - -"@tsconfig/node16@^1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.2.tgz#423c77877d0569db20e1fc80885ac4118314010e" - integrity sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA== - "@vercel/ncc@^0.33.4": version "0.33.4" resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.33.4.tgz#e44a87511f583b7ba88e4b9ae90eeb7ba252b872" integrity sha512-ln18hs7dMffelP47tpkaR+V5Tj6coykNyxJrlcmCormPqRQjB/Gv4cu2FfBG+PMzIfdZp2CLDsrrB1NPU22Qhg== -acorn-walk@^8.1.1: - version "8.2.0" - resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.2.0.tgz#741210f2e2426454508853a2f44d0ab83b7f69c1" - integrity sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA== - -acorn@^8.4.1: - version "8.7.1" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.7.1.tgz#0197122c843d1bf6d0a5e83220a788f278f63c30" - integrity sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A== - -arg@^4.1.0: - version "4.1.3" - resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089" - integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA== - before-after-hook@^2.2.0: version "2.2.2" resolved "https://registry.yarnpkg.com/before-after-hook/-/before-after-hook-2.2.2.tgz#a6e8ca41028d90ee2c24222f201c90956091613e" integrity sha512-3pZEU3NT5BFUo/AD5ERPWOgQOCZITni6iavr5AUw5AUwQjMlI0kzu5btnyD39AF0gUEsDPwJT+oY1ORBJijPjQ== -create-require@^1.1.0: - version "1.1.1" - resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333" - integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ== - deprecation@^2.0.0, deprecation@^2.3.1: version "2.3.1" resolved "https://registry.yarnpkg.com/deprecation/-/deprecation-2.3.1.tgz#6368cbdb40abf3373b525ac87e4a260c3a700919" integrity sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ== -diff@^4.0.1: - version "4.0.2" - resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d" - integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A== - graphql@^15.4.0: version "15.8.0" resolved "https://registry.yarnpkg.com/graphql/-/graphql-15.8.0.tgz#33410e96b012fa3bdb1091cc99a94769db212b38" @@ -216,11 +159,6 @@ isomorphic-unfetch@^3.1.0: node-fetch "^2.6.1" unfetch "^4.2.0" -make-error@^1.1.1: - version "1.3.6" - resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2" - integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw== - node-fetch@^2.6.1, node-fetch@^2.6.7: version "2.6.7" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad" @@ -245,25 +183,6 @@ tr46@~0.0.3: resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o= -ts-node@^10.7.0: - version "10.7.0" - resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.7.0.tgz#35d503d0fab3e2baa672a0e94f4b40653c2463f5" - integrity sha512-TbIGS4xgJoX2i3do417KSaep1uRAW/Lu+WAL2doDHC0D6ummjirVOXU5/7aiZotbQ5p1Zp9tP7U6cYhA0O7M8A== - dependencies: - "@cspotcode/source-map-support" "0.7.0" - "@tsconfig/node10" "^1.0.7" - "@tsconfig/node12" "^1.0.7" - "@tsconfig/node14" "^1.0.0" - "@tsconfig/node16" "^1.0.2" - acorn "^8.4.1" - acorn-walk "^8.1.1" - arg "^4.1.0" - create-require "^1.1.0" - diff "^4.0.1" - make-error "^1.1.1" - v8-compile-cache-lib "^3.0.0" - yn "3.1.1" - tunnel@0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/tunnel/-/tunnel-0.0.6.tgz#72f1314b34a5b192db012324df2cc587ca47f92c" @@ -284,11 +203,6 @@ universal-user-agent@^6.0.0: resolved "https://registry.yarnpkg.com/universal-user-agent/-/universal-user-agent-6.0.0.tgz#3381f8503b251c0d9cd21bc1de939ec9df5480ee" integrity sha512-isyNax3wXoKaulPDZWHQqbmIx1k2tb9fb3GGDBRxCscfYV2Ch7WxPArBsFEG8s/safwXTT7H4QGhaIkTp9447w== -v8-compile-cache-lib@^3.0.0: - version "3.0.1" - resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf" - integrity sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg== - webidl-conversions@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" @@ -306,8 +220,3 @@ wrappy@1: version "1.0.2" resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= - -yn@3.1.1: - version "3.1.1" - resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50" - integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==