Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 1 addition & 9 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ async function getModifiedFilenames(forge, urlInfo, requestHeaders, pr) {
return items
}

// returns the key if the item is in the array
export function addIfIncluded(array, item, key) {
if (array.includes(item)) {
return key
}
return null
}

// cap on the number of per-PR file fetches in flight at once: firing one
// request per PR on a repo with 100+ open PRs trips forge abuse protections
// (e.g. GitHub's secondary rate limits, which watch concurrency, not quota)
Expand Down Expand Up @@ -129,7 +121,7 @@ export async function mapWithConcurrency(items, limit, task) {
export function getFilesPRs(forge, urlInfo, requestHeaders, prs) {
return mapWithConcurrency(prs, MAX_CONCURRENT_FETCHES, async pr => {
const filenames = await getModifiedFilenames(forge, urlInfo, requestHeaders, pr)
return addIfIncluded(filenames, urlInfo.filepath, forge.prNumber(pr))
return filenames.includes(urlInfo.filepath) ? forge.prNumber(pr) : null
})
}

Expand Down
23 changes: 1 addition & 22 deletions tests/background.test.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
import { test } from "node:test"
import assert from "node:assert/strict"

import { addIfIncluded, authHeadersFor, getFilesPRs, fetchAllPages, mapWithConcurrency } from "../background.js"
import { authHeadersFor, getFilesPRs, fetchAllPages, mapWithConcurrency } from "../background.js"
import { github } from "../forges.js"

//
// addIfIncluded
//
test("addIfIncluded returns the key when the item is in the array", () => {
assert.equal(addIfIncluded(["a.js", "b.js"], "a.js", 42), 42)
})

test("addIfIncluded returns null when the item is absent", () => {
assert.equal(addIfIncluded(["a.js", "b.js"], "c.js", 42), null)
})

test("addIfIncluded returns null for an empty array", () => {
assert.equal(addIfIncluded([], "a.js", 42), null)
})

test("addIfIncluded preserves a falsy key when the item is present", () => {
// a PR number of 0 is unrealistic, but the helper must not confuse a
// present-but-falsy key with the absent case
assert.equal(addIfIncluded(["a.js"], "a.js", 0), 0)
})

//
// authHeadersFor
//
Expand Down