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
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
"@types/micromatch": "^3.1.0",
"@types/node": "18.19.18",
"@types/node-fetch": "^2.5.12",
"@types/p-limit": "^2.0.0",
"@types/parse-github-url": "^1.0.3",
"@types/prettier": "^1.16.1",
"@types/readline-sync": "^1.4.3",
Expand Down Expand Up @@ -168,7 +167,6 @@
"node-cleanup": "^2.1.2",
"node-fetch": "^2.6.7",
"override-require": "^1.1.1",
"p-limit": "^2.1.0",
"parse-diff": "^0.7.0",
"parse-github-url": "^1.0.2",
"parse-link-header": "^2.0.0",
Expand Down
42 changes: 40 additions & 2 deletions source/platforms/github/GitHubAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { Octokit as GitHubNodeAPI } from "@octokit/rest"
import { debug } from "../../debug"
import * as node_fetch from "node-fetch"
import parse from "parse-link-header"
import pLimit from "p-limit"

import { GitHubPRDSL, GitHubIssueComment, GitHubUser } from "../../dsl/GitHubDSL"

import { dangerIDToString } from "../../runner/templates/githubIssueTemplate"
Expand All @@ -15,6 +13,46 @@ import { CheckOptions } from "./comms/checks/resultsToCheck"

export type APIToken = string

/**
* Inline concurrency limiter — replaces the `p-limit` package.
* Restricts the number of promises running at once to `concurrency`.
*/
function pLimit(concurrency: number) {
const queue: Array<() => void> = []
let active = 0

const next = () => {
if (queue.length > 0 && active < concurrency) {
active++
queue.shift()!()
}
}

return <T>(fn: () => Promise<T>): Promise<T> =>
new Promise<T>((resolve, reject) => {
const run = () => {
Promise.resolve(fn()).then(
(val) => {
resolve(val)
active--
next()
},
(err) => {
reject(err)
active--
next()
}
)
}
if (active < concurrency) {
active++
run()
} else {
queue.push(run)
}
})
}

const limit = pLimit(25)

// Structure of files returned by the 'List pull request files' API
Expand Down
21 changes: 1 addition & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1918,13 +1918,6 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.18.126.tgz#27875faa2926c0f475b39a8bb1e546c0176f8d4b"
integrity sha512-OTcgaiwfGFBKacvfwuHzzn1KLxH/er8mluiy8/uM3sGXHaRe73RrSIj01jow9t4kJEW633Ov+cOexXeiApTyAw==

"@types/p-limit@^2.0.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@types/p-limit/-/p-limit-2.2.0.tgz#94a608e9b258a6c6156a13d1a14fd720dba70b97"
integrity sha512-fGFbybl1r0oE9mqgfc2EHHUin9ZL5rbQIexWI6jYRU1ADVn4I3LHzT+g/kpPpZsfp8PB94CQ655pfAjNF8LP6A==
dependencies:
p-limit "*"

"@types/parse-github-url@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@types/parse-github-url/-/parse-github-url-1.0.3.tgz#a097f26ae1993f1963d4031126dc7965707804aa"
Expand Down Expand Up @@ -5645,14 +5638,7 @@ p-is-promise@^3.0.0:
resolved "https://registry.yarnpkg.com/p-is-promise/-/p-is-promise-3.0.0.tgz#58e78c7dfe2e163cf2a04ff869e7c1dba64a5971"
integrity sha512-Wo8VsW4IRQSKVXsJCn7TomUaVtyfjVDn3nUP7kE967BQk0CwFpdbZs0X0uk5sW9mkBa9eNM7hCMaG93WUAwxYQ==

p-limit@*:
version "6.2.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-6.2.0.tgz#c254d22ba6aeef441a3564c5e6c2f2da59268a0f"
integrity sha512-kuUqqHNUqoIWp/c467RI4X6mmyuojY5jGutNU0wVTmEOOfcuwLqyMVoAi9MKi2Ak+5i9+nhmrK4ufZE8069kHA==
dependencies:
yocto-queue "^1.1.1"

p-limit@^2.0.0, p-limit@^2.1.0, p-limit@^2.2.0:
p-limit@^2.0.0, p-limit@^2.2.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.3.0.tgz#3dd33c647a214fdfffd835933eb086da0dc21db1"
integrity sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==
Expand Down Expand Up @@ -7593,11 +7579,6 @@ yocto-queue@^0.1.0:
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==

yocto-queue@^1.1.1:
version "1.2.0"
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-1.2.0.tgz#4a29a93e7591328fa31768701e6ea66962401f79"
integrity sha512-KHBC7z61OJeaMGnF3wqNZj+GGNXOyypZviiKpQeiHirG5Ib1ImwcLBH70rbMSkKfSmUNBsdf2PwaEJtKvgmkNw==

yoctocolors-cjs@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/yoctocolors-cjs/-/yoctocolors-cjs-2.1.2.tgz#f4b905a840a37506813a7acaa28febe97767a242"
Expand Down