From 522892dbf2540053f5ce082f0967799a98cbef91 Mon Sep 17 00:00:00 2001 From: Paul Meinhardt Date: Thu, 29 Nov 2018 09:01:57 +0000 Subject: [PATCH] [#110] Add support for Ora (#111) * [#110] Add support for Ora * Bump version number to 2.1.0 --- README.md | 11 ++--- package.json | 2 +- spec/adapters/ora-spec.js | 85 +++++++++++++++++++++++++++++++++++++ src/common/adapters/jira.js | 2 +- src/common/adapters/ora.js | 28 ++++++++++++ src/common/search.js | 3 +- 6 files changed, 123 insertions(+), 8 deletions(-) create mode 100644 spec/adapters/ora-spec.js create mode 100644 src/common/adapters/ora.js diff --git a/README.md b/README.md index 87ff7d79..8c89cb99 100644 --- a/README.md +++ b/README.md @@ -29,11 +29,12 @@ Tickety-Tick helps you create branches and commits for a few ticket systems. Currently, we support: -- GitHub -- GitLab -- Jira -- Pivotal Tracker -- Trello +- [GitHub](https://github.com/) +- [GitLab](https://gitlab.com/) +- [Jira](https://www.atlassian.com/software/jira) +- [Ora](https://ora.pm/) +- [Pivotal Tracker](https://www.pivotaltracker.com/) +- [Trello](https://trello.com/) ## Installation diff --git a/package.json b/package.json index a051744d..e79f4195 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "private": true, - "version": "2.0.1", + "version": "2.1.0", "name": "tickety-tick", "description": "A browser extension that helps you to create commit messages and branch names from story trackers.", "author": "Bodo Tasche ", diff --git a/spec/adapters/ora-spec.js b/spec/adapters/ora-spec.js new file mode 100644 index 00000000..61c39acd --- /dev/null +++ b/spec/adapters/ora-spec.js @@ -0,0 +1,85 @@ +import { JSDOM } from 'jsdom'; + +import adapter from '../../src/common/adapters/ora'; + +function task({ id, title, type }) { + return ` +
+
+ +
+
+
+ +
+
+
+ +
+
+
+
+
+

A description paragraph

+
    +
  • list item 0
  • +
  • list item 1 with a mention #42)
  • +
  • list item 2
  • +
+

…and more text

+
+
+
+
+
+ `; +} + +describe('ora adapter', () => { + const loc = { host: 'ora.pm', pathname: '/project/53123/kanban/task/641617' }; + + function doc(body) { + const { window } = new JSDOM(`${body}`); + return window.document; + } + + it('returns null if it is on a different page', () => { + adapter.inspect({ host: 'github.com' }, null, (err, res) => { + expect(err).toBe(null); + expect(res).toBe(null); + }); + }); + + it('extracts feature tickets', () => { + const ticket = { id: 'ORA12', title: 'Random Ora task title', type: 'feature' }; + adapter.inspect(loc, doc(task(ticket)), (err, res) => { + expect(err).toBe(null); + expect(res).toEqual([ticket]); + }); + }); + + it('extracts chore tickets', () => { + const ticket = { id: 'ORA12', title: 'Random Ora task title', type: 'chore' }; + adapter.inspect(loc, doc(task(ticket)), (err, res) => { + expect(err).toBe(null); + expect(res).toEqual([ticket]); + }); + }); + + it('extracts bug tickets', () => { + const ticket = { id: 'ORA12', title: 'Random Ora task title', type: 'bug' }; + adapter.inspect(loc, doc(task(ticket)), (err, res) => { + expect(err).toBe(null); + expect(res).toEqual([ticket]); + }); + }); +}); diff --git a/src/common/adapters/jira.js b/src/common/adapters/jira.js index bd497ca7..17c7d0d3 100644 --- a/src/common/adapters/jira.js +++ b/src/common/adapters/jira.js @@ -48,7 +48,7 @@ const adapter = { } if ($has('.ghx-columns .ghx-issue.ghx-selected', doc)) { - // Board view, when a ticket is opened in a modal window + // board view, when a ticket is opened in a modal window const issue = $find('.ghx-columns .ghx-issue.ghx-selected', doc); const id = $attr('.ghx-key', issue, 'aria-label'); const title = $text('.ghx-summary', issue); diff --git a/src/common/adapters/ora.js b/src/common/adapters/ora.js new file mode 100644 index 00000000..3fccba7a --- /dev/null +++ b/src/common/adapters/ora.js @@ -0,0 +1,28 @@ +import { + $find, + $has, + $text, +} from './helpers'; + +function identifier(value) { + if (typeof value === 'string') return value.replace(/^#/, ''); + return null; +} + +const adapter = { + inspect(loc, doc, fn) { + if (loc.host !== 'ora.pm') return fn(null, null); + + if ($has('#task-modal.single-task-modal', doc)) { + const task = $find('#task-modal.single-task-modal', doc); + const id = identifier($text('.task-id', task)); + const title = $text('#task-title', task); + const type = $text('[data-ng-if="features[\'task_types\']"]', task) || 'feature'; + return fn(null, [{ id, title, type }]); + } + + return fn(null, null); + }, +}; + +export default adapter; diff --git a/src/common/search.js b/src/common/search.js index da6ae98b..5583d2fc 100644 --- a/src/common/search.js +++ b/src/common/search.js @@ -1,10 +1,11 @@ import GitHub from './adapters/github'; import GitLab from './adapters/gitlab'; import Jira from './adapters/jira'; +import Ora from './adapters/ora'; import Pivotal from './adapters/pivotal'; import Trello from './adapters/trello'; -const stdadapters = [GitHub, GitLab, Jira, Pivotal, Trello]; +const stdadapters = [GitHub, GitLab, Jira, Ora, Pivotal, Trello]; function search(adapters, loc, doc, fn) { let pending = adapters.length;