diff --git a/browse.py b/browse.py index 8c4d115..2b1b964 100755 --- a/browse.py +++ b/browse.py @@ -3,6 +3,7 @@ import configparser import os import re +import subprocess import sys import webbrowser @@ -11,6 +12,7 @@ REPOSITORY_REGEX = '(?P[\w\.@:\/~_-]+)' GITHUB_SSH_URL = 'git@github.com:%s/%s' % (USER_REGEX, REPOSITORY_REGEX) GITHUB_HTTPS_URL = 'https://github.com/%s/%s' % (USER_REGEX, REPOSITORY_REGEX) +UBER_PHABRICATOR_SSH_URL = 'gitolite@code.uber.internal' class GithubHost(object): @@ -58,9 +60,29 @@ def file_url(self, repository_url, focus_object): return repository_url +class UberPhabricatorHost(object): + def __init__(self, user, repository): + pass + + @staticmethod + def create(url_regex_match): + return UberPhabricatorHost(None, None) + + def get_url(self, focus_object): + path = focus_object.path + # arc browse requires an object, provide the root object by default + if focus_object.is_root(): + path = '.' + command = ['arc', 'browse'] + if path: + command.append(path) + return command + + HOST_REGEXES = { GITHUB_SSH_URL: GithubHost, GITHUB_HTTPS_URL: GithubHost, + UBER_PHABRICATOR_SSH_URL: UberPhabricatorHost, } @@ -156,6 +178,9 @@ def get_focus_object(sys_argv, path): def open_url(url): print(url) + if url.__class__ is list: + subprocess.call(url) + return if sys.platform == 'darwin': webbrowser.open(url) diff --git a/test_git_urls.py b/test_git_urls.py index 1d175f4..515338e 100644 --- a/test_git_urls.py +++ b/test_git_urls.py @@ -48,6 +48,21 @@ TEST_DIR, 'https://github.com/albertyw/git-browse/tree/master/testdir/' ), + ( + 'gitolite@code.uber.internal:a/b', + None, + ['arc', 'browse', '.'] + ), + ( + 'gitolite@code.uber.internal:a/b', + 'README.md', + ['arc', 'browse', 'README.md'] + ), + ( + 'gitolite@code.uber.internal:a/b', + TEST_DIR, + ['arc', 'browse', TEST_DIR+'/'] + ) ]