# Bitbucket

The Bitbucket integration connects Interlynk to your Bitbucket workspaces, enabling automated SBOM processing triggered by repository events.

***

## Purpose

* Automatically ingest SBOMs on push and pull request events from Bitbucket repositories.
* Map Bitbucket branches to Interlynk environments.

## Setup Steps

Interlynk connects to Bitbucket via OAuth.

1. Navigate to **Settings > Organization > Integrations**.
2. Click **Bitbucket**.
3. You will be redirected to Bitbucket to authorize the Interlynk application.
4. Complete the authorization.
5. After redirect, select the **Workspace** from the dropdown.
6. Click **Save**.

## Supported Events

| Event                   | Trigger                 |
| ----------------------- | ----------------------- |
| `repo:push`             | Code pushed to a branch |
| `pullrequest:created`   | New pull request opened |
| `pullrequest:fulfilled` | Pull request merged     |
| `pullrequest:updated`   | Pull request updated    |

## Required Scopes

| Scope              | Purpose                                 |
| ------------------ | --------------------------------------- |
| Repository read    | Access repository contents and metadata |
| Pull request read  | Read pull request details               |
| Webhook read/write | Register and manage webhooks            |

## Security Notes

* OAuth tokens are encrypted at rest and refreshed automatically.
* The integration only accesses repositories within the selected workspace.
* Revoke access from Bitbucket's **Personal Settings > App authorizations** if needed.

## Troubleshooting

| Issue                            | Cause                                | Resolution                                             |
| -------------------------------- | ------------------------------------ | ------------------------------------------------------ |
| No workspaces visible            | OAuth scope too narrow               | Re-authorize the Bitbucket integration                 |
| Push events not triggering       | Webhook not registered on repository | Verify workspace selection and re-save the integration |
| Token expired and not refreshing | Refresh token revoked                | Disconnect and reconnect the Bitbucket integration     |
