Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
noahd1 committed Dec 22, 2011
0 parents commit ac5429e
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions code_climate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
import subprocess
import webbrowser
import sublime, sublime_plugin

def git_root(directory):
while directory:
if os.path.exists(os.path.join(directory, '.git')):
return directory
parent = os.path.realpath(os.path.join(directory, os.path.pardir))
if parent == directory:
# /.. == /
return False
directory = parent
return False

def get_repository_path(full_name):
folder_name, file_name = os.path.split(full_name)
return full_name.replace(git_root(folder_name) + "/", '')

def get_remote_repository(full_name):
folder_name, file_name = os.path.split(full_name)

git_command = ["git", "config", "--get", "remote.origin.url"]
os.chdir(folder_name)
popen = subprocess.Popen(git_command, stdout = subprocess.PIPE)
return popen.communicate()[0].strip()

class CodeClimateCommand(sublime_plugin.TextCommand):

def run(self, args):
file_name = self.view.file_name()
url = "https://codeclimate.com/browse?repo=" + get_remote_repository(file_name) + "&path=" + get_repository_path(file_name)
print "Opening URL: " + url
webbrowser.open_new(url)

0 comments on commit ac5429e

Please sign in to comment.