Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions scripts/identify-web-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function gatherFeaturesFromExplorerUrls(urls) {
continue;
}

const candidateId = url.pathname.substring(url.pathname.indexOf("features/") + 9).replace("/", "").replace(".json", "");
const candidateId = url.pathname.substring(url.pathname.indexOf("features/") + 9).replace("/", "").replace(".json", "").toLowerCase();
if (features[candidateId]) {
gatheredFeatures.add(candidateId);
}
Expand All @@ -90,8 +90,13 @@ function gatherFeaturesFromWPTUrls(urls) {

const query = url.searchParams.get("q");
const match = query.match(/feature:([a-z0-9-]+)/);
if (match && match[1] && features[match[1]]) {
gatheredFeatures.add(match[1]);
if (!match || !match[1]) {
continue;
}

const id = match[1].toLowerCase();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I"d be tempted to write a helper function rather than have to remember to write toLowerCase every time you are going to check if the feature exists, even if it's something mildly unpleasant like:

function addIfExists(feature, gatheredFeatures) {
  const id = feature.toLowerCase();
  if (features[id]) {
    gatheredFeatures.add(id);
  }
}

(mildly unpleasant because it's mutating its arguments, but I think anything nicer would end up wrapping gatheredFeatures in a class, which is probably overkill for this kind of script).

if (features[id]) {
gatheredFeatures.add(id);
}
}

Expand All @@ -107,8 +112,13 @@ function gatherFeaturesFromExplicitMentions(issueBody) {
const explicitMentions = issueBody.match(/web-features?:\s*([a-z0-9-]+)/gi) || [];
for (const mention of explicitMentions) {
const match = mention.match(/web-features?:\s*([a-z0-9-]+)/i);
if (match && match[1] && features[match[1]]) {
gatheredFeatures.add(match[1]);
if (!match || !match[1]) {
continue;
}

const id = match[1].toLowerCase();
if (features[id]) {
gatheredFeatures.add(id);
}
}

Expand All @@ -120,8 +130,9 @@ function gatherFeaturesFromExplicitMentions(issueBody) {
for (const section of sectionMentions) {
const lines = section.split(/[\r\n]+/).map(line => line.trim()).filter(line => line && !line.startsWith("###"));
for (const line of lines) {
if (features[line]) {
gatheredFeatures.add(line);
const id = line.toLowerCase();
if (features[id]) {
gatheredFeatures.add(id);
}
}
}
Expand Down