From 7023b4b4829869086c6e00b19046a6cdc9335d53 Mon Sep 17 00:00:00 2001 From: Manuel Bouza Date: Thu, 10 Oct 2019 14:38:28 +0200 Subject: [PATCH] feature/strip-identifier (#25) * Ignore non-alphanumeric chars finding project by identifier * Add babel plugin nullish coallescing operator * Refactor * Add projectId to remote services --- .babelrc | 3 ++- package.json | 1 + src/js/remoteServices.js | 47 +++++++++++++++++++++++++--------------- src/js/utils/index.js | 7 +++++- yarn.lock | 15 +++++++++++++ 5 files changed, 54 insertions(+), 19 deletions(-) diff --git a/.babelrc b/.babelrc index 1a131b9..cf69c7b 100644 --- a/.babelrc +++ b/.babelrc @@ -3,6 +3,7 @@ "plugins": [ ["@babel/plugin-proposal-decorators", { "legacy": true }], ["@babel/plugin-proposal-class-properties", { "loose": true }], - ["@babel/plugin-proposal-optional-chaining"] + "@babel/plugin-proposal-optional-chaining", + "@babel/plugin-proposal-nullish-coalescing-operator" ] } diff --git a/package.json b/package.json index 3c420fe..662755f 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "@babel/core": "^7.2.2", "@babel/plugin-proposal-class-properties": "^7.2.2", "@babel/plugin-proposal-decorators": "^7.2.2", + "@babel/plugin-proposal-nullish-coalescing-operator": "^7.4.4", "@babel/plugin-proposal-optional-chaining": "^7.2.0", "@babel/preset-env": "^7.2.2", "@babel/preset-react": "^7.0.0", diff --git a/src/js/remoteServices.js b/src/js/remoteServices.js index 6b1430c..4a8a0ca 100644 --- a/src/js/remoteServices.js +++ b/src/js/remoteServices.js @@ -11,28 +11,23 @@ export default { document.querySelector(".ItemRow--highlighted textarea")?.textContent?.trim() || document.querySelector(".ItemRow--focused textarea")?.textContent?.trim() || document.querySelector(".SingleTaskPane textarea")?.textContent?.trim(), - projectId: document => { - const match = document + projectId: document => + document .querySelector(".TaskProjectPill-projectName") ?.textContent?.trim() - ?.match(projectRegex) - return match && match[1] - }, + ?.match(projectRegex)?.[1], }, "github-pr": { name: "github", urlPatterns: ["https\\://github.com/:org/:repo/pull/:id(/:tab)"], id: (document, service, { org, repo, id }) => [service.key, org, repo, id].join("."), - description: (document, service, { org, repo, id }) => - document.querySelector(".js-issue-title")?.textContent?.trim(), - projectId: document => { - const match = document + description: document => document.querySelector(".js-issue-title")?.textContent?.trim(), + projectId: document => + document .querySelector(".js-issue-title") ?.textContent.trim() - ?.match(projectRegex) - return match && match[1] - }, + ?.match(projectRegex)?.[1], }, "github-issue": { @@ -41,6 +36,11 @@ export default { id: (document, service, { org, repo, id }) => [service.key, org, repo, id].join("."), description: (document, service, { org, repo, id }) => document.querySelector(".js-issue-title")?.textContent?.trim(), + projectId: document => + document + .querySelector(".js-issue-title") + ?.textContent?.trim() + ?.match(projectRegex)?.[1], }, jira: { @@ -87,12 +87,22 @@ export default { urlPatterns: ["https\\://trello.com/c/:id/:title"], description: (document, service, { title }) => document.querySelector(".js-title-helper")?.textContent?.trim() || title, + projectId: document => + document + .querySelector(".js-title-helper") + ?.textContent?.trim() + ?.match(projectRegex)?.[1], }, youtrack: { name: "youtrack", urlPatterns: ["https\\://:org.myjetbrains.com/youtrack/issue/:id"], description: document => document.querySelector("yt-issue-body h1")?.textContent?.trim(), + projectId: document => + document + .querySelector("yt-issue-body h1") + ?.textContent?.trim() + ?.match(projectRegex)?.[1], }, wrike: { @@ -107,13 +117,11 @@ export default { id: ["t", "ot"], }, description: document => document.querySelector(".title-field-ghost")?.textContent?.trim(), - projectId: document => { - const match = document + projectId: document => + document .querySelector(".header-title__main") ?.textContent?.trim() - ?.match(projectRegex) - return match && match[1] - }, + ?.match(projectRegex)?.[1], }, wunderlist: { @@ -123,5 +131,10 @@ export default { document .querySelector(".taskItem.selected .taskItem-titleWrapper-title") ?.textContent?.trim(), + projectId: document => + document + .querySelector(".taskItem.selected .taskItem-titleWrapper-title") + ?.textContent?.trim() + ?.match(projectRegex)?.[1], }, } diff --git a/src/js/utils/index.js b/src/js/utils/index.js index 20127eb..be245f3 100644 --- a/src/js/utils/index.js +++ b/src/js/utils/index.js @@ -23,6 +23,7 @@ export const ERROR_UNKNOWN = "unknown" export const noop = () => null export const asArray = input => (Array.isArray(input) ? input : [input]) +export const removeNonAlphanumChars = input => String(input ?? "").replace(/[\W_]/g, "") export const findProjectBy = prop => val => projects => { if (!val) { @@ -30,7 +31,11 @@ export const findProjectBy = prop => val => projects => { } return compose( - find(pathEq(prop, val)), + find( + project => + project[prop] === val || + removeNonAlphanumChars(project[prop]) === removeNonAlphanumChars(val), + ), flatMap(get("options")), )(projects) } diff --git a/yarn.lock b/yarn.lock index 1c64445..d92df2f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -280,6 +280,14 @@ "@babel/helper-plugin-utils" "^7.0.0" "@babel/plugin-syntax-json-strings" "^7.2.0" +"@babel/plugin-proposal-nullish-coalescing-operator@^7.4.4": + version "7.4.4" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-nullish-coalescing-operator/-/plugin-proposal-nullish-coalescing-operator-7.4.4.tgz#41c360d59481d88e0ce3a3f837df10121a769b39" + integrity sha512-Amph7Epui1Dh/xxUxS2+K22/MUi6+6JVTvy3P58tja3B6yKTSjwwx0/d83rF7551D6PVSSoplQb8GCwqec7HRw== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-nullish-coalescing-operator" "^7.2.0" + "@babel/plugin-proposal-object-rest-spread@^7.5.5": version "7.5.5" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.5.5.tgz#61939744f71ba76a3ae46b5eea18a54c16d22e58" @@ -348,6 +356,13 @@ dependencies: "@babel/helper-plugin-utils" "^7.0.0" +"@babel/plugin-syntax-nullish-coalescing-operator@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-nullish-coalescing-operator/-/plugin-syntax-nullish-coalescing-operator-7.2.0.tgz#f75083dfd5ade73e783db729bbd87e7b9efb7624" + integrity sha512-lRCEaKE+LTxDQtgbYajI04ddt6WW0WJq57xqkAZ+s11h4YgfRHhVA/Y2VhfPzzFD4qeLHWg32DMp9HooY4Kqlg== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-object-rest-spread@^7.0.0", "@babel/plugin-syntax-object-rest-spread@^7.2.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-object-rest-spread/-/plugin-syntax-object-rest-spread-7.2.0.tgz#3b7a3e733510c57e820b9142a6579ac8b0dfad2e"