javitolin/codeowners

By javitolin

Updated over 1 year ago

CodeOwners feature for Azure DevOps and RocketChat

Image
0

9

Readme

Purpose

  • Enforce code ownership on different parts of the project
  • Specially helpful for MonoRepo microservice based system

Usage

  1. Create an appsettings.json file with your credentials
    • Tip: You can set the credentials as Environment Variables using .Net format (for example, ado.pat will be set using ado__pat)
  2. run docker compose up

Process

  1. Get all opened PRs
  2. git pull the destination branch
  3. Parse the CODEOWNERS file (from DESTINATION branch)
  4. git pull the source branch
  5. Find changes between source and destination branches
  6. Find code owners for the changes and add them to the PR as revieweres
    • If added, send them a notification

CODEOWNER file

  • Very much like GitHub's CODEOWNER file
  • Should be placed in the root of your repo, file name: CODEOWNERS (can be changed in the settings 'codeowners_filename')
  • You can use "#" for comments
  • Order of the items is important, last one wins
  • Use "*" followed by usernames for "default owners"
CODEOWNER example:
# Default codeowner for the project
* @project_owner

# Specific owner for changes on "service_1/" directory (and everything inside)
service_1/ @service_1_owner

Currently implemented

  • Pull Request source:

    • Azure DevOps
  • Notifications:

    • RocketChat

Settings

  • Can use environment variables to override file 'appsettings.json'

Notifier Message Format

  • Can use any of these:
    • {username}: RocketChat username
    • {pr_url}: PullRequest URL
    • {pr_name}: PullRequest Name
    • {pr_description}: PullRequest Description
    • {pr_id}: PullRequest unique id
    • {pr_reviewers}: List of reviewers, separated by comma
    • {pr_destination_branch}: PullRequest Destionation branch
    • {pr_source_branch}: PullRequest Source branch
    • {pr_repository}: PullRequest repository

Permissions

Azure DevOps
  • Create a PAT (Personal Access Token) with the following permissions:
    • Code: Read & Write
    • Graph: Read
    • Identity: Read
RocketChat
  • Create a user (or use an existing one)
  • Should have at least "user" permission (no need for bot/app)

Contributing

  1. Fork it (https://github.com/javitolin/CodeOwners/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

Meta

Docker Pull Command

docker pull javitolin/codeowners