## Pierre Bot

**Pierre Bot** is an AI-powered code review companion designed for Bitbucket Server/Data Center.
It fetches pull request diffs, analyzes them using Google's Gemini 2.0 Flash model, and identifies potential bugs, style issues, or logic errors.

## Installation

Ensure you have [Go](https://go.dev/) installed, then clone the repository and build the binary:

```bash
git clone https://git.schreifuchs.ch/schreifuchs/pierre-bot.git
cd pierre-bot
go build -o pierre ./cmd/pierre/main.go

```

## Configuration

Pierre Bot can be configured via **Command Line Flags**, **Environment Variables**, or a **YAML Config File**.

### Configuration Hierarchy

1. Command line flags
2. Environment variables
3. `config.yaml` in the current directory
4. `~/.pierre.yaml`

### Required Environment Variables

To avoid passing sensitive tokens in plain text, it you cann export these:

```bash
export BITBUCKET_URL="https://your-bitbucket-instance.com"
export BITBUCKET_TOKEN="your-personal-access-token"
export LLM_API_KEY="your-gemini-api-key"

```

## Usage Examples

The tool uses **positional arguments** for the specific Pull Request you want to target:
`pierre <project> <repo> <pr-id>`

### 1. Basic Command Line Usage

If you have your environment variables set, simply run:

```bash
./pierre-bot PROJ-KEY my-app-repo 125

```

### 2. Using a Configuration File

You can create a `config.yaml` file to store persistent settings:

```yaml
# config.yaml
bitbucket-url: "https://bitbucket.example.com"
bitbucket-token: "np-mY-S3cr3t-T0k3n"
```

Then run the bot:

```bash
./pierre-bot --config config.yaml PROJ-KEY my-app-repo 125

```

### 3. Overriding Everything via Flags

```bash
./pierre \
  --bitbucket-url="https://bitbucket.example.com" \
  --bitbucket-token="token" \
  MYPROJECT my-repo 42

```
