DevSensei | Code Owners for Bitbucket

Can I disable Code Owners globally?

When you install Code Owners for the first time, it will be enabled by default. Any projects/repositories can thus use Code Owners right away. If you prefer to gradually adopt Code Owners within your organization, you can decide to disable Code Owners by default instead and let individual projects and/or repositories enable it when they are ready to use Code Owners.

If you want to disable Code Owners by default, you need to navigate to the Code Owners administration configuration (located at <your instance>/plugins/servlet/codeowners/admin) and toggle the switch in front of the "Code Owners app" to OFF.

Note that enabled Code Owners merge checks will still apply even if you disable Code Owners.

When you disable Code Owners, it will not be disabled on Projects or repositories that already explicitly enables. See this entry to disable them in that case.

How can I disable the Code Owners app on all existing projects?

The Code Owners app has an API to enable or disable the application for a given project.

The following scripts will go through all existing project, and disable the Code Owners app for each of them (including the Apps' auto-merge feature).
Check lines 5 to 12 before you run it.

#!/usr/bin/env bash
# Disable Code Owners app for all Bitbucket DC projects, so that you can opt-in one-by-one.
set -e
# Requires curl and https://stedolan.github.io/jq/
# Admin user with Project admin permission
ADMIN_USER=
# Access token for above user with Project admin permission, see https://confluence.atlassian.com/bitbucketserver/http-access-tokens-939515499.html
ADMIN_ACCESS_TOKEN=
# Your bitbucket domain, e.g https://git.company.com
BITBUCKET_URL=
HTTP_AUTH="curl --user $ADMIN_USER:$ADMIN_ACCESS_TOKEN"
$HTTP_AUTH $BITBUCKET_URL/rest/api/latest/projects\?limit=1 | jq --raw-output '.values[] | .key' > projects.txt
# Code Owners
cat projects.txt | while read -r line ; do $HTTP_AUTH -X PUT $BITBUCKET_URL/rest/codeowners/1.0/projects/$line/settings/app-active/disabled ; done
# Auto-merge
cat projects.txt | while read -r line ; do echo 'false' | $HTTP_AUTH -X PUT $BITBUCKET_URL/rest/codeowners/1.0/app-settings/projects/$line/settings/enable-devsensei ; done
echo "Go to $BITBUCKET_URL/projects and then to corresponding `Project settings -> Code Owners` to enable Code Owners app again in your some of the projects."

This script only disables the app for existing projects. Newly created projects will need to be manually disabled via the settings.