Skip to content

Commit

Permalink
Merge pull request #616 from linear-b/fine/add-bitbucket-cloud-integr…
Browse files Browse the repository at this point in the history
…ation

Add Bitbucket Cloud Integration Support
  • Loading branch information
PavelLinearB authored Dec 23, 2024
2 parents f9b6bcd + c33c265 commit b8100cb
Show file tree
Hide file tree
Showing 10 changed files with 228 additions and 51 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Our research shows that code reviews are [the most consistent bottleneck in the

## 🚀 Get Started

gitStream is a GitHub / GitLab app that processes automations defined in Continuous Merge (CM) automation files contained in your git repos. You can test gitStream automations on your own PRs via the [gitStream playground](https://app.gitstream.cm/playground).
gitStream is a GitHub / GitLab / Bitbucket app that processes automations defined in Continuous Merge (CM) automation files contained in your git repos. You can test gitStream automations on your own PRs via the [gitStream playground](https://app.gitstream.cm/playground).

If you're ready to install gitStream, or want to explore its automation capabilities, [head over to the docs](https://docs.gitstream.cm). You can have your first automation up and running in as little as 2 minutes.

Expand Down Expand Up @@ -92,4 +92,4 @@ gitStream is a free product from the team at [LinearB](https://linearb.io/?utm_s
<img alt="Novu Logo" src="https://raw.githubusercontent.com/linear-b/gitstream/a5d4aca7b923e5cd70c813df06dc70de97382d8c/docs/downloads/images/LinearB-logo-dark.png" width="280"/>
</picture>
</a>
</div>
</div>
45 changes: 23 additions & 22 deletions docs/automation-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,32 @@ Actions are the end results of the automation described in your `.cm` file.

- :fontawesome-brands-github: Supported on GitHub
- :fontawesome-brands-gitlab: Supported on GitLab
- :fontawesome-brands-bitbucket: Supported on Bitbucket
- :fontawesome-solid-flask: Open beta - Feature is under development and currently available for all

## Overview

[`send-http-request`](#send-http-request) is executed immediately after the evaluation of the condition.
For all other actions, gitStream executes the actions in the order they are listed per automation. If an action result fails, the following actions will not be executed.

- [`add-comment`](#add-comment) :fontawesome-brands-github: :fontawesome-brands-gitlab:
- [`add-comment`](#add-comment) :fontawesome-brands-github: :fontawesome-brands-gitlab: :fontawesome-brands-bitbucket:
- [`add-github-check`](#add-github-check) :fontawesome-brands-github:
- [`add-label`](#add-label) :fontawesome-brands-github: :fontawesome-brands-gitlab:
- [`add-labels`](#add-labels) :fontawesome-brands-github: :fontawesome-brands-gitlab:
- [`add-reviewers`](#add-reviewers) :fontawesome-brands-github: :fontawesome-brands-gitlab:
- [`add-reviewers`](#add-reviewers) :fontawesome-brands-github: :fontawesome-brands-gitlab: :fontawesome-brands-bitbucket:
- [`add-thread`](#add-thread) :fontawesome-brands-gitlab:
- [`approve`](#approve) :fontawesome-brands-github: :fontawesome-brands-gitlab:
- [`close`](#close) :fontawesome-brands-github: :fontawesome-brands-gitlab:
- [`explain-code-experts`](#explain-code-experts) :fontawesome-brands-github: :fontawesome-brands-gitlab:
- [`merge`](#merge) :fontawesome-brands-github: :fontawesome-brands-gitlab:
- [`request-changes`](#request-changes) :fontawesome-brands-github: :fontawesome-brands-gitlab:
- [`approve`](#approve) :fontawesome-brands-github: :fontawesome-brands-gitlab: :fontawesome-brands-bitbucket:
- [`close`](#close) :fontawesome-brands-github: :fontawesome-brands-gitlab: :fontawesome-brands-bitbucket:
- [`explain-code-experts`](#explain-code-experts) :fontawesome-brands-github: :fontawesome-brands-gitlab: :fontawesome-brands-bitbucket:
- [`merge`](#merge) :fontawesome-brands-github: :fontawesome-brands-gitlab: :fontawesome-brands-bitbucket:
- [`request-changes`](#request-changes) :fontawesome-brands-github: :fontawesome-brands-gitlab: :fontawesome-brands-bitbucket:
- [`require-reviewers`](#require-reviewers) :fontawesome-brands-github:
- [`run-github-workflow`](#run-github-workflow) :fontawesome-brands-github:
- [`send-http-request`](#send-http-request) :fontawesome-brands-github:
- [`send-slack-message`](#send-slack-message) :fontawesome-brands-github:
- [`send-http-request`](#send-http-request) :fontawesome-brands-github: :fontawesome-brands-gitlab: :fontawesome-brands-bitbucket:
- [`send-slack-message`](#send-slack-message) :fontawesome-brands-github: :fontawesome-brands-gitlab: :fontawesome-brands-bitbucket:
- [`set-required-approvals`](#set-required-approvals) :fontawesome-brands-github:
- [`update-description`](#update-description) :fontawesome-brands-github:
- [`update-title`](#update-title) :fontawesome-brands-github:
- [`update-description`](#update-description) :fontawesome-brands-github: :fontawesome-brands-gitlab: :fontawesome-brands-bitbucket:
- [`update-title`](#update-title) :fontawesome-brands-github: :fontawesome-brands-gitlab: :fontawesome-brands-bitbucket:

!!! note

Expand All @@ -60,7 +61,7 @@ automations:

## Reference

#### `add-comment` :fontawesome-brands-github: :fontawesome-brands-gitlab:
#### `add-comment` :fontawesome-brands-github: :fontawesome-brands-gitlab: :fontawesome-brands-bitbucket:

This action, once triggered, adds a comment to the PR.

Expand Down Expand Up @@ -156,7 +157,7 @@ This is a managed action, when a PR updates existing labels that were added by g
</div>


#### `add-reviewers` :fontawesome-brands-github: :fontawesome-brands-gitlab:
#### `add-reviewers` :fontawesome-brands-github: :fontawesome-brands-gitlab: :fontawesome-brands-bitbucket:

This action, once triggered, sets a specific reviewer.

Expand Down Expand Up @@ -211,7 +212,7 @@ automations:
comment: "Please make sure this change request is documented before merging"
```

#### `explain-code-experts` :fontawesome-brands-github: :fontawesome-brands-gitlab:
#### `explain-code-experts` :fontawesome-brands-github: :fontawesome-brands-gitlab: :fontawesome-brands-bitbucket:

This action, shall add a comment with codeExperts suggestion. If the comment already exists, the comment shall be edited.

Expand All @@ -236,7 +237,7 @@ automations:
gt: 10
```

#### `approve` :fontawesome-brands-github: :fontawesome-brands-gitlab:
#### `approve` :fontawesome-brands-github: :fontawesome-brands-gitlab: :fontawesome-brands-bitbucket:

This action, once triggered, approves the PR for merge.

Expand All @@ -251,7 +252,7 @@ automations:
- action: approve@v1
```

#### `close` :fontawesome-brands-github: :fontawesome-brands-gitlab:
#### `close` :fontawesome-brands-github: :fontawesome-brands-gitlab: :fontawesome-brands-bitbucket:

This action, once triggered, close the PR without merging.

Expand All @@ -269,7 +270,7 @@ automations:
- action: close@v1
```

#### `merge` :fontawesome-brands-github: :fontawesome-brands-gitlab:
#### `merge` :fontawesome-brands-github: :fontawesome-brands-gitlab: :fontawesome-brands-bitbucket:

Once triggered, merge the PR if possible. It can be set to wait for all checks to pass or only required ones.

Expand All @@ -294,7 +295,7 @@ automations:
rebase_on_merge: true
```

#### `request-changes` :fontawesome-brands-github: :fontawesome-brands-gitlab:
#### `request-changes` :fontawesome-brands-github: :fontawesome-brands-gitlab: :fontawesome-brands-bitbucket:

This action, once triggered, requests changes on the PR. As long as request change is set, gitStream will block the PR merge.

Expand Down Expand Up @@ -401,7 +402,7 @@ has:
* We encourage you to use this action with [custom triggers](./execution-model.md#explicit-triggers)
* To manually test the webhook dispatch, please [run the workflow](https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/manually-running-a-workflow#running-a-workflow){:target="_blank"} before using it with gitStream.

#### `send-http-request` :fontawesome-brands-github:
#### `send-http-request` :fontawesome-brands-github: :fontawesome-brands-gitlab: :fontawesome-brands-bitbucket:

The action, once triggered, sends an HTTP request to the specified URL
<div class="filter-details" markdown=1>
Expand Down Expand Up @@ -431,7 +432,7 @@ automations:
body: '{"text": "Hello, world!"}'
```

#### `send-slack-message` :fontawesome-brands-github:
#### `send-slack-message` :fontawesome-brands-github: :fontawesome-brands-gitlab: :fontawesome-brands-bitbucket:

The action, once triggered, sends a webhook with a message content to a Slack app.
To use this action, [create a Slack app](https://api.slack.com/messaging/webhooks#getting_started) with Incoming Webhooks enabled. gitStream uses the webhook URL to send the message.
Expand Down Expand Up @@ -485,7 +486,7 @@ automations:

To allow this action to block merge, you should enable branch protection, and gitStream has to be set as required check in GitHub.

#### `update-description` :fontawesome-brands-github:
#### `update-description` :fontawesome-brands-github: :fontawesome-brands-gitlab: :fontawesome-brands-bitbucket:
This action, when triggered, updates the PR description with new content.

This is a managed action. When a PR updates, the existing comments that were added by gitStream are re-evaluated, and those that are not applicable are removed.
Expand Down Expand Up @@ -520,7 +521,7 @@ jira_ticket_from_title: {{ pr.title | capture(regex=r/\b[A-Za-z]+-\d+\b/) }}
```


#### `update-title` :fontawesome-brands-github:
#### `update-title` :fontawesome-brands-github: :fontawesome-brands-gitlab: :fontawesome-brands-bitbucket:
This action, when triggered, updates the PR title with new content.

This is a managed action. When a PR updates, the existing comments that were added by gitStream are re-evaluated, and those that are not applicable are removed.
Expand Down
79 changes: 79 additions & 0 deletions docs/bitbucket-installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
title: How to Setup gitStream with Bitbucket
description: Install gitStream to your Bitbucket workspace.
---
# How to Setup gitStream with Bitbucket

!!! info "gitStream for Bitbucket Cloud is currently in **beta**"

If you're interested in automating your Bitbucket pull requests and enhancing your development workflow, please [contact our support team](mailto:[email protected]) to request access and receive setup instructions.
We’d love to hear your feedback and collaborate to improve this integration during the beta phase. Thank you for your interest!

!!! info "Prerequisites"

1. Bitbucket Cloud account
2. Bitbucket Pipelines enabled
3. <a href="https://app.linearb.io/login" target="_blank">Login</a>, or <a href="https://app.linearb.io/sign-up" target="_blank">create a free account</a> on the LinearB app, and follow the steps to connect gitStream using a Bitbucket integration.

Bitbucket Installation Overview

1. Designate a gitStream user account.
2. Create a CM configuration file.
3. Create a Bitbucket pipeline.
4. Install the gitStream service.

## Designate a gitStream User Account

gitStream automation rules are executed on behalf of the user account configured when you install the gitStream service. This account must have the necessary permissions to the relevant repositories.

We recommend creating a dedicated service account to control access to individual repositories easily. You can also use your professional or personal Bitbucket account for this, which would result in all automations being executed under that account.

!!! tip "Use this account when you integrate gitStream"
Make sure to use this account when authorizing Bitbucket in LinearB.

## Create a CM Configuration File

Create a `gitstream.cm` rules file in the root directory of your repository's default branch (usually `master` or `main`). This file will contain a YAML configuration that determines the workflows that run on your repositories. You can name the CM file anything you want as long as it ends in `.cm`.

!!! info "Configuration files go in the repo's root directory."
Your `.cm` files should be placed in the repository's root directory.

!!! example "Example Configuration"
```yaml
--8<-- "docs/downloads/gitstream-bb.cm"
```

## Create a Bitbucket Pipeline

Once your gitStream configuration file is set up, you need a Bitbucket Pipelines configuration file to trigger gitStream automations. Create a `bitbucket-pipelines.yml` file in your repository's default branch (usually `master` or `main`) and add the following configuration:

```yaml
--8<-- "docs/downloads/bitbucket-pipelines.yml"
```

!!! warning "Note"
The `add-label` action is not supported in Bitbucket as Bitbucket does not have a native labeling feature.

## Install the gitStream Service

To complete the setup, install the gitStream service in your Bitbucket workspace. Follow the instructions provided in the LinearB app to connect your Bitbucket account and repositories to gitStream.

## Next Step
If you successfully complete these instructions, gitStream will now automate your code review workflows in Bitbucket.

!!! tip "How gitStream Works"
Read our guide, [How gitStream Works](/how-it-works/), for a deeper understanding of gitStream's capabilities and how to leverage them fully.

## Additional Resources

### Required Bitbucket Permissions

The required permissions are:

| Permissions | Reason |
| ----------------- | -------------------------------------------------------------------------------------------- |
| Read/Write API | To get notified on PR changes and allow gitStream to approve PRs once all conditions are met |
| Read repository | To read and check rules over the code changes on monitored repositories |
| Read user profile | Used to identify users |

</markdown>
49 changes: 49 additions & 0 deletions docs/downloads/bitbucket-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Code generated by gitStream - DO NOT EDIT

image: atlassian/default-image:4

pipelines:
# Pipelines that can only be triggered manually
custom:
gitstream:
- variables:
- name: client_payload
description: the client payload
- name: head_ref
description: the head sha
- name: base_ref
description: The base sha
- name: resolver_url
description: the resolver url to pass results to
- name: resolver_token
description: Optional resolver token for resolver service
- name: debug_mode
description: Debug mode
default: 'true'
- name: oauth_token
description: token to do operations in bitbucket
- name: full_repo
description: workspace/repo
- step:
name: /:\ gitstream workflow automation
max-time: 15
clone:
enabled: false
services:
- docker
script:
- git clone https://x-token-auth:[email protected]/$full_repo.git gitstream/repo
- git clone https://x-token-auth:[email protected]/$BITBUCKET_WORKSPACE/$BITBUCKET_REPO_SLUG.git gitstream/cm
- cd gitstream/repo
- git fetch --all
- git checkout $base_ref
- git checkout $head_ref
- docker pull gitstream/rules-engine:latest
- |
docker run -v $BITBUCKET_CLONE_DIR/gitstream:/code \
-e HEAD_REF=$head_ref \
-e BASE_REF=$base_ref \
-e CLIENT_PAYLOAD="$client_payload" \
-e RULES_RESOLVER_URL=$resolver_url \
-e RULES_RESOLVER_TOKEN=$resolver_token \
-e DEBUG_MODE=$debug_mode gitstream/rules-engine:latest
49 changes: 49 additions & 0 deletions docs/downloads/gitstream-bb.cm
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- mode: yaml -*-
# This example configuration provides basic automations to get started with gitStream.
# View the gitStream quickstart for more examples: https://docs.gitstream.cm/examples/
manifest:
version: 1.0


automations:
# Add a comment that indicates how many minutes it will take to review the PR.
estimated_time_to_review:
if:
- true
run:
- action: add-comment@v1
args:
comment: "{{ calc.etr }} min review"

# Inform PR authors when they fail to reference Jira tickets in the PR title or description.
comment_missing_jira_info:
if:
- {{ not (has.jira_ticket_in_title or has.jira_ticket_in_desc) }}
run:
- action: add-comment@v1
args:
comment: |
This PR is missing a Jira ticket reference in the title or description.
Please add a Jira ticket reference to the title or description of this PR.
# Post a comment that lists the best experts for the files that were modified.
explain_code_experts:
if:
- true
run:
- action: explain-code-experts@v1
args:
gt: 10


# +----------------------------------------------------------------------------+
# | Custom Expressions |
# | https://docs.gitstream.cm/how-it-works/#custom-expressions |
# +----------------------------------------------------------------------------+

calc:
etr: {{ branch | estimatedReviewTime }}

has:
jira_ticket_in_title: {{ pr.title | includes(regex=r/\b[A-Za-z]+-\d+\b/) }}
jira_ticket_in_desc: {{ pr.description | includes(regex=r/atlassian.net\/browse\/\w{1,}-\d{3,4}/) }}
18 changes: 7 additions & 11 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,38 @@ Choose which repositories are permitted to use GitHub Actions.

## Does gitStream services have access to my code?

Like any other CI/CD automation, the source code is being scanned in the repo and is not shared with any external services. Only metadata that relates and affects the workflow is shared to allow rule based automation on the repo.
Like any other CI/CD automation, the source code is being scanned in the repo and is not shared with any external services. Only metadata related to and affecting the workflow is shared to allow rule-based automation on the repo.

## Why does gitStream require permission to write code?
In order to support automations that either Approve or Merge PRs, GitHub API requires code write scope.
To support automations that either Approve or Merge PRs, the git providers require code write scope.

## What repos are supported?

Any repo in GitHub is supported. More Git providers are planned soon.
gitStream supports repositories in GitHub, GitLab, and Bitbucket. Note that the `add-label` action is not supported in Bitbucket as it does not have a native labeling feature.

## Can I use gitStream with Merge Queues?

Yes. When a merge queue is used, and gitStream is set as a required check, gitStream automation will be invoked with the merge event. The automation will set gitStream to a `Completed` status and `Skipped` conclusion to allow the PR merge.
![gitStream with Merge Queue](screenshots/merge-queue-check.png)

## Custom filter functions

Coming soon.

## Is there .cm syntax highlighting?

The `.cm` file use YAML with JINJA2, in order for your favorite editor to choose automatically the right syntax, you can use modelines.
The `.cm` file uses YAML with JINJA2. For your favorite editor to automatically choose the right syntax, you can use modelines.

Add the following line to the top of the `.cm` file (the default has it already):

```
# -*- mode: yaml -*-
```

Get a plug-in that enable modelines, popular ones are:
Get a plug-in that enables modelines. Popular ones are:

- VS Code: [Modelines](https://marketplace.visualstudio.com/items?itemName=chrislajoie.vscode-modelines)
- Sublime Text: [CM syntax for ST4](https://packagecontrol.io/packages/Continuous%20Merge) or [Emacs-like Sublime Modeline](https://github.com/kvs/STEmacsModelines)
- Vim [Modeline magic](https://vim.fandom.com/wiki/Modeline_magic)

## I have an issue I can't seem to solve, what should I do?
## I have an issue I can't seem to solve. What should I do?

Go to our issues page and check if there are any similar issues already reported. If not, create a new issue with all the details so we can take a look.
Go to our issues page and check if any similar issues are already reported. If not, create a new issue with all the details so we can take a look.

Found a bug? Create a new item in the [project's issues](https://github.com/linear-b/gitstream/issues)
Loading

0 comments on commit b8100cb

Please sign in to comment.