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
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { describe, expect, it } from "vitest"

import { repositoryResponseSchema, workspaceResponseSchema } from "@application/hub/contracts"

import { repositoryShowData } from "."

describe("repositoryShowData()", () => {
it("uses a GitHub snapshot without joining an unrelated user by login in real data", () => {
const repository = { id: "1", nameWithOwner: "example/repository", defaultBranch: "main" }
const workspace = workspaceResponseSchema.parse({
viewer: { id: "viewer", login: "viewer", name: null, avatarUrl: null },
repositories: [repository],
})
const data = repositoryResponseSchema.parse({
repository,
prototypes: [
{
id: "2",
repositoryId: repository.id,
name: "GitHub snapshot",
branchName: "proto/github",
description: null,
authorId: null,
authorLogin: "sam",
authorProvider: "github",
canEdit: false,
builds: [],
},
{
id: "3",
repositoryId: repository.id,
name: "Explicit owner",
branchName: "proto/owner",
description: null,
authorId: "entra-user",
authorLogin: "sam",
authorProvider: "entra",
canEdit: false,
builds: [],
},
],
pagination: { page: 1, pageSize: 20, totalCount: 2, pageCount: 1 },
authors: [
{
id: "entra-user",
login: "sam",
name: "Entra user",
provider: "entra",
avatarUrl: "https://example.test/entra.png",
},
],
})

const { prototypes } = repositoryShowData(workspace, data, new URLSearchParams(), {
real: true,
})

expect.soft(prototypes.find(({ id }) => id === "2")?.author).toEqual({
avatarUrl: null,
label: "By @sam",
ownerLabel: "@sam",
url: "https://github.com/sam",
})
expect(prototypes.find(({ id }) => id === "3")?.author).toEqual({
avatarUrl: "https://example.test/entra.png",
label: "By Entra user",
ownerLabel: "Entra user",
url: null,
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ export function repositoryShowData(
const builds = [...prototype.builds].sort((first, second) => second.number - first.number)
const latestBuild = prototype.latestBuild === undefined ? builds[0] : prototype.latestBuild
const reviewBuild = builds.find((build) => build.previewUrl && build.desktopScreenshotUrl)
const prototypeAuthor = data.authors.find((item) =>
prototype.authorId ? item.id === prototype.authorId : item.login === prototype.authorLogin,
)
const prototypeAuthor = prototype.authorId
? data.authors.find((item) => item.id === prototype.authorId)
: options.real
? undefined
: data.authors.find((item) => item.login === prototype.authorLogin)
const authorName =
prototypeAuthor?.provider && prototypeAuthor.provider !== "github"
? (prototypeAuthor.name ?? prototypeAuthor.login)
Expand Down
2 changes: 2 additions & 0 deletions hub/docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Runtime and setup require `DATABASE_URL`; setup accepts no additional references

Versioned references make rotation explicit. An unversioned runtime/setup URL is resolved once at startup; there is no background refresh or automatic revision restart. Use the installation's serialized release procedure to load a rotated value. Source development, local image runs with directly supplied protected environment values, and the existing setup/provisioning scripts retain their original entrypoints and behavior.

The Azure entrypoint also supports the scoped [GitHub author repair and webhook checks](github-actions-builds.md#commit-authors). These maintenance targets load the same runtime secret references into their own process before importing the command.

## Setup before release

Run `npm run setup` from `hub/`, or invoke `node dist/server/scripts/setup/index.js` inside the image. Normal API and worker startup never runs setup.
Expand Down
56 changes: 50 additions & 6 deletions hub/docs/github-actions-builds.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions hub/docs/share-links.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ Hosted public sharing is off by default. It requires configured Build storage an
The prototype's **Share links** action requires a GitHub session and one of these permissions:

- GitHub currently reports repository administrator permission.
- At least one successful Build for this prototype records the signed-in GitHub identity as its commit author, and GitHub currently reports at least read access.
- The signed-in user is the prototype's stored owner, at least one successful Build records that GitHub identity as its commit author, and GitHub currently reports at least read access.

Hub matches the recorded provider, issuer, and immutable GitHub user ID, not the login. Repository write access, a Hub administrator role, or an Entra session does not substitute for either rule. The API rechecks permission for each list, create, and revoke request. The browser lists only active hosted links.
Hub matches the recorded provider, issuer, and immutable GitHub user ID, not the login. Commit attribution alone does not assign ownership or authorize sharing. Ownerless imported prototypes therefore require repository administrator permission. Existing owners are retained; the schema does not independently record or re-attest the source of historical owner assignments. Repository write access, a Hub administrator role, or an Entra session does not substitute for either rule. The API rechecks permission for each list, create, and revoke request. The browser lists only active hosted links.

An explicit `none` result for the expected GitHub identity permanently revokes only that creator's links in that repository. Confirmed GitHub App disconnection revokes all hosted links for the affected repositories. Unavailable or ambiguous evidence denies management without revoking links. Public visits do not call GitHub, and some webhook events narrow signed-in access without proving a creator lost all access. Sharing does not promise immediate detection of creator access loss.

Expand Down
4 changes: 4 additions & 0 deletions hub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"local:builds": "node server/scripts/run-local-builds/index.ts",
"local:builds:enqueue": "node server/scripts/enqueue-local-builds/index.ts",
"local:worker": "node server/scripts/start-local-worker/index.ts",
"github:repair-author": "node server/scripts/repair-github-build-author/index.ts",
"github:check-webhooks": "node server/scripts/check-github-webhooks/index.ts",
Comment thread
weastler marked this conversation as resolved.
Resolved
"db:studio": "prisma studio",
"jobs:setup": "node server/scripts/setup-jobs/index.ts",
"setup": "node server/scripts/setup/index.ts",
Expand All @@ -30,6 +32,8 @@
"start:worker:scheduled": "node dist/server/workers/index.js scheduled",
"start:jobs:setup": "node dist/server/scripts/setup-jobs/index.js",
"start:setup": "node dist/server/scripts/setup/index.js",
"start:github:repair-author": "node dist/server/scripts/repair-github-build-author/index.js",
"start:github:check-webhooks": "node dist/server/scripts/check-github-webhooks/index.js",
"controls:build": "node script/build-controls-bridge.mjs",
"controls:assets:check": "node script/build-controls-bridge.mjs --check",
"controls:test": "node --test script/tests/build-controls.test.mjs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { GitHubWorkflowRun } from "../../../integrations/github/create-gith
import { listGitHubBuildRuns } from "../../../repositories/github-builds/list-github-build-runs/index.ts"
import { listGitHubBranchIdentities } from "../../../repositories/prototypes/list-github-branch-identities/index.ts"
import { listConnectedGitHubRepositories } from "../../../repositories/repository-access/list-connected-github-repositories/index.ts"
import { githubDeselectedWorkflowFailure } from "../../../utils/github-deselected-workflow-failure/index.ts"
import type { GitHubWorkflowRunJob } from "../get-github-workflow-run-job-definition/index.ts"
import { refreshGitHubBranchHeads } from "../refresh-github-branch-heads/index.ts"

Expand All @@ -22,8 +23,9 @@ export interface DiscoverGitHubWorkflowRunsDependencies {

/**
* A run is settled once its Build can no longer change: a successful Build whose
* completed-run pass finished, a superseded Build, or a failure that this attempt
* cannot reopen. Everything else still needs an import pass.
* completed-run pass finished, a failed Build without unresolved attribution, a
* deselected or superseded Build, or an older attempt that cannot reopen its Build.
* Everything else still needs an import pass.
*/
function settled(run: GitHubWorkflowRun, saved: SavedRun[]) {
return saved.some((build) => {
Expand All @@ -37,10 +39,17 @@ function settled(run: GitHubWorkflowRun, saved: SavedRun[]) {
}
return build.runId !== null && build.runId > run.id
}
if (
build.state === "failed" &&
(build.authorProvider !== null || build.failureSummary === githubDeselectedWorkflowFailure)
) {
return build.runAttempt >= run.runAttempt
}
return (
build.runAttempt >= run.runAttempt &&
((build.state === "successful" && build.workflowCompletedAt !== null) ||
build.state === "failed")
build.runAttempt > run.runAttempt ||
(build.runAttempt === run.runAttempt &&
(build.state === "successful" || build.state === "failed") &&
build.workflowCompletedAt !== null)
)
})
}
Expand Down
6 changes: 6 additions & 0 deletions hub/server/domains/github-builds/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class GitHubBuildAuthorTargetError extends Error {
constructor() {
super("No GitHub Build matches that repository and Build ID.")
this.name = "GitHubBuildAuthorTargetError"
}
}
Loading
Loading