Skip to content

Commit

Permalink
Update logic to extract details from git_config
Browse files Browse the repository at this point in the history
Extract the user & repo (& project for codebasehq) based on the
type of git repository we have as the format in git_config is different
if we're looking at an SSH config or an HTTP one.

The format for non-codebasehq repositories is:
SSH: {example.com}:{user}/{repo}.git
HTTP: {example.com}/{user}/{repo}.git

The codebasehq format is slightly different as we need the project and
the user name is in a different place.
SSH: "codebasehq.com:{user}/{project}/{repo}.git"
HTTP: "{user}.codebasehq.com/{project}/{repo}.git"

Also swap the test for codebasehq to a positive check for clarity.
  • Loading branch information
akrabat committed Jan 6, 2016
1 parent a443626 commit f79db0b
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions GitLink.py
Expand Up @@ -59,11 +59,24 @@ def run(self, edit, **args):

# need to get username from full url

# Get username and repository
if remote_name != 'codebasehq':
source, user, repo = git_config.replace(".git", "").replace("https://", "").split("/")
# Get username and repository (& also project for codebasehq)
if ':' in git_config:
# SSH repository
if remote_name == 'codebasehq':
# format is codebasehq.com:{user}/{project}/{repo}.git
domain, user, project, repo = git_config.replace(".git", "").replace(":", "/").split("/")
else:
# format is {domain}:{user}/{repo}.git
domain, user, repo = git_config.replace(".git", "").replace(":", "/").split("/")
else:
user, project, repo = git_config.replace(".git", "").replace("https://", "").split("/")
# HTTP repository
if remote_name == 'codebasehq':
# format is {user}.codebasehq.com/{project}/{repo}.git
domain, project, repo = git_config.replace(".git", "").split("/")
user = domain.split('.', 1)[0] # user is first segment of domain
else:
# format is {domain}/{user}/{repo}.git
domain, user, repo = git_config.replace(".git", "").split("/")

# Find top level repo in current dir structure
remote_path = self.getoutput("git rev-parse --show-prefix")
Expand All @@ -72,10 +85,10 @@ def run(self, edit, **args):
branch = self.getoutput("git rev-parse --abbrev-ref HEAD")

# Build the URL
if remote_name != 'codebasehq':
url = remote['url'].format(user, repo, branch, remote_path, filename)
else:
if remote_name == 'codebasehq':
url = remote['url'].format(user, project, repo, branch, remote_path, filename)
else:
url = remote['url'].format(user, repo, branch, remote_path, filename)

if(args['line']):
row = self.view.rowcol(self.view.sel()[0].begin())[0] + 1
Expand Down

0 comments on commit f79db0b

Please sign in to comment.