Skip to content

Commit 37aa8a6

Browse files
authored
🐛 Send an Issue to the API base the host configured (#608) (#613)
`useGitHubIssues()` built the public default source whenever no access was injected, so a configured GitHub Enterprise or loopback endpoint reached the options object and then went nowhere. `GitHubIssuesOptions` now names the endpoint, and the source is chosen the way the pull-request middleware already chooses one: an injected transport, then a configured endpoint, then the platform's own GitHub. The regression installs the middleware with an endpoint and no access at all, and reads one issue from the loopback tracker under the credential this process is standing in. The tracker's payload names its own origin as the issue's home, which the adapter accepts only when that is the endpoint its source was built against — so a normalized answer is itself the proof that the configured source was the one used. Co-authored-by: Taras Mankovski <[email protected]>
1 parent 0ccd3e1 commit 37aa8a6

2 files changed

Lines changed: 68 additions & 1 deletion

File tree

‎packages/workflow/src/deno/issue/github.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ export interface GitHubIssuesOptions {
306306
* document can write widens it.
307307
*/
308308
readonly ceiling: readonly string[];
309+
/** The API base every request is built against, when not the default. */
310+
readonly endpoint?: string;
311+
/** An injected transport, which outranks any configured endpoint. */
309312
readonly access?: GitHubSource;
310313
}
311314

@@ -321,7 +324,13 @@ export function* useGitHubIssues(options: GitHubIssuesOptions): Operation<void>
321324
// A source rather than an access: it is credential-free, so holding one for
322325
// the middleware's whole lifetime retains nothing. A session — which does have
323326
// an identity — is opened per request below, after that request's ceiling.
324-
const source = options.access ?? denoGitHubSource();
327+
//
328+
// Precedence: an injected transport, then a configured endpoint, then the
329+
// platform's own GitHub. A suite that supplies its own access is not asking
330+
// for a different endpoint as well.
331+
const source =
332+
options.access ??
333+
(options.endpoint === undefined ? denoGitHubSource() : denoGitHubSource(options.endpoint));
325334

326335
yield* IssueApi.around(
327336
{

‎packages/workflow/tests/ambient-authentication.test.ts‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import { remoteBranch, remoteRefs, useBareRemote } from "./support/git-remotes.t
6161
import { useGitHttpRemote } from "./support/git-http.ts";
6262
import type { GitHttpRemote } from "./support/git-http.ts";
6363
import { useHomeWithoutAuthentication, useInvokingHome } from "./support/credential-home.ts";
64+
import { credential, useIssueTrackerServer } from "./support/issue-tracker-server.ts";
6465
import {
6566
fixture as pullRequestFixture,
6667
published as publishedPullRequest,
@@ -1336,6 +1337,63 @@ describe("workflow GitHub source sessions", () => {
13361337
expect(refusal).toBeDefined();
13371338
expect(opened).toEqual([]);
13381339
});
1340+
1341+
it("sends an Issue read to the API base the host configured, as this process", function* () {
1342+
const server = yield* useIssueTrackerServer({
1343+
issues: [
1344+
{
1345+
number: 7,
1346+
state: "open",
1347+
title: "an ordinary issue",
1348+
body: "what it says",
1349+
labels: ["triage"],
1350+
assignee: null,
1351+
},
1352+
],
1353+
});
1354+
1355+
// Ambient, and only ambient: the installation below names no access, no
1356+
// transport and no environment, so the only credential it can reach is the
1357+
// one this process is standing in. Restored on every exit, so the identity
1358+
// this case arranged is not inherited by whatever runs next.
1359+
const before = process.env.GH_TOKEN;
1360+
yield* ensure(() => {
1361+
if (before === undefined) {
1362+
delete process.env.GH_TOKEN;
1363+
} else {
1364+
process.env.GH_TOKEN = before;
1365+
}
1366+
});
1367+
process.env.GH_TOKEN = credential();
1368+
1369+
const details = yield* scoped(function* () {
1370+
yield* useGitHubIssues({
1371+
ceiling: ["https://github.com/octo/project"],
1372+
endpoint: server.url,
1373+
});
1374+
return yield* IssueApi.operations.read("https://github.com/octo/project/issues/7", {
1375+
provider: GITHUB,
1376+
});
1377+
});
1378+
1379+
// A normalized answer at all is already the proof: the payload names its own
1380+
// loopback origin as the issue's home, and the adapter accepts that only
1381+
// when it is the endpoint the source was built against. The default source
1382+
// this middleware used to construct would have asked public GitHub.
1383+
expect(details).toEqual({
1384+
url: "https://github.com/octo/project/issues/7",
1385+
title: "an ordinary issue",
1386+
description: "what it says",
1387+
tags: ["triage"],
1388+
assignee: null,
1389+
});
1390+
expect(server.requests.map((request) => `${request.method} ${request.path}`)).toEqual([
1391+
"GET /repos/octo/project/issues/7",
1392+
]);
1393+
// Reduced to a verdict before it is asserted, so a failure prints whether
1394+
// the request carried this process's credential rather than printing it.
1395+
expect(server.requests[0]?.authorization === `Bearer ${credential()}`).toBe(true);
1396+
});
13391397
});
13401398

13411399
describe("workflow GitHub ambient credentials", () => {

0 commit comments

Comments
 (0)