swagger: "2.0"
info:
  description: "GitHub webhook handler"
  version: "1.0.0"
  title: "github-webhooks-svc"
  contact:
    name: "Infra"
    email: "infrateam@zoox.com"
    url: "https://git.zooxlabs.com/zooxco/driving"

basePath: "/api/v1"

schemes:
  - "https"

paths:
  "/webhook":
    post:
      summary: "Incoming webhook from GitHub"
      description: ""
      operationId: "ci.webhooks.server.webhook"
      produces:
        - "application/json"
      parameters:
        - in: "body"
          name: "payload"
          schema:
            $ref: "#/definitions/Webhook"
      responses:
        "200":
          description: "Successful operation"
          schema:
            $ref: "#/definitions/WebhookSuccessResponse"
        "204":
          description: "No content"
        "422":
          description: "Invalid parameter"
          schema:
            $ref: "#/definitions/ErrorResponse"
        "500":
          description: "Internal server error"
          schema:
            $ref: "#/definitions/ErrorResponse"
  "/config":
    get:
      summary: "Returns the current config"
      description: ""
      operationId: "ci.webhooks.server.config"
      responses:
        "200":
          description: "Returned current config"
          schema:
            $ref: "#/definitions/ConfigResponse"
        "500":
          description: "Internal server error"
          schema:
            $ref: "#/definitions/ErrorResponse"
  "/health/status":
    get:
      summary: "Health check"
      description: ""
      operationId: "ci.webhooks.server.health"
      responses:
        "200":
          description: "Healthy"
          schema:
            $ref: "#/definitions/HealthResponse"
        "500":
          description: "Unhealthy"
          schema:
            $ref: "#/definitions/HealthResponse"

definitions:
  # This takes many different forms and varies greatly based on the type of
  # event.
  Webhook:
    type: "object"
    additionalProperties: true

  ConfigResponse:
    type: "object"
    properties:
      optInCi:
        description: "True iff opt-in CI is enabled"
        type: "boolean"
      debug:
        description: "True iff debug mode is enabled"
        type: "boolean"
      launchPipedreamExperimentalBuild:
        description: "True iff an experimental pipedream build should be launched"
        type: "boolean"
      experimentName:
        description: "Name of experiment"
        type: "string"
      experimentalBuildPercentage:
        description: "Percentage of builds to launch the experiment on"
        type: "integer"
      experimentalPlans:
        description: "Plans that are launched for the experiment"
        type: "array"
        items:
          type: "string"

  HealthResponse:
    type: "object"
    properties:
      message:
        description: "A message describing the health"
        type: "string"

  ErrorResponse:
    type: "object"
    properties:
      message:
        description: "A message describing the error"
        type: "string"

  WebhookSuccessResponse:
    type: "object"
    properties:
      message:
        description: "A success message"
        type: "string"
