Skip to content

Instantly share code, notes, and snippets.

@jphastings
Last active May 3, 2018 08:55
Show Gist options
  • Save jphastings/cac3bf8db15966f940f607ee715e64ad to your computer and use it in GitHub Desktop.
Save jphastings/cac3bf8db15966f940f607ee715e64ad to your computer and use it in GitHub Desktop.
Show your codeowners in Sublime Text 3

Codeowners

Github uses a CODEOWNERS file in the root of a repo as a declaration of individuals or teams that should be notified if files are changed.

This is very useful when working on a project with a large number of contributors; but it can be a bit hard to make use of as a human.

This Sublime Text plugin adds a status bar hint to let you know who you might want to talk to about the file you're editing.

Illustration of plugin active in the Status Bar

This is a first-blush attempt at this functionality, so expect problems! To install it, clone this gist into your Plugins:

git clone https://gist.github.com/cac3bf8db15966f940f607ee715e64ad.git "$HOME/Library/Application Support/Sublime Text 3/Packages/codeowners"
import os
import sublime
import sublime_plugin
class ShowCodeownerListener(sublime_plugin.EventListener):
def on_activated(self, view):
codeowners = None
path = view.file_name()
while path != '/':
path = os.path.dirname(path)
check = os.path.join(path, 'CODEOWNERS')
if os.path.isfile(check):
codeowners = check
break
if codeowners is None:
return # We don't use CODEOWNERS in this repo
relative = view.file_name()[len(path):]
owners = []
with open(codeowners, 'r') as f:
for line in f.readlines():
if line.rstrip() == "" or line.startswith('#'):
continue
chunks = line.rstrip().split(' ')
print(chunks)
if relative.startswith(chunks[0]):
owners.extend(chunks[1:])
if len(owners) != 0:
view.set_status("owners", "Owners: " + '; '.join(owners))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment