Setting up approval rules in a SourceCraft repository

With SourceCraft, you can flexibly set up mandatory approval rules before any code can be added to the target branch of the repository.

For more information, see Approval rules in SourceCraft.

You specify the approval rule configuration for a particular repository and store it in the .sourcecraft/review.yaml file.

Warning

Support for storing configurations for CI/CD, approval rules, and branch policies in a single .src.ci.yaml file at the repository root will soon be discontinued. Use the separate .sourcecraft/ci.yaml, .sourcecraft/review.yaml, and .sourcecraft/branches.yaml files.

See the templates repository in SourceCraft for the full specification of the .sourcecraft/review.yaml file.

To set up approval rules in a repository:

  1. Clone the repository:

    1. Install Git.

    2. Open the SourceCraft home page.

    3. On the Home tab, navigate to Repositories and select a repository.

    4. In the top-right corner, click Clone.

    5. Depending on your connection method, copy the link for cloning the repository.

    6. In the terminal, run this command:

      git clone <link_for_cloning_repository>
      
    7. Go to your cloned repository:

      cd <repository_name>
      
  2. Generate an approval rule configuration file named .sourcecraft/review.yaml, e.g.:

    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
      rules:
        - patterns:
            - '*'
          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
    

    See the templates repository in SourceCraft for the full specification of the .sourcecraft/review.yaml file.

  3. Under usernames, list the users the pool request must feature at least one approval from.

  4. Add the approval rule configuration file to the git index, commit, and push the changes to the main branch:

    git add .sourcecraft/review.yaml
    git commit -m "Added code review configuration"
    git push -u origin main
    
  5. Make sure that the approval rules were applied:

    1. Create a test pull request.

    2. Make sure that in the pool request you created:

      • The 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.
    3. Wait for the pull request to be approved.

    4. To merge with the main branch, click Merge.

      The merging can be done only by users with the Repository developer role or higher.

Warning

Only users with the Repository maintainer or Repository admin role can override the approval rules and perform a forced merge.

See also