---
description: This Script is faster, more powerful, and easier to implement.
---

# Updated New Script

## Appsurify Script Installation

***

### Index

* Installation Instructions
  * Requirements
  * Support OS / Python
  * Installation Command
* Repository Push / Git2TestBrain (git2appsurify)
  * Possible params
  * Usage Examples
* Repository Checkout
  * Possible Params
  * Usage Examples

## Installation Instructions

***

### Requirements

{% hint style="success" %}
Python 3.7+
{% endhint %}

### Support OS / Python



<table><thead><tr><th width="253">OS</th><th width="232">Python</th><th>Support</th></tr></thead><tbody><tr><td>Linux</td><td>3.7</td><td> 🟢</td></tr><tr><td>Linux</td><td>3.8</td><td> 🟢</td></tr><tr><td>Linux</td><td>3.11</td><td> 🟢</td></tr><tr><td>MacOS</td><td>3.7</td><td> 🟢</td></tr><tr><td>MacOS</td><td>3.8</td><td> 🟢</td></tr><tr><td>MacOS</td><td>3.11</td><td> 🟢</td></tr><tr><td>Windows</td><td>3.7</td><td> 🟢</td></tr><tr><td>Windows</td><td>3.8</td><td> 🟢</td></tr><tr><td>Windows</td><td>3.11</td><td> 🟢</td></tr></tbody></table>

### Installation Command

```
pip install appsurify-testbrain-cli
```

or

```
poetry add appsurify-testbrain-cli
```

{% hint style="info" %}
Note: Use -U or --upgrade for force upgrade to last version
{% endhint %}

### Docker image "appsurify-testbrain-cli"

#### Latest Version

```
docker pull appsurifyinc/appsurify-testbrain-cli
```

#### Specify version

```
docker pull appsurifyinc/appsurify-testbrain-cli:2023.10.24
```

## Repository Push | Git2Testbrain (git2appsurify)

***

This module is used to push changes in the repository to the Testbrain server for further analysis and testing optimization.

{% hint style="info" %}
This module can be used as an independent command in the OS or as a subcommand of the main CLI application "testbrain"
{% endhint %}

Alias #1

```
testbrain repository push --help
```

Alias #2

```
git2testbrain push --help
```

Alias #3

```
testbrain git2testbrain push --help
```

### Parameters

<table><thead><tr><th width="141">Required</th><th width="121">Parameter</th><th width="95">Default</th><th width="138">Env</th><th>Description</th></tr></thead><tbody><tr><td>Yes</td><td>--server</td><td></td><td>TESTBRAIN_SERVER</td><td>Enter your Testbrain server instance url.</td></tr><tr><td>Yes</td><td>--token</td><td></td><td>TESTBRAIN_TOKEN</td><td>Enter your testbrain server instance token or API Key. <br><br>Located in top-right hand corner of user-interface under user profile. </td></tr><tr><td>Yes</td><td>--project</td><td></td><td>TESTBRAIN_PROJECT</td><td>Enter your Testbrain projet name. </td></tr><tr><td>No</td><td>--work-dir</td><td>current dir</td><td>TESTBRAIN_WORK_DIR</td><td>Enter the testbrain script working directory. If not specified, the current working directory will be used. </td></tr><tr><td>No</td><td>--repo name</td><td></td><td>TESTBRAIN_REPO_NAME</td><td>Define repository name. If not specified, it will be automatically taken from the GitRepository repository.</td></tr><tr><td>No</td><td>--repo-dir</td><td>current dir</td><td>TESTBRAIN_REPO_DIR</td><td>Enter the git repository directory. If not specified, the current working directory will be used. </td></tr><tr><td>No</td><td>--branch</td><td>current</td><td>TESTBRAIN_BRANCH</td><td>Enter the explicit branch to process commits. If not specified, use current active branch. </td></tr><tr><td>No</td><td>--start / --commit</td><td>latest (HEAD)</td><td>TESTBRAIN_START_COMMIT</td><td>Enter the commit that should be starter. If not specified, it will be used 'latest' commit. </td></tr><tr><td>No</td><td>--number</td><td>1</td><td>TESTBRAIN_NUMBER_OF_COMMITS</td><td>Enter the number of commits to process. </td></tr><tr><td>No (unavailable)</td><td>--blame</td><td>false</td><td></td><td>Add blame information.</td></tr><tr><td>No</td><td>--minimize</td><td>false</td><td></td><td>Suppress commit changes information. [default; (False)]</td></tr><tr><td>No</td><td>--pr-mode</td><td>false</td><td>TESTBRAIN_PR_MODE</td><td>Activate PR mode</td></tr><tr><td>No</td><td>-l, --loglevel</td><td>INFO</td><td></td><td>Possible fatalities: DEBUG/INFO/WARNING/ERROR</td></tr><tr><td>No</td><td>--logfile</td><td>stderr</td><td></td><td>Saves logs to file</td></tr><tr><td>No</td><td>--quiet</td><td>fales</td><td></td><td>Quiet mode...every time exit with 0</td></tr></tbody></table>

### Usage Examples

Push to Testbrain server only one last commit from current branch:

```
git2testbrain --server https://demo.appsurify.com --token ************************************************************** --project DEMO
```

Or

```
git2testbrain push --server https://demo.appsurify.com --token ************************************************************** --project DEMO
```

Push to Testbrain server last 100 commits started from specify commit into specify branch:

```
git2testbrain --server https://demo.appsurify.com --token ************************************************************** --project DEMO --branch main --start latest --number 100
```

If need more process information - change logging level:

```
git2testbrain --server https://demo.appsurify.com --token ************************************************************** --project DEMO --branch main --start latest --number 100 --loglevel DEBUG
```

Add log file with full or relative path:

```
git2testbrain --server https://demo.appsurify.com --token ************************************************************** --project DEMO --branch main --start latest --number 100 --loglevel INFO --logfile ./git2testbrain.log
```

If any crash errors script will create crash dump file into {WORK\_DIR}/.crashdumps/

```
git2testbrain --server https://demo.appsurify.com --token ************************************************************** --project DEMO
```

You can see this message:

```
2023-11-05 21:16:03 INFO     testbrain.repository.cli push [repository/cli.py:184] Running...
2023-11-05 21:16:03 DEBUG    testbrain.terminal.process Process.__init__ [terminal/process.py:22] Set up execution working dir ...
Dumped crash report to <path_to_work_dir>/.crashdumps/git2testbrain-2023-10-23-11-27-39.dump
```

**Docker version usage**

$(pwd) - git repository path

```
docker run --rm -it \
-v $(pwd)/:/data \
appsurifyinc/appsurify-testbrain-cli git2testbrain --server https://demo.appsurify.com --token ************************************************************** --project DEMO
```

#### CI example (github actions)

.github/workflows/testbrain-git2testbrain.yml

```
name: "Testbrain"

on:
    workflow_dispatch:
    pull_request:
        branches:
            - "main"
            - "development"
    push:
        branches:
            - "main"
            - "releases/*.*.*"
            - "development"

jobs:
    push-changes:
        name: "Push changes to server"
        runs-on: ubuntu-latest
        permissions:
            contents: write
            pull-requests: write
            checks: write
        steps:
            - name: "Checkout repository"
              uses: actions/checkout@v4
              with:
                  fetch-depth: 0
            - name: "Extract branch name"
              shell: bash
              run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
              id: extract_branch
            - name: "Push"
              uses: addnab/docker-run-action@v3
              with:
                  image: appsurifyinc/appsurify-testbrain-cli:latest
                  options: -v ${{ github.workspace }}:/data -e TESTBRAIN_PR_MODE=${{ github.event_name == 'pull_request' }}
                  run: |
                      git2testbrain push --server ${{ vars.TESTBRAIN_SERVER }} --token ${{ secrets.TESTBRAIN_TOKEN }} --project ${{ vars.TESTBRAIN_PROJECT }} --branch ${{ steps.extract_branch.outputs.branch }} --start ${{ github.sha }} --number ${{ vars.TESTBRAIN_NUMBER_OF_COMMITS }} -l DEBUG
            - name: "Upload crash dumps"
              uses: actions/upload-artifact@v3
              if: failure()
              with:
                  name: "crashdumps"
                  path: ${{ github.workspace }}/.crashdumps/
                  retention-days: 1
```

### Repository Checkout

***

This module is used to checkout branches during the execution of CI pipelines or manually. **Cloning is not provided.**

Alias #1 &#x20;

```
testbrain repository checkout --help
```

Alias #2 &#x20;

```
git2testbrain checkout --help
```

Alias #3&#x20;

```
testbrain git2testbrain checkout --help
```

### Parameters

<table><thead><tr><th width="130">Required</th><th width="120">Parameter</th><th width="128">Default</th><th width="129">Env</th><th>Description</th></tr></thead><tbody><tr><td>No</td><td>--repo-dir</td><td>current dir</td><td>TESTBRAIN_REPO_DIR</td><td>Enter the git repository directory. If not specified, the current working directly will be used.</td></tr><tr><td>No</td><td>--branch</td><td>current</td><td>TESTBRAIN_BRANCH</td><td>Enter the explicit branch to process commits. If not specified, use current active branch. </td></tr><tr><td>No</td><td>--commit</td><td>latest (HEAD)</td><td>TESTBRAIN_START_COMMIT</td><td>Enter the commit that should be starter. If not specified, it will be used 'latest' commit.</td></tr><tr><td>No</td><td>--pr-mode</td><td>False</td><td>TESTBRAIN_PR_MODE</td><td>Activate PR mode</td></tr><tr><td>No</td><td>--work-dir</td><td>current dir</td><td>TEST_WORK_DIR</td><td>Enter the testbrain script working directory, the current working directory will be used. </td></tr><tr><td>No</td><td>-l, --loglevel</td><td>INFO</td><td></td><td>Possible Fatalities: DEBUG/INFO/WARNING/ERROR</td></tr><tr><td>No</td><td>--logfile</td><td>stderr</td><td></td><td>Save logs to file</td></tr><tr><td>No</td><td>--quiet</td><td>false</td><td></td><td>Quiet mode...every time exit with 0</td></tr></tbody></table>

### Usage Examples:

Checkout using Testbrain CLI

```
git2testbrain checkout --branch main -l INFO
```

Or

```
git2testbrain checkout --branch main --commit 75ec2f061868c33306963a27d5164211553c049b --pr-mode -l INFO
```

Or

```
git2testbrain checkout --branch main --commit 676c581 --pr-mode -l INFO
```

Docker version usage

$(pwd) - git repository path

```
docker run --rm -it \
-v $(pwd)/:/data \
appsurifyinc/appsurify-testbrain-cli git2testbrain checkout --branch main --commit 676c581 --pr-mode -l INFO
```
