1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
from django.shortcuts import render
from github import Github
from dotenv import load_dotenv
import os
load_dotenv()
# Create your views here.
def home(request):
g = Github(os.getenv('GH_TOKEN'))
repo = g.get_repo('luciferreeves/thatcomputerscientist')
contents = repo.get_contents('')
files = []
while contents:
file_content = contents.pop(0)
files.append(file_content)
context = {
'title': 'Source Code',
'files': files,
}
return render(request, 'dev_status/home.html', context)
def tree(request, path=None):
g = Github(os.getenv('GH_TOKEN'))
repo = g.get_repo('luciferreeves/thatcomputerscientist')
path = '' if not path else path
parent = '' if len(path.split('/')) == 1 else '/'.join(path.split('/')[:-1])
contents = repo.get_contents(path)
files = []
while contents:
file_content = contents.pop(0)
files.append(file_content)
context = {
'title': 'Tree - {}'.format(path),
'files': files,
'parent': parent,
}
return render(request, 'dev_status/home.html', context)
def raw(request, path):
g = Github(os.getenv('GH_TOKEN'))
repo = g.get_repo('luciferreeves/thatcomputerscientist')
path = '' if not path else path
parent = '' if len(path.split('/')) == 1 else '/'.join(path.split('/')[:-1])
contents = repo.get_contents(path)
context = {
'title': 'File - {}'.format(path),
'file': contents.html_url,
'parent': parent,
}
return render(request, 'dev_status/home.html', context)
|