-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
90 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
}, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters