diff --git a/src/zen/live-folders/providers/GithubLiveFolder.sys.mjs b/src/zen/live-folders/providers/GithubLiveFolder.sys.mjs index f565e7b8f..ce3ef4cb9 100644 --- a/src/zen/live-folders/providers/GithubLiveFolder.sys.mjs +++ b/src/zen/live-folders/providers/GithubLiveFolder.sys.mjs @@ -198,45 +198,36 @@ export class nsGithubLiveFolderProvider extends nsZenLiveFolderProvider { } const document = new DOMParser().parseFromString(text, "text/html"); - const issues = document.querySelectorAll( - "div[class^=IssueItem-module__defaultRepoContainer]" + const links = document.querySelectorAll( + 'a[data-testid="issue-listitem-title-link"]' ); const items = []; const activeRepos = new Set(); - if (issues.length) { - const authors = document.querySelectorAll( - "a[class^=IssueItem-module__authorCreatedLink]" + for (const link of links) { + const issueUrl = new URL(link.getAttribute("href"), this.state.url); + const pathMatch = issueUrl.pathname.match( + /^\/([^/]+\/[^/]+)\/(?:issues|pull)\/([0-9]+)/ ); - const titles = document.querySelectorAll( - "div[class^=Title-module__container]" - ); - const links = document.querySelectorAll( - '[data-testid="issue-pr-title-link"]' - ); - - for (let i = 0; i < issues.length; i++) { - const [rawRepo, rawNumber] = issues[i].childNodes; - const author = authors[i]?.textContent; - const title = titles[i]?.textContent; - const issueUrl = links[i]?.href; - - const repo = rawRepo.textContent?.trim(); - if (repo) { - activeRepos.add(repo); - } - - const numberMatch = rawNumber?.textContent?.match(/[0-9]+/); - const number = numberMatch?.[0] ?? ""; - - items.push({ - title, - subtitle: author, - icon: "chrome://browser/content/zen-images/favicons/github.svg", - url: "https://github.com" + issueUrl, - id: `${repo}#${number}`, - }); + if (!pathMatch) { + continue; } + + const [, repo, number] = pathMatch; + activeRepos.add(repo); + + const author = link + .closest("li") + ?.querySelector('[data-testid="author-filter-link"]') + ?.lastChild?.textContent.trim(); + + items.push({ + title: link.textContent.trim(), + subtitle: author, + icon: "chrome://browser/content/zen-images/favicons/github.svg", + url: issueUrl.href, + id: `${repo}#${number}`, + }); } return { diff --git a/src/zen/tests/live-folders/browser_github_live_folder.js b/src/zen/tests/live-folders/browser_github_live_folder.js index e56be019e..c87d181d5 100644 --- a/src/zen/tests/live-folders/browser_github_live_folder.js +++ b/src/zen/tests/live-folders/browser_github_live_folder.js @@ -130,18 +130,22 @@ add_task(async function test_html_parsing_logic() { const mockHtml = ` -
-
mozilla/zen#101
- UserA -
Fix the login bug
- -
-
-
mozilla/zen#102
- UserB -
Add dark mode
- -
+ `; @@ -158,12 +162,15 @@ add_task(async function test_html_parsing_logic() { Assert.equal(items[0].title, "Fix the login bug"); Assert.equal(items[0].subtitle, "UserA"); Assert.equal(items[0].id, "mozilla/zen#101"); - Assert.equal(items[0].url, "https://github.com/issues/101"); + Assert.equal( + items[0].url, + "https://github.com/zen-browser/desktop/issues/101" + ); Assert.equal(items[1].title, "Add dark mode"); Assert.equal(items[1].subtitle, "UserB"); Assert.equal(items[1].id, "mozilla/zen#102"); - Assert.equal(items[1].url, "https://github.com/pull/102"); + Assert.equal(items[1].url, "https://github.com/zen-browser/desktop/pull/102"); sandbox.restore(); });