> ## Documentation Index
> Fetch the complete documentation index at: https://docs.patch.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect a GitHub repo to a project

> Its home becomes GitHub: Patch records it by GitHub's id and copies none of its files. It goes to a new project of `owner`'s (an org you're in; `slug` and `name` from the repo unless you say), or to `project` (`owner/slug`), one of your orgs' with no repo yet (409 `has_repo`). You need admin or maintain on it on GitHub (403 `github_not_admin`), and the app installed on its account (403 `github_not_installed`, with `install_url`) and reaching it (403 `github_repo_not_added`, with `settings_url`). One project per repo (409 `already_connected`, saying where to whoever can see it). The project takes the repo's licence for its code and art, new or existing: GitHub's SPDX id for it, `NOASSERTION` for one GitHub can't name, or `LicenseRef-Proprietary` (all rights reserved) with none. A public repo with a licence starts Open, and any other Private; an existing Open project stays Open only if the repo can be, and otherwise goes Closed source if people play a release of it, or Private. A chat's key leaves it as a chat's first push would: a new project starts Private, and an existing Open one stays Open only where the person chose Open and the repo can be, going Closed source otherwise if people play a release of it, or Private. Only a public repo can be Open (422 `needs_public`), only one with a licence of its own until the Patch licence is ready (422 `needs_license`), and only the person can make it Open, not a chat's key (403 `open_needs_person`, with `page`, where they can: the project's page, or a new project's once it's connected). Its first commits are recorded as best GitHub says. A public repo's README and top-level names are read for its page once it's connected, or by the hourly job when GitHub doesn't give them then; a private repo's never are. Needs the `publish` scope. Send an Idempotency-Key header to make retries safe.



## OpenAPI

````yaml /api-reference/openapi.json post /github/connect
openapi: 3.1.0
info:
  title: Patch API
  version: 1.0.0
  description: >-
    The public API behind patch.gg, the desktop app and pch. Changes within v1
    are additive only. Errors are { error: { code, message, details } }; branch
    on code.
servers:
  - url: https://patch.gg/api/v1
security: []
paths:
  /github/connect:
    post:
      tags:
        - GitHub
      summary: Connect a GitHub repo to a project
      description: >-
        Its home becomes GitHub: Patch records it by GitHub's id and copies none
        of its files. It goes to a new project of `owner`'s (an org you're in;
        `slug` and `name` from the repo unless you say), or to `project`
        (`owner/slug`), one of your orgs' with no repo yet (409 `has_repo`). You
        need admin or maintain on it on GitHub (403 `github_not_admin`), and the
        app installed on its account (403 `github_not_installed`, with
        `install_url`) and reaching it (403 `github_repo_not_added`, with
        `settings_url`). One project per repo (409 `already_connected`, saying
        where to whoever can see it). The project takes the repo's licence for
        its code and art, new or existing: GitHub's SPDX id for it,
        `NOASSERTION` for one GitHub can't name, or `LicenseRef-Proprietary`
        (all rights reserved) with none. A public repo with a licence starts
        Open, and any other Private; an existing Open project stays Open only if
        the repo can be, and otherwise goes Closed source if people play a
        release of it, or Private. A chat's key leaves it as a chat's first push
        would: a new project starts Private, and an existing Open one stays Open
        only where the person chose Open and the repo can be, going Closed
        source otherwise if people play a release of it, or Private. Only a
        public repo can be Open (422 `needs_public`), only one with a licence of
        its own until the Patch licence is ready (422 `needs_license`), and only
        the person can make it Open, not a chat's key (403 `open_needs_person`,
        with `page`, where they can: the project's page, or a new project's once
        it's connected). Its first commits are recorded as best GitHub says. A
        public repo's README and top-level names are read for its page once it's
        connected, or by the hourly job when GitHub doesn't give them then; a
        private repo's never are. Needs the `publish` scope. Send an
        Idempotency-Key header to make retries safe.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                repo_id:
                  type: integer
                  exclusiveMinimum: 0
                  description: GitHub's id
                owner:
                  type: string
                  minLength: 1
                  maxLength: 100
                  description: The org a new project goes to; needed unless `project` says
                slug:
                  type: string
                  minLength: 1
                  maxLength: 64
                name:
                  type: string
                  minLength: 1
                  maxLength: 100
                visibility:
                  type: string
                  enum:
                    - open
                    - closed_source
                    - private
                  description: >-
                    Who can reach the project's repo. open: anyone can find it,
                    read it and fork it. closed_source: anyone can find and play
                    what it releases; only its org reads the source. private:
                    only its org can find it, and anyone else gets a 404. It
                    isn't locked: the game host serves a published browser game
                    to anyone who has its address.
                project:
                  type: string
                  pattern: ^[^/\s]+\/[^/\s]+$
                  description: An existing project with no repo, as owner/slug
              required:
                - repo_id
      responses:
        '201':
          description: Connected
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GithubConnected'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Not signed in
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Not allowed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: Connected already, the slug's taken, or the project has a repo
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '422':
          description: >-
            Open needs a public repo with a licence of its own, or the owner or
            slug won't do
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '502':
          description: GitHub didn't answer
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - bearer: []
components:
  schemas:
    GithubConnected:
      type: object
      properties:
        project:
          type: object
          properties:
            owner:
              type: string
            slug:
              type: string
          required:
            - owner
            - slug
        github:
          $ref: '#/components/schemas/GithubRepo'
      required:
        - project
        - github
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              example: version_exists
            message:
              type: string
            details: {}
          required:
            - code
            - message
      required:
        - error
    GithubRepo:
      type: object
      properties:
        repo_id:
          type: integer
          description: GitHub's id for it, which renames keep
        full_name:
          type: string
          example: sam/sky-mod
        html_url:
          type: string
          format: uri
          example: https://github.com/sam/sky-mod
        default_branch:
          type: string
          example: main
        private:
          type: boolean
          description: Whether it's private on GitHub
        head_commit:
          type:
            - string
            - 'null'
          description: The default branch's latest commit, as of GitHub's last push event
        pushed_at:
          type:
            - string
            - 'null'
          format: date-time
        state:
          type: string
          enum:
            - connected
            - disconnected
            - gone
            - suspended
            - no_access
          description: >-
            connected. disconnected: someone disconnected it on Patch, or it
            moved to an account without Patch's GitHub App. gone: deleted from
            GitHub. suspended: the app is suspended on its account. no_access:
            the app no longer reaches it (uninstalled, or the repo was taken out
            of the installation).
      required:
        - repo_id
        - full_name
        - html_url
        - default_branch
        - private
        - head_commit
        - pushed_at
        - state
  securitySchemes:
    bearer:
      type: http
      scheme: bearer
      description: An API key (pch_...) or the token from pch login.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.