---
metadata:
  - name: generator
    content: Diplodoc Platform v5.63.0
alternate:
  - https://vibe.sourcecraft.dev/portal/docs/en/sourcecraft/operations/code-review.md
  - https://vibe.sourcecraft.dev/portal/docs/ru/sourcecraft/operations/code-review.md
  - href: https://vibe.sourcecraft.dev/portal/docs/en/sourcecraft/operations/code-review.md
    type: text/markdown
    title: Markdown version
  - href: https://vibe.sourcecraft.dev/portal/docs/en/llms.txt
    rel: describedby
title: Setting up approval rules in a SourceCraft repository
description: How to set up approval rules in a SourceCraft repository using a configuration file.
---
> **Documentation Index:** Fetch the complete configuration index at https://vibe.sourcecraft.dev/portal/docs/en/llms.txt


# Setting up approval rules in a SourceCraft repository

<!-- source: en/_includes/sourcecraft/configuration-tip.md -->
{% note tip %}

You can set up and view repository configurations in the SourceCraft interface under ![image](../../_assets/console-icons/gear.svg) **Repository settings** in the ![image](../../_assets/console-icons/nut-hex.svg) **Configurations** section. Learn more in [this article](https://vibe.sourcecraft.dev/portal/docs/en/sourcecraft/operations/configuration-edit.md).

{% endnote %}
<!-- endsource: en/_includes/sourcecraft/configuration-tip.md -->

<!-- source: en/_includes/sourcecraft/code-review-intro.md -->
With SourceCraft, you can flexibly set up mandatory approval rules before any code can be added to the target branch of the repository.
<!-- endsource: en/_includes/sourcecraft/code-review-intro.md -->

For more information, see [Approval rules in SourceCraft](https://vibe.sourcecraft.dev/portal/docs/en/sourcecraft/concepts/code-review.md).

<!-- source: en/_includes/sourcecraft/code-review-file.md -->
You specify the approval rule configuration for a particular repository and store it in the `.sourcecraft/review.yaml` file. You can also set the [configuration at the SourceCraft organization level](https://vibe.sourcecraft.dev/portal/docs/en/sourcecraft/concepts/org-config.md).
<!-- endsource: en/_includes/sourcecraft/code-review-file.md -->

To set up approval rules in a repository: 
1. Clone the repository:

    <!-- source: en/_includes/sourcecraft/clone-repo-workflow.md -->
    1. [Install Git](https://git-scm.com/downloads).
    1. Open the SourceCraft [home page](https://sourcecraft.dev).
    1. On the ![image](../../_assets/console-icons/house.svg) **Home** tab, under ![image](../../_assets/console-icons/layout-tabs.svg) **Your craftspace**, navigate to ![image](../../_assets/console-icons/archive.svg) **Repositories** and select your repository.

        Also, you can open any public repository.

    1. In the top-right corner of the repository page, click ![image](../../_assets/console-icons/chevron-down-wide.svg) **Clone**.
    1. From the **HTTPS** or **SSH** field, copy the ![image](../../_assets/console-icons/copy.svg) repository cloning link.

        Depending on the cloning connection protocol, different domains are used:

        #|
        || **Protocol** | **Domain** | **Cloning link** ||
        || HTTPS | `git.sourcecraft.dev` | `https://git@git.sourcecraft.dev/<organization_slug>/<repository_slug>.git` ||
        || SSH | `ssh.sourcecraft.dev` | `ssh://ssh.sourcecraft.dev/<organization_slug>/<repository_slug>.git` ||
        |#

    1. In the terminal, run this command:

        ```bash
        git clone <link_for_cloning_repository>
        ```

        {% cut "Example of a command for cloning a repository with SourceCraft documentation" %}

        ```bash
        git clone https://git@git.sourcecraft.dev/sourcecraft/documentation.git
        ```

        {% endcut %}

        <!-- source: en/_includes/sourcecraft/private-repo-clone-note.md -->
        {% note warning %}

        To clone a [private or internal repository](https://vibe.sourcecraft.dev/portal/docs/en/sourcecraft/concepts/index.md#repos), authenticate with a [personal access token (PAT)](https://vibe.sourcecraft.dev/portal/docs/en/sourcecraft/security/pat.md) or [SSH key](https://vibe.sourcecraft.dev/portal/docs/en/sourcecraft/security/ssh.md).

        {% endnote %}
        <!-- endsource: en/_includes/sourcecraft/private-repo-clone-note.md -->

    1. Go to your cloned repository:
        
        ```bash
        cd <repository_name>
        ```
    <!-- endsource: en/_includes/sourcecraft/clone-repo-workflow.md -->

1. Generate an approval rule configuration file named `.sourcecraft/review.yaml`, e.g.:

    <!-- source: en/_includes/sourcecraft/code-review-config.md -->
    ```yaml
    codereview: 
      need_ships: 1 # Required number of approvals from reviewers
      ignore_self_ship: false # Ignore approvals from the pull request author
      ignore_non_reviewers_block: false # Ignore pull request blocking from non-reviewers
      auto_assign: true # Automatically assign reviewers
      disable_trust: true # Prohibit the _Trust_ resolution for pull requests
      rules:
        - patterns:
            - "**" # Repository path pattern
          reviewers:
            usernames: 
              - "<user_name>" # List of reviewers
            assign: 1 # Number of automatically assigned reviewers
            need_ships: 1 # Required number of approvals from reviewers
            ignore_self_ship: false # Ignore approvals from the pull request author
    ```
    <!-- endsource: en/_includes/sourcecraft/code-review-config.md -->

    <!-- source: en/_includes/sourcecraft/wildcard-pattern-tip.md -->
    {% note tip %}

    For group filtering, we recommend to use the `**` pattern because the simple `*` pattern will not give you a match in expressions with `/`.

    {% endnote %}
    <!-- endsource: en/_includes/sourcecraft/wildcard-pattern-tip.md -->

1. <!-- source: en/_includes/sourcecraft/review-patterns.md -->
   Under `patterns`, specify the repository paths for your approval rules as follows:

   * `"**"`: Apply the rule to the entire repository.
   * `"src/**"`: Apply the rule only to the `src` directory.
   * `"!docs/**"`: Do not apply the rule to the `docs` directory.

   You can list multiple patterns one by one, like this:

   ```yaml
   - patterns:
     - "**"
     - "!docs/**"
   ```

   This way, the rule will apply to any changes in your repository except those in the `docs` directory.

   {% note tip %}

   When using multiple patterns, list the `"**"` pattern first.

   {% endnote %}
   <!-- endsource: en/_includes/sourcecraft/review-patterns.md -->

   For more information on path filter syntax and rules, see [Filters and patterns in SourceCraft](https://vibe.sourcecraft.dev/portal/docs/en/sourcecraft/concepts/filters-by-paths.md).

1. Under `usernames`, list the users the pull request must feature at least one approval from.
1. Add the approval rule configuration file to the `git` index, commit, and push the changes to the `main` branch:

    ```bash
    git add .sourcecraft/review.yaml
    git commit -m "Added code review configuration"
    git push -u origin main
    ```

1. Make sure that the approval rules were applied:
    1. [Create](https://vibe.sourcecraft.dev/portal/docs/en/sourcecraft/operations/pr-create.md) a test pull request.
    1. Make sure that in the pull request you created:
        * The ![image](../../_assets/console-icons/circle-exclamation.svg) **Overview** tab displays the **Code Review** verification with `In progress` status.
        * The **Reviewers** section shows some of the reviewers from among those specified in the approval rule configuration file.
    1. Wait until your pull request is approved.
    1. To merge with the main branch, click ![image](../../_assets/console-icons/code-pull-request.svg) **Merge**.

        The merging can be done only by users with the `Repository developer` [role](https://vibe.sourcecraft.dev/portal/docs/en/sourcecraft/security/index.md#src-repositories-developer) or higher.

<!-- source: en/_includes/sourcecraft/code-review-bypass.md -->
{% note warning %}

Only users with the [`Repository maintainer`](https://vibe.sourcecraft.dev/portal/docs/en/sourcecraft/security/index.md#src-repositories-maintainer) or [`Repository admin`](https://vibe.sourcecraft.dev/portal/docs/en/sourcecraft/security/index.md#src-repositories-admin) role can override the approval rules and perform a forced merge.

{% endnote %}
<!-- endsource: en/_includes/sourcecraft/code-review-bypass.md -->

#### Useful links {#see-also}

* [Getting started with SourceCraft](https://vibe.sourcecraft.dev/portal/docs/en/sourcecraft/quickstart.md)
* [Approval rules in SourceCraft](https://vibe.sourcecraft.dev/portal/docs/en/sourcecraft/concepts/code-review.md)
* [Continuous integration and continuous deployment in SourceCraft](https://vibe.sourcecraft.dev/portal/docs/en/sourcecraft/concepts/ci-cd.md)
* [Configuring CI/CD in a SourceCraft repository](https://vibe.sourcecraft.dev/portal/docs/en/sourcecraft/operations/ci-cd.md)
* [Setting up a branch policy in a SourceCraft repository](https://vibe.sourcecraft.dev/portal/docs/en/sourcecraft/operations/branch-policies.md)
* [Setting up approval rules and branch policies at the organization level in SourceCraft](https://vibe.sourcecraft.dev/portal/docs/en/sourcecraft/operations/org-config.md)
