Skip to content

Bitbucket

Run as a Bitbucket Pipeline

You can use the Bitbucket Pipeline system to run PR-Agent on every pull request open or update.

  1. Add the following file in your repository bitbucket-pipelines.yml
pipelines:
    pull-requests:
      '**':
        - step:
            name: PR Agent Review
            image: codiumai/pr-agent:latest
            script:
              - pr-agent --pr_url=https://bitbucket.org/$BITBUCKET_WORKSPACE/$BITBUCKET_REPO_SLUG/pull-requests/$BITBUCKET_PR_ID review
  1. Add the following secure variables to your repository under Repository settings > Pipelines > Repository variables.

  2. CONFIG__GIT_PROVIDER: bitbucket

  3. OPENAI__KEY: <your key>
  4. BITBUCKET__AUTH_TYPE: basic or bearer (default is bearer)
  5. BITBUCKET__BEARER_TOKEN: <your token> (required when auth_type is bearer)
  6. BITBUCKET__BASIC_TOKEN: <your token> (required when auth_type is basic)

You can get a Bitbucket token for your repository by following Repository Settings -> Security -> Access Tokens. For basic auth, you can generate a base64 encoded token from your username:password combination.

Note that comments on a PR are not supported in Bitbucket Pipeline.

Bitbucket Server and Data Center

Login into your on-prem instance of Bitbucket with your service account username and password. Navigate to Manage account, HTTP Access tokens, Create Token. Generate the token and add it to .secret.toml under bitbucket_server section

[bitbucket_server]
bearer_token = "<your key>"

Run it as CLI

Modify configuration.toml:

git_provider="bitbucket_server"

and pass the Pull request URL:

python cli.py --pr_url https://git.onpreminstanceofbitbucket.com/projects/PROJECT/repos/REPO/pull-requests/1 review

Run it as service

To run PR-Agent as webhook, build the docker image:

docker build . -t codiumai/pr-agent:bitbucket_server_webhook --target bitbucket_server_webhook -f docker/Dockerfile
docker push codiumai/pr-agent:bitbucket_server_webhook  # Push to your Docker repository

Navigate to Projects or Repositories, Settings, Webhooks, Create Webhook. Fill the name and URL, Authentication None select the Pull Request Opened checkbox to receive that event as webhook.

The URL should end with /webhook, for example: https://domain.com/webhook

Footer