Skip to content

Open Pull Requests

Pull requests from the changes of an exec job, opened from inside the program or after the job.

Requirements:

1. Call Gradient from the Job

All attempts start with their own job token. The gradient CLI in the guest can run without login. Jobs for pull requests from unapproved forks can use only gradient build. That job can send a build request and stream the build logs of evaluations that it created. That job can also poll those evaluations.

Place Content
/home/gradient/.config/gradient/config.toml Server, token, the job's project and task as selections
GRADIENT_API, GRADIENT_TOKEN The same server and token for scripts
GRADIENT_PROJECT_NAME, GRADIENT_TASK_NAME Names of the job's project and task
Job token scope Access
Reads Own project, its tasks, evaluations, builds and exec jobs
Writes Build requests, evaluations and pull requests of the own task
Everything else 403 with job tokens only reach their own project and task
Evaluation without project credentials Build request routes. POST /evals/{id}/builds, GET /evals/{id} and GET /evals/{id}/artefacts apply only to evaluations from the job's own build request. All other routes return 403 with job tokens without project credentials for evaluations reach only build requests and the evaluations that those build requests started.
  • Job tokens act with the rights of the user behind the evaluation, else the task creator.
  • Tokens end with the attempt. Job pages list each token with its expiry, never its value.
  • Logs show the token as [secret:job-token].
  • Changed trees reach the workers through gradient build, see Build Before Pushing. Job pages link each such evaluation.

2. Pick a Way

Way Pick for
gradient pr open in the program Many pull requests per job, each with chosen paths
exec_tree PR action One pull request with every change, without a CLI call

Both ways need an open_pr action to name a Git host connection. Tasks without one return There is no open_pr action on the task to specify a connection to the Git host..

3. Open from the Program

gradient pr open --title "flake: update inputs" --branch update/flake flake.lock
  • Listed paths limit the diff. Calls without paths take the whole tree, new untracked files included.
  • Equal paths without --branch update the same pull request.
  • Force updates from Gradient move the branch from --branch or branch_pattern to the base branch and the new commit. These force updates go through the connection to the Git host for the open_pr action. Only the protection measures for branches on the Git host protect the branch.
  • Patches deleting a file fail with the patch deletes <path>; deleting files is not supported.
  • Secret values in the patch receive masks before the upload.
  • All options are in the CLI reference.

4. Open after the Job

Go to Actions -> New Action inside the task. Select PR as the type. Pick a value for Git host connection. Set Generator to Exec Tree.

Do the same as GitHub guide and declare the github-acme connection first.

services.gradient.state.tasks.infra.actions = [{
  name = "tree-pr";
  type = "open_pr";
  config = {
    git_host_connection = "github-acme";
    generator = "exec_tree";
    branch_pattern = "update/{entry_point}"; # (1)!
  };
}];
  1. branch_pattern, title_template and body_template accept {entry_point} and {job}.
  • Completed exec jobs of the task fire the action.
  • Jobs without changes in /work open nothing.

Verify Deployment

  • Job tokens and pull requests show on the job page.
  • Pull requests appear on the Git host with the branch from --branch or the action.

Next Steps