Skip to content

Commit

Permalink
community/git: Obtain org name from git remote
Browse files Browse the repository at this point in the history
Closes coala#26
  • Loading branch information
jayvdb committed Dec 14, 2017
1 parent 10d6753 commit c1de365
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
46 changes: 46 additions & 0 deletions community/git.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os.path

from git.config import GitConfigParser
import giturlparse

REPO_DIR = os.path.join(
os.path.dirname(__file__),
'..',
)
GIT_CONFIG = os.path.join(
REPO_DIR,
'.git',
'config',
)

_config = None


def get_config():
global _config
if not _config:
_config = GitConfigParser(GIT_CONFIG)
return _config

def get_remote():
config = get_config()

for key in config.sections():
if key == 'remote "origin"':
return config.items(key)
if key == 'remote "upstream"':
return config.items(key)
else:
raise KeyError


def get_remote_url():
remote = get_remote()
url = remote[0][1]
url = giturlparse.parse(url)
return url


def get_remote_owner():
url = get_remote_url()
return url.owner
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
gitconfigparser
git-url-parse
django<2.0
django-distill
IGitt
Expand Down
4 changes: 3 additions & 1 deletion twitter/view_twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import requests
import json

from community.git import get_remote_owner


def index(request):
s = []

org_name = open('org_name.txt', 'r').read().strip()
org_name = get_owner()
s.append('<link rel="shortcut icon" type="image/png" '
'href="../static/favicon.png"/>')

Expand Down

0 comments on commit c1de365

Please sign in to comment.