Repository navigation
feat(api): create an application from a GitHub repository (part of #213) - #526
Merged
Merged
Conversation
Part of #213 (ADR 0031, SPEC 4). An application can take its configuration from the shipkeep.yml of a repository that the organization's GitHub App reaches: POST …/applications/github reads it at the branch head with a token scoped to that repository (contents: read), revoked once read, validates it, and stores the installation, the repository's identifier and name, the branch and the path. Until builds land it names a built image. Its configuration is the repository's, so the API does not replace it, and an environment holding one is not cloned yet. Releases get a commit_sha column for the push deployments that come next. Signed-off-by: samuel mbabhazi <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 30 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
… refuses is unreachable GitHub answers 422 when an installation token is asked for a repository the installation does not include: that is now github_repository_unavailable instead of GitHub being unavailable, which a push would retry for ever. A Git application stores the commit its configuration was read from, so a release of it records the same. Signed-off-by: samuel mbabhazi <[email protected]>
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 27, 2026
… (part of #213) (#528) ## What changed Part of #213: the web side of Git applications. **UI change: the maintainer validates it before merge.** Until #526 merges, this pull request also shows #526's commits; its own commit is `a02207b`. - **Integrations** (`/orgs/:id/integrations`) replaces the Preview screen with a live page: - **Without an App:** an owner chooses their GitHub account or a GitHub organization and creates the App. The control plane returns GitHub's manifest URL and the manifest. The page posts them to GitHub as a form, only when the URL's origin is `https://github.com`. Others read that an owner creates it. - **With the App:** its name and owner account, with "Install on repositories" and "Open on GitHub". The repositories its installations reach show with their default branch and whether they are private. Unreachable installations and truncation are said. - GitLab, Gitea and Bitbucket are said to be planned. No sample data. - **`integrations/github`:** where GitHub sends the owner back. It gives `code` and `state` to the control plane once, then leaves for the integrations without them in the URL. - An expired or used link says so. - An App GitHub created that could not be kept links to its page, for deletion. Only `https://github.com/apps/<slug>` pages are linked. - **The environment's Resources tab:** a "From a GitHub repository" form: repository (each proposes its default branch), branch, and the path of `shipkeep.yml`. Each refusal of the API (#526) gets its own words. The list shows a Git application as `owner/repo · branch`. - **New resource:** the GitHub repository card is live and opens that form. - **A Git application's page:** its `shipkeep.yml` shows read-only, with which repository, branch and path it comes from, and that a push deploys it unless the environment is protected. - **CSP:** `form-action 'self' https://github.com`, for the manifest form. - `requestProblem` keeps an `appUrl` detail when it is a GitHub App page. - French translations for every new text. ## Why #213's application side needs a way to connect GitHub and choose a repository without calling the API by hand. ## How it was tested - **Unit tests** (14 new): - the manifest posted as a form to GitHub only, with the organization name trimmed; - non-owners see no form; - the App, its links and its repositories; GitHub unreachable, then "Try again"; - the return page: connected, then redirected; invalid; not kept, with the App link; unreachable; - the form: the body sent, default branches, the refusal texts, no App, no repository. - **Browser test** `github.browser.spec.ts`, Chromium against the production build, real API and PostgreSQL, with a fake GitHub on both sides: - an owner creates the App; Playwright stands in for github.com and checks the posted manifest (private, named for the organization), then redirects back with a code; - a signed `installation` webhook arrives, and the repository lists; - an application is created from it, and the list shows `acme-corp/billing · main`; - no console error and no CSP report. - Mutation check: with `form-action 'self'`, the test fails, because the form never reaches GitHub. - `web` lint, typecheck and tests (63 files) and `api` lint, typecheck and unit tests (941) pass. - Screenshots, desktop and 390 px, English and French: on the review page linked in the conversation. ## Security considerations - The CSP gains one form target, `https://github.com`, and the page refuses to post anywhere else. - The manifest holds no secret. GitHub returns the App's secrets to the control plane, never to the browser. - The return page sends `code` and `state` once, over the session, and removes them from the address. - Links in refusals are limited to GitHub App pages. --------- Signed-off-by: samuel mbabhazi <[email protected]>
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 27, 2026
## What changed A verified GitHub push deploys its commit (#213, ADR 0031). This pull request is stacked on #526: its base is that branch until #526 merges. - **Webhook (`git` module):** - A `push` to a branch is recorded with a job of the new `github-push` pg-boss queue, in one transaction, and answered 204 at once. - A tag, a deleted branch or a malformed field queues nothing (`pushOf`). - The job carries identifiers, the branch, the commit and the pusher's login only. - **Worker (`deployments` module):** `PushWorker` works the queue, started by `main.ts`. It checks each payload again (`pushJob`) and hands it to `PushDeployments`. For each Git application that follows that branch of that repository through that installation (at most 20): 1. GitHub is asked for the branch head. Only while the pushed commit is that head does anything happen, so a replayed or overtaken push deploys nothing. 2. The `shipkeep.yml` there becomes the application's configuration, as the system (`ApplicationCommands.applyRepositoryConfig`). It is audited as `application.updated` with the commit. The application's name cannot change, and domains are claimed as for any configuration. 3. `DeploymentCommands.deployPush` queues a deployment with the trigger `webhook` and no actor, and its release keeps `commit_sha`. `release.created` and `deployment.queued` are the system's, with `commitSha` and `githubPusher`. - In a protected environment (the default, SPEC 7) or during maintenance, nothing deploys: `deployment.push_held`. - When the newest release is already this commit's, nothing deploys twice. - **Failures:** - A configuration that cannot deploy is audited as `deployment.push_refused` with the error's stable code. - While a deployment is under way, or GitHub cannot be reached, the push is tried again a minute later for the applications left, 30 times at most. - A database error fails the job, and pg-boss retries it. - **Refactor:** `claimDomains` and the application audit take an `Actor`, so the system can use them. - **Docs:** SPEC (GitHub App section) and a note in ADR 0031: the delivery is recorded with the job rather than with the deployment, so that the webhook answers within GitHub's ten seconds. ## Why Acceptance of #213: "A verified push webhook enqueues a deploy request job with the commit and branch; a forged or replayed webhook is rejected." Forged deliveries were already refused (#466). This adds the job, the branch head check against replays, and the deployment. ## How it was tested - **`push-deployments.integration.spec.ts`** (PostgreSQL, the real webhook route, a fake GitHub): - a signed push queues exactly one job with the expected payload; GitHub's redelivery and the same body under another identifier queue nothing; a tag and a deleted branch queue nothing; - a protected environment: the configuration follows, `push_held`, no deployment; - an unprotected environment: an overtaken push deploys nothing; the head deploys once with trigger `webhook`, a null actor and the commit; handled again it does not deploy twice; while that deployment runs, the next push is answered "try again", then deploys; - invalid YAML and a renamed application are refused with their codes; GitHub unavailable means "try again". - **Mutation check:** without the branch head check, two of these cases fail. - **Unit tests:** `pushOf` (tags, deletions, zero commit, upper case, bad ids, branch tricks) and `pushJob` (every field of the payload, retries). - `api` lint, typecheck and unit tests pass: 945 tests. The HTTP pipeline test fakes the new queue. - Full integration suite: 455 pass, plus the same environment-only failures as on #526 (container runtime; PostgreSQL 18's 23001). ## Security considerations - Replays deploy nothing: the delivery identifier and body are recorded as before, and only the current branch head deploys. - A push deploys only Git applications of the organization whose installation, repository identifier and branch all match. - Protected environments are never deployed by a push. Audit events carry codes and identifiers, never configuration or GitHub text. - No new external service, and no change to the agent or its action list. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * GitHub push events now trigger deployments when the pushed commit is the current branch head and the application configuration is valid. * Configuration updates from pushes are applied automatically. Pushes to protected environments or during maintenance update configuration without deploying. * Busy deployments and temporary GitHub or processing failures are retried; pushes that cannot be deployed are recorded for review. * **Documentation** * Updated GitHub integration guidance to describe push-triggered deployments, holds, and retries. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: samuel mbabhazi <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What changed
Part of #213 (ADR 0031, SPEC 4): an application can take its configuration from the
shipkeep.ymlof a GitHub repository.POST …/environments/{environmentId}/applications/github(deploy.run) with{installationId, repositoryId, branch, configPath};configPathdefaults toshipkeep.yml..ymlor.yaml, and have no empty,.or..segment.contents: read,metadata: read), finds the repository by GitHub's identifier, reads the branch's head and the file at that commit, then revokes the token.github_app_missing,github_installation_unavailable,github_repository_unavailable,github_branch_not_found,github_config_not_found,invalid_application_config(with the commit),unsupported_build_type.20261127100000_git_applications):applicationsgetsinstallation_id,repository_id,repository,branchandconfig_path. A CHECK sets all of them forsource = 'git', and none otherwise.(organization_id, repository_id, branch)serves the push lookup that comes next.releasesgetscommit_sha, and the write-once trigger covers it.POST …/configanswers 409application_config_in_repository.environment_has_git_applications). This is added to SPEC's open questions.application.createdcarries the repository, the branch, the path and the commit read.repository(null for image applications).gitmodule:GithubSourcesimplements theRepositorySourceport that theappsmodule declares.GithubApigainsrepository()(GET /repositories/{id}) andfile()(raw contents at a commit, at most 256 KiB).Why
Step 3 of the v0.1.0 order (#413): deployment from Git. A push can only deploy an application that knows its repository and branch. The next pull request makes a verified push queue a deployment of that commit, with the branch head check of ADR 0031.
How it was tested
git-applications-http.integration.spec.ts, real PostgreSQL and a fake GitHub:repositoryOf,validCommitandvalidConfigPath(traversal, absolute, backslash, newline, query, length), and the client's raw read (URL encoding,accept, 404, oversize, an answer about another repository, no request for a bad name or ref).apilint, typecheck and unit tests (941), andwebandapi-clientlint, typecheck and tests, all pass. The route-role matrix and the audit coverage map are updated.Security considerations
finally, and never stored, logged or returned.