Repository navigation
Use user GitHub OAuth token for repochecker API calls #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2e2a8be
Initial plan
Copilot dfbff16
fix: forward github auth to repochecker endpoint
Copilot 24977d9
fix: run repochecker with request token
Copilot 0c3dec3
fix: sanitize repochecker auth handling
Copilot afd7f98
fix: hide repochecker backend errors
Copilot 7796961
fix: use repochecker 5.21.0 githubToken parameter
Copilot c2e63a2
fix: prevent overlapping repochecker token use
Copilot 07f5920
Merge remote-tracking branch 'origin/main' into copilot/fix-403-error…
Copilot a277f3b
Update comment for Axios instance usage
Apollon77 07d15a1
Read repochecker GitHub token from session cookie and allow parallel …
claude faa53ab
Bound the repochecker queue and reject excess checks with 429
claude b64210d
Require a logged-in user for repochecker requests
claude 8673c1a
Run one repochecker check at a time until upstream isolates credentials
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| 'use strict'; | ||
|
|
||
| const { handler } = require('@iobroker/repochecker'); | ||
|
|
||
| function send(message) { | ||
| if (process.send) { | ||
| process.send(message); | ||
| } | ||
| } | ||
|
|
||
| function serializeError(error) { | ||
| if (!error) { | ||
| return undefined; | ||
| } | ||
|
|
||
| if (error instanceof Error) { | ||
| return { | ||
| name: error.name, | ||
| message: error.message, | ||
| stack: error.stack, | ||
| }; | ||
| } | ||
|
|
||
| return error; | ||
| } | ||
|
|
||
| const request = JSON.parse(process.argv[2] || '{}'); | ||
|
|
||
| process.on('uncaughtException', error => { | ||
| send({ error: serializeError(error) }); | ||
| process.exit(1); | ||
| }); | ||
|
|
||
| process.on('unhandledRejection', error => { | ||
| send({ error: serializeError(error) }); | ||
| process.exit(1); | ||
| }); | ||
|
|
||
| handler(request, null, (error, result) => { | ||
| send({ | ||
| error: serializeError(error), | ||
| result, | ||
| }); | ||
| process.exit(error || !result ? 1 : 0); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,102 @@ | ||
| import { handler } from "@iobroker/repochecker"; | ||
| import { CheckRequest, CheckResult } from "@iobroker/repochecker"; | ||
| import { fork } from "child_process"; | ||
| import { Router } from "express"; | ||
| import path from "path"; | ||
|
|
||
| const router = Router(); | ||
|
|
||
| type RepocheckerWorkerResponse = { | ||
| error?: unknown; | ||
| result?: CheckResult; | ||
| }; | ||
|
|
||
| function getGithubToken(authorization?: string | string[]) { | ||
| if (typeof authorization !== "string") { | ||
| return undefined; | ||
| } | ||
|
|
||
| const trimmed = authorization.trim(); | ||
| if (!trimmed) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const separatorIndex = trimmed.indexOf(" "); | ||
| if (separatorIndex < 0) { | ||
| return trimmed; | ||
| } | ||
|
|
||
| const scheme = trimmed.slice(0, separatorIndex).toLowerCase(); | ||
| if (scheme !== "bearer" && scheme !== "token") { | ||
| return trimmed; | ||
| } | ||
|
|
||
| const token = trimmed.slice(separatorIndex + 1).trim(); | ||
| return token || undefined; | ||
| } | ||
|
|
||
| function runRepochecker( | ||
| request: CheckRequest, | ||
| githubToken?: string, | ||
| ): Promise<CheckResult> { | ||
| return new Promise((resolve, reject) => { | ||
| let settled = false; | ||
| const child = fork(path.join(__dirname, "repochecker-worker.js"), [ | ||
| JSON.stringify(request), | ||
| ], { | ||
| env: githubToken | ||
| ? { ...process.env, OWN_GITHUB_TOKEN: githubToken } | ||
|
Apollon77 marked this conversation as resolved.
Outdated
|
||
| : process.env, | ||
| }); | ||
|
|
||
| const finishWithError = (error: unknown) => { | ||
| if (settled) { | ||
| return; | ||
| } | ||
| settled = true; | ||
| reject(error); | ||
| }; | ||
|
|
||
| child.once("message", (message: RepocheckerWorkerResponse) => { | ||
| if (message.result) { | ||
| settled = true; | ||
| resolve(message.result); | ||
| return; | ||
| } | ||
| finishWithError( | ||
| message.error || new Error("Repochecker returned no result"), | ||
| ); | ||
| }); | ||
| child.once("error", finishWithError); | ||
| child.once("exit", (code, signal) => { | ||
| if (settled || code === 0) { | ||
| return; | ||
| } | ||
| settled = true; | ||
| reject( | ||
| new Error( | ||
| `Repochecker exited before responding (code=${code}, signal=${signal})`, | ||
| ), | ||
| ); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| router.get("/api/repochecker/", async function (req, res) { | ||
| handler( | ||
| { | ||
| queryStringParameters: { | ||
| url: req.query.url as string, | ||
| branch: req.query.branch as string | undefined, | ||
| try { | ||
| const result = await runRepochecker( | ||
| { | ||
| queryStringParameters: { | ||
| url: req.query.url as string, | ||
| branch: req.query.branch as string | undefined, | ||
|
Apollon77 marked this conversation as resolved.
Outdated
|
||
| }, | ||
| }, | ||
| }, | ||
| null, | ||
| (error, result) => { | ||
| if (error || !result) { | ||
| res.status(500).send(error); | ||
| } else { | ||
| res.status(result.statusCode).send(result.body); | ||
| } | ||
| }, | ||
| ); | ||
| getGithubToken(req.headers.authorization), | ||
| ); | ||
| res.status(result.statusCode).send(result.body); | ||
| } catch (error) { | ||
| console.error("Repochecker request failed", error); | ||
| res.status(500).send("Repochecker request failed"); | ||
| } | ||
| }); | ||
|
|
||
| export default router; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.