syntax = "proto3";

import "proto/context.proto";

package runner;

message RunRequest {
  // The request context.
  context.RequestContext request_context = 1;

  message GitRepo {
    // The HTTPS URL of the Git repository that will be checked
    // out and built as part of this project.
    // Ex. "https://github.com/buildbuddy-io/buildbuddy-internal"
    string repo_url = 1;

    // The access token to use when cloning this repository.
    //
    // For Github, and Gitlab, this is known as a Personal Access Token.
    //
    // For Bitbucket, this is known as an App Password, which requires
    // an associated username. The app password requires the following
    // permissions: [webhooks: r+w, pull requests: r+w; repo: r+w]
    //
    // If omitted, this defaults to the access token for the linked
    // GitHub account, if the repo URL is a GitHub URL. Otherwise,
    // an error is returned.
    //
    // Ex. "ABASDBASDBASBD"
    string access_token = 2;

    // The username to use when cloning this repository.
    // This is required for Bitbucket, whose "app passwords" require an
    // associated username.
    string username = 3;
  }

  // The git repository to checkout. Required.
  GitRepo git_repo = 2;

  message RepoState {
    // SHA of the commit to be checked out. This happens before applying
    // any patches (see below).
    // Ex. "e782592faf56da05cc0a243220689135e807958f"
    string commit_sha = 1;

    // Any local patches that should be applied to the repo before
    // running the command. Patches will be applied using "git apply"
    // in the root directory of the repository.
    repeated string patch = 2;
  }

  // The state of the repository. Optional. (default is HEAD, without patches).
  RepoState repo_state = 3;

  // The bazel command to run. Required.
  // Example: "build :server"
  // Example: "test //..."
  string bazel_command = 4;

  // The remote instance name. Everything happens within this namespace, so
  // changing this key will mean hitting a different cache and remote executor.
  // Optional.
  string instance_name = 5;

  // Key used to indicate preference to which Bazel instance the request should
  // be routed to.
  string session_affinity_key = 6;
}

message RunResponse {
  // The response context.
  context.ResponseContext response_context = 1;

  // The invocation ID of the run.
  string invocation_id = 2;
}
