Skip to content

feat(api): create an application from a GitHub repository (part of #213) - #526

Merged
samuelmbabhazi merged 4 commits into
mainfrom
feat/213-git-applications
Nov 27, 2026
Merged

samuelmbabhazi merged 4 commits into
mainfrom
feat/213-git-applications

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

What changed

Part of #213 (ADR 0031, SPEC 4): an application can take its configuration from the shipkeep.yml of a GitHub repository.

  • POST …/environments/{environmentId}/applications/github (deploy.run) with {installationId, repositoryId, branch, configPath}; configPath defaults to shipkeep.yml.
    • The branch and the path are checked before GitHub is asked. The path must be relative, end in .yml or .yaml, and have no empty, . or .. segment.
    • The installation must be one of the App's that GitHub has not suspended.
    • The control plane mints a token for that one repository (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.
    • The file is parsed and validated like any configuration. Until builds land (M3.3, [M3.3] Builds and registry #215), it names a built image.
    • Refusals have their own codes: 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.
  • Data (migration 20261127100000_git_applications):
    • applications gets installation_id, repository_id, repository, branch and config_path. A CHECK sets all of them for source = 'git', and none otherwise.
    • A partial index on (organization_id, repository_id, branch) serves the push lookup that comes next.
    • releases gets commit_sha, and the write-once trigger covers it.
  • Behaviour of a Git application:
    • Its configuration is the repository's: POST …/config answers 409 application_config_in_repository.
    • An environment holding one cannot be cloned yet (409 environment_has_git_applications). This is added to SPEC's open questions.
    • application.created carries the repository, the branch, the path and the commit read.
    • Responses carry repository (null for image applications).
  • The git module:
    • GithubSources implements the RepositorySource port that the apps module declares.
    • GithubApi gains repository() (GET /repositories/{id}) and file() (raw contents at a commit, at most 256 KiB).
    • Every URL part is validated before the request is built.

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

  • New integration test git-applications-http.integration.spec.ts, real PostgreSQL and a fake GitHub:
    • every refusal above, the path tricks and suspended installations refused before GitHub is asked, and an outsider getting 404;
    • the token's exact scope, and its revocation after every read, failed ones included;
    • a renamed repository kept under its new name;
    • the domain claimed, the audit metadata, the 409 on a config edit and on a clone;
    • the table CHECKs, by direct inserts.
  • Unit tests: repositoryOf, validCommit and validConfigPath (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).
  • api lint, typecheck and unit tests (941), and web and api-client lint, typecheck and tests, all pass. The route-role matrix and the audit coverage map are updated.
  • The full integration suite on PostgreSQL 18: 451 pass. The failures are local only and known:
    • the VictoriaMetrics and S3 files need a container runtime, which this machine lacks;
    • three tests expect 23503 where PostgreSQL 18 says 23001.

Security considerations

  • No new external service, and no change to the agent.
  • GitHub tokens:
    • minted per read, for one repository, with read-only contents;
    • revoked in finally, and never stored, logged or returned.
  • GitHub's answers:
    • bounded (256 KiB for a file, 2 MiB for JSON) and never followed through redirects;
    • GitHub's text is never repeated.
  • Path, branch and commit are validated twice, at the service and in the client, so a URL never names another resource.
  • Access is checked before GitHub is asked and again in the transaction that creates the application.

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]>
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between cab0fdd and f74bb24.

Files ignored due to path filters: 3

  • apps/api/openapi.json is excluded by !apps/api/openapi.json
  • docs/generated/route-role-matrix.md is excluded by !**/generated/**, !docs/generated/**
  • packages/api-client/src/gen/openapi.ts is excluded by !**/gen/**, !packages/api-client/src/gen/**
Files selected for processing: 23

  • apps/api/prisma/migrations/20261127100000_git_applications/migration.sql
  • apps/api/prisma/schema.prisma
  • apps/api/src/audit-coverage.spec.ts
  • apps/api/src/modules/apps/application/application-commands.ts
  • apps/api/src/modules/apps/application/environment-clone.ts
  • apps/api/src/modules/apps/application/ports.ts
  • apps/api/src/modules/apps/apps.module.ts
  • apps/api/src/modules/apps/domain/application.spec.ts
  • apps/api/src/modules/apps/domain/application.ts
  • apps/api/src/modules/apps/git-applications-http.integration.spec.ts
  • apps/api/src/modules/apps/infrastructure/prisma-application.store.ts
  • apps/api/src/modules/apps/interface/application.controller.ts
  • apps/api/src/modules/apps/interface/application.dto.ts
  • apps/api/src/modules/git/application/github-repositories.ts
  • apps/api/src/modules/git/application/github-sources.ts
  • apps/api/src/modules/git/application/ports.ts
  • apps/api/src/modules/git/domain/github-api.spec.ts
  • apps/api/src/modules/git/domain/github-api.ts
  • apps/api/src/modules/git/git.module.ts
  • apps/api/src/modules/git/github-repositories-http.integration.spec.ts
  • apps/api/src/modules/git/infrastructure/github-api.client.spec.ts
  • apps/api/src/modules/git/infrastructure/github-api.client.ts
  • docs/SPEC.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

… 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
samuelmbabhazi merged commit 15c0840 into main Nov 27, 2026
27 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/213-git-applications branch November 27, 2026 08:50
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant