feature/strip-identifier (#25)

* Ignore non-alphanumeric chars finding project by identifier

* Add babel plugin nullish coallescing operator

* Refactor

* Add projectId to remote services
This commit is contained in:
Manuel Bouza 2019-10-10 14:38:28 +02:00 committed by Tobias Miesel
parent 53be150788
commit 7023b4b482
5 changed files with 54 additions and 19 deletions

View File

@ -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"
]
}

View File

@ -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",

View File

@ -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],
},
}

View File

@ -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)
}

View File

@ -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"