Skip to content

Commit b996949

Browse files
authored
[401] Fix GitHub adapter bug label detection (#402)
GitHub's markup for issues changed, so that our detection for `bug` labels no longer worked. This adjusts our selectors, so that we can figure out whether an issue is labelled as bug or not. Fixes: #401 Ticket: #401 On the side this also remove support for GH projects. Projects work differently in GitHub now. They belong to the user/organization, not to one repository. We need to handle them differently. The current adapter's implementation does not work any more.
1 parent 3f36110 commit b996949

File tree

2 files changed

+20
-94
lines changed

2 files changed

+20
-94
lines changed

src/core/adapters/github.test.ts

Lines changed: 7 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -22,49 +22,27 @@ const pages = {
2222
<span class="gh-header-number">#12</span>
2323
</h1>
2424
<div class="js-issue-labels">
25-
<a class="sidebar-labels-style" title="bug">bug</a>
25+
<a class="IssueLabel hx_IssueLabel" data-name="bug">bug</a>
2626
</div>
2727
</div>`,
2828
indexpage: `
2929
<div class="js-check-all-container">
30-
<ul>
31-
<li id="issue_12" class="js-issue-row selected">
30+
<div>
31+
<div id="issue_12" class="js-issue-row selected">
3232
<input type="checkbox" class="js-issues-list-check" name="issues[]" value="12">
3333
<a href="/bitcrowd/tickety-tick/issues/12" class="h4 js-navigation-open">
3434
A Selected GitHub Issue
3535
</a>
36-
<span class="labels">
36+
<span class="lh-default">
3737
<a href="#" class="IssueLabel">bug</a>
3838
</span>
39-
</li>
40-
<li id="issue_11" class="js-issue-row">
39+
</div>
40+
<div id="issue_11" class="js-issue-row">
4141
<input type="checkbox" class="js-issues-list-check" name="issues[]" value="11">
4242
<a href="/bitcrowd/tickety-tick/issues/11" class="h4 js-navigation-open">
4343
A GitHub Issue
4444
</a>
45-
<span class="labels"></span>
46-
</li>
47-
</ul>
48-
</div>`,
49-
projectpage: `
50-
<div class="project-columns">
51-
<div class="project-card"
52-
data-card-state='["open"]'
53-
data-card-label='["enhancement"]'
54-
data-card-title='["an","example","feature","ticket","42","#42"]'>
55-
<a class="h5">An Example Feature Ticket</a>
56-
</div>
57-
<div class="project-card"
58-
data-card-state='["open"]'
59-
data-card-label='["bug"]'
60-
data-card-title='["an","example","bug","ticket","43","#43"]'>
61-
<a class="h5">An Example Bug Ticket</a>
62-
</div>
63-
<div class="project-card"
64-
data-card-state='["closed"]'
65-
data-card-label='["bug"]'
66-
data-card-title='["an","example","bug","ticket","which","was","closed","and","should","not","be","found","44","#44"]'>
67-
<a class="h5">An Example Bug Ticket which was closed and should not be found</a>
45+
</div>
6846
</div>
6947
</div>`,
7048
},
@@ -109,28 +87,6 @@ const pages = {
10987
</li>
11088
</ul>
11189
</div>`,
112-
113-
projectpage: `
114-
<div class="project-columns">
115-
<div class="project-card"
116-
data-card-state='["open"]'
117-
data-card-label='["enhancement"]'
118-
data-card-title='["an","example","feature","ticket","42","#42"]'>
119-
<a class="h5">An Example Feature Ticket</a>
120-
</div>
121-
<div class="project-card"
122-
data-card-state='["open"]'
123-
data-card-label='["bug"]'
124-
data-card-title='["an","example","bug","ticket","43","#43"]'>
125-
<a class="h5">An Example Bug Ticket</a>
126-
</div>
127-
<div class="project-card"
128-
data-card-state='["closed"]'
129-
data-card-label='["bug"]'
130-
data-card-title='["an","example","bug","ticket","which","was","closed","and","should","not","be","found","44","#44"]'>
131-
<a class="h5">An Example Bug Ticket which was closed and should not be found</a>
132-
</div>
133-
</div>`,
13490
},
13591
};
13692

@@ -140,7 +96,6 @@ const url = (path: string) =>
14096
Object.keys(selectors).forEach((variant) => {
14197
const html = pages[variant as keyof typeof selectors];
14298

143-
// eslint-disable-next-line jest/valid-describe
14499
describe(`github adapter (${variant})`, () => {
145100
function doc(body = "") {
146101
const { window } = new JSDOM(`<html><body>${body}</body></html>`);
@@ -187,23 +142,5 @@ Object.keys(selectors).forEach((variant) => {
187142
},
188143
]);
189144
});
190-
191-
it("extracts tickets from project pages", async () => {
192-
const result = await scan(url("projects/1"), doc(html.projectpage));
193-
expect(result).toEqual([
194-
{
195-
id: "42",
196-
title: "An Example Feature Ticket",
197-
type: "feature",
198-
url: "https://github.com/test-org/test-project/issues/42",
199-
},
200-
{
201-
id: "43",
202-
title: "An Example Bug Ticket",
203-
type: "bug",
204-
url: "https://github.com/test-org/test-project/issues/43",
205-
},
206-
]);
207-
});
208145
});
209146
});

src/core/adapters/github.ts

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import { hasRequiredDetails } from "./utils";
1818
export const selectors = {
1919
default: {
2020
issuesPage: ".js-check-all-container .js-issue-row.selected",
21-
issuesPageLabel: ".labels .IssueLabel",
21+
issuesPageLabel: ".lh-default .IssueLabel",
2222
issuePage: ".js-issues-results .gh-header-number",
23-
issuePageLabel: '.js-issue-labels .sidebar-labels-style[title="bug"]',
23+
issuePageLabel: '.js-issue-labels .IssueLabel[data-name="bug" i]',
2424
},
2525
legacy: {
2626
issuesPage: ".issues-listing .js-issue-row.selected",
@@ -38,16 +38,21 @@ async function attempt(
3838
if ($has(select.issuesPage, doc)) {
3939
const issues = $all(select.issuesPage, doc);
4040

41-
const tickets = issues.map((issue) => {
41+
const tickets = issues.reduce((acc, issue) => {
4242
const id = $value("input.js-issues-list-check", issue);
4343
const title = $text("a.js-navigation-open", issue);
44+
45+
if (!id || !title) return acc;
46+
4447
const labels = $all(select.issuesPageLabel, issue);
4548
const type = labels.some((l) => /bug/i.test(`${l.textContent}`))
4649
? "bug"
4750
: "feature";
4851

49-
return { id, title, type };
50-
});
52+
const ticket = { id, title, type };
53+
acc.push(ticket);
54+
return acc;
55+
}, <TicketData[]>[]);
5156

5257
return tickets;
5358
}
@@ -56,27 +61,11 @@ async function attempt(
5661
if ($has(select.issuePage, doc)) {
5762
const id = $text(".gh-header-number", doc)?.replace(/^#/, "");
5863
const title = $text(".js-issue-title", doc);
59-
const type = $has(select.issuePageLabel, doc) ? "bug" : "feature";
60-
const tickets = [{ id, title, type }];
61-
return tickets;
62-
}
6364

64-
// project page
65-
if ($has(".project-columns .project-card", doc)) {
66-
const openProjectCardSelector =
67-
".project-columns .project-card[data-card-state='[\"open\"]']";
68-
const projectCards = $all(openProjectCardSelector, doc);
69-
70-
const tickets = projectCards.map((card) => {
71-
const id = JSON.parse(card.dataset.cardTitle ?? "null").slice(-2, -1)[0];
72-
const type = JSON.parse(card.dataset.cardLabel ?? "null").includes("bug")
73-
? "bug"
74-
: "feature";
75-
const title = $text("a.h5", card);
76-
77-
return { id, title, type };
78-
});
65+
if (!id || !title) return [];
7966

67+
const type = $has(select.issuePageLabel, doc) ? "bug" : "feature";
68+
const tickets = [{ id, title, type }];
8069
return tickets;
8170
}
8271

0 commit comments

Comments
 (0)