Skip to content

Commit

Permalink
Add Linear.app adapter (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtarnovan authored Apr 26, 2022
1 parent 7d56bfb commit b6d5d32
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Currently, we support:
- [Notion](https://www.notion.so/)
- [Tara](https://app.tara.ai/)
- [Trello](https://trello.com/)
- [Linear](https://linear.app)

Your ticket system is missing? Go ahead and implement an adapter for it! We are always happy about contributions and here to support you 👋.

Expand Down
43 changes: 43 additions & 0 deletions src/core/adapters/linear.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @jest-environment node
*/

import { JSDOM } from "jsdom";

import scan from "./linear";

const pages = {
issuePage: {
url: new URL(
"https://linear.app/my_team/issue/FOO-1/do-something-interesting"
),
document: "<span title='Edit issue title'>Do something interesting</span>",
},
};

describe("linear adapter", () => {
function doc(body = "") {
const { window } = new JSDOM(`<html><body>${body}</body></html>`);
return window.document;
}

it("returns an empty array if it is on a different page", async () => {
const result = await scan(new URL("https://example.com"), doc());
expect(result).toEqual([]);
});

it("extracts the ticket from the issue page", async () => {
const result = await scan(
pages.issuePage.url,
doc(pages.issuePage.document)
);
expect(result).toEqual([
{
id: "FOO-1",
title: "Do something interesting",
type: "issue",
url: pages.issuePage.url.toString(),
},
]);
});
});
34 changes: 34 additions & 0 deletions src/core/adapters/linear.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Linear adapter
*
* The adapter extracts ticket information from the markup. Note that linear
* obfuscates classes, so the DOM selectors are probably not reliable (for one,
* they are locale dependent, but at this time Linear is only available in
* English).
*
*/

import { match } from "micro-match";

import type { TicketData } from "../types";
import { $text } from "./dom-helpers";

async function scan(url: URL, document: Document): Promise<TicketData[]> {
if (url.hostname !== "linear.app") return [];

const { id, issueType } = match("/:team/:issueType/:id/:slug", url.pathname);
const title = $text('[title="Edit issue title"]', document);

if (!id) return [];

const ticket = {
id,
url: url.toString(),
title,
type: issueType,
} as TicketData;

return [ticket];
}

export default scan;
11 changes: 10 additions & 1 deletion src/core/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Ticket } from "../types";
import GitHub from "./adapters/github";
import GitLab from "./adapters/gitlab";
import Jira from "./adapters/jira";
import Linear from "./adapters/linear";
import Notion from "./adapters/notion";
import Tara from "./adapters/tara";
import Trello from "./adapters/trello";
Expand Down Expand Up @@ -36,7 +37,15 @@ async function search(adapters: Adapter[], url: URL, document: Document) {
return aggregate(results);
}

const stdadapters: Adapter[] = [GitHub, GitLab, Jira, Notion, Tara, Trello];
const stdadapters: Adapter[] = [
GitHub,
GitLab,
Jira,
Linear,
Notion,
Tara,
Trello,
];

export { search, stdadapters };
export default search.bind(null, stdadapters);
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ exports[`no-tickets with no errors renders a hint 1`] = `
<p>
Tickety-Tick currently supports
<br />
GitHub, GitLab, Jira, Trello, Notion and Tara.
GitHub, GitLab, Jira, Trello, Notion, Tara and Linear.
</p>
<h6>
Missing anything or found a bug?
Expand Down
2 changes: 1 addition & 1 deletion src/popup/components/no-tickets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function Hint() {
<p>
Tickety-Tick currently supports
<br />
GitHub, GitLab, Jira, Trello, Notion and Tara.
GitHub, GitLab, Jira, Trello, Notion, Tara and Linear.
</p>
<h6>Missing anything or found a bug?</h6>
<p className="pb-1">
Expand Down

0 comments on commit b6d5d32

Please sign in to comment.