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 58f57ed commit f64806c
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 20 deletions.
4 changes: 0 additions & 4 deletions .ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

set -e -x

bash orgname.sh

mkdir _site public

python activity/scraper.py || true

python manage.py collectstatic --noinput
python manage.py distill-local public --force
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,3 @@ ENV/

_site/
/public/
org_name.txt
10 changes: 5 additions & 5 deletions activity/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import calendar
from dateutil import parser, relativedelta

from community.git import get_remote_owner


class Scraper():
"""
Expand Down Expand Up @@ -129,9 +131,9 @@ def get_data(self):
return self.data


if __name__ == '__main__':
def activity_json(request):

org_name = open('org_name.txt').readline()
org_name = get_remote_owner()

# URL to grab all issues from
issues_url = 'http://' + org_name + '.github.io/gh-board/issues.json'
Expand All @@ -143,6 +145,4 @@ def get_data(self):
real_data = Scraper(parsed_json['issues'], datetime.datetime.today())
real_data = real_data.get_data()

print(real_data)
with open('static' + os.sep + 'activity-data.json', 'w') as fp:
json.dump(real_data, fp)
return json.dumps(real_data)
63 changes: 63 additions & 0 deletions community/git.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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()

print(config.sections())

has_remote = False
branches = []

for key in config.sections():
if key == 'remote "origin"':
return config.items(key)
elif key == 'remote "upstream"':
return config.items(key)
elif key.startswith('remote'):
has_remote = True
elif key.startswith('branch'):
branches.append(config.items(key))

print(branches)

if has_remote:
raise KeyError('No git remote called "origin" or "upstream"')

raise KeyError('No git remotes found')


def get_remote_url():
remote = get_remote()
url = remote[0][1]
try:
url = giturlparse.parse(url)
except:
url = giturlparse.parse(url + '.git')
return url


def get_remote_owner():
url = get_remote_url()
return url.owner
13 changes: 10 additions & 3 deletions community/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.views.generic import TemplateView

from gci.views import index as gci_index
from activity.scraper import activity_json
from twitter.view_twitter import index as twitter_index


Expand All @@ -30,16 +31,22 @@ def get_index():
distill_func=get_index,
distill_file='activity/index.html',
),
distill_url(
r'twitter/', twitter_index,
name='twitter',
distill_func=get_index,
distill_file='twitter/index.html',
),
distill_url(
r'gci/', gci_index,
name='community-gci',
distill_func=get_index,
distill_file='gci/index.html',
),
distill_url(
r'twitter/', twitter_index,
name='twitter',
r'static/activity-data.json', activity_json,
name='activity_json',
distill_func=get_index,
distill_file='twitter/index.html',
distill_file='static/activity-data.json',
),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
6 changes: 0 additions & 6 deletions orgname.sh

This file was deleted.

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_remote_owner()
s.append('<link rel="shortcut icon" type="image/png" '
'href="../static/favicon.png"/>')

Expand Down

0 comments on commit f64806c

Please sign in to comment.