Dive

Guides

Test a tool

Call a tool with input and read its result or error.

commits_by_author counts the commits each author made since a git ref.

version: 2
name: commits_by_author
description: How many commits each author made since a git ref.
kind: exec
command: bash
args:
- -ceuo
- pipefail
- |
  git shortlog -sn --no-merges "$1..HEAD" </dev/null \
    | jq -Rs '[split("\n")[] | select(length > 0)
        | capture("^\\s*(?<commits>[0-9]+)\\t(?<author>.+)$")
        | {author, commits: (.commits | tonumber)}]'
- commits_by_author
- '{{input.base}}'
output: json
read_only: true
input_schema:
  type: object
  required:
  - base
  properties:
    base:
      type: string
      description: The ref to start after, such as a release tag

Call the tool

Pass the tool's name, as dive tool list prints it, and set its input with --input:

dive tool test user__commits_by_author \
  --input base=v0.14.0

Dive calls the tool and prints its result:

[
  {
    "author": "Tyler Davis",
    "commits": 32
  }
]

Read an error

Give it a ref that doesn't exist, and add --json to see whether the call failed:

dive tool test user__commits_by_author \
  --input base=v9.9.9 --json

isError is true, and result carries the command's exit status and stderr:

{
  "isError": true,
  "result": {
    "error": "'bash' exited with exit status: 128",
    "stderr": "fatal: ambiguous argument 'v9.9.9..HEAD': unknown revision or path not in the working tree.…",
    "stdout": "[]"
  },
  "tool": "user__commits_by_author"
}

The command still exits with code 0, so check isError in scripts.