Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support phabricator #10

Merged
merged 2 commits into from
Jan 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions browse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import configparser
import os
import re
import subprocess
import sys
import webbrowser

Expand All @@ -11,6 +12,7 @@
REPOSITORY_REGEX = '(?P<repository>[\w\.@:\/~_-]+)'
GITHUB_SSH_URL = '[email protected]:%s/%s' % (USER_REGEX, REPOSITORY_REGEX)
GITHUB_HTTPS_URL = 'https://github.com/%s/%s' % (USER_REGEX, REPOSITORY_REGEX)
UBER_PHABRICATOR_SSH_URL = '[email protected]'


class GithubHost(object):
Expand Down Expand Up @@ -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,
}


Expand Down Expand Up @@ -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)

Expand Down
15 changes: 15 additions & 0 deletions test_git_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@
TEST_DIR,
'https://github.com/albertyw/git-browse/tree/master/testdir/'
),
(
'[email protected]:a/b',
None,
['arc', 'browse', '.']
),
(
'[email protected]:a/b',
'README.md',
['arc', 'browse', 'README.md']
),
(
'[email protected]:a/b',
TEST_DIR,
['arc', 'browse', TEST_DIR+'/']
)
]


Expand Down