Skip to content

Commit

Permalink
[fix]
Browse files Browse the repository at this point in the history
  • Loading branch information
boke0 committed Mar 13, 2021
1 parent fef0f0b commit 8ea57ef
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
29 changes: 17 additions & 12 deletions izanami/controller.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from mitama.app import Controller
from mitama.app.http import Response
from mitama.models import User, Group, InnerRole, Node, is_admin
from pathlib import Path
from .model import Repo, Merge, InnerPermission
from .forms import MergeCreateForm, SettingsForm, HookCreateForm
from . import gitHttpBackend
Expand Down Expand Up @@ -160,30 +161,34 @@ def retrieve(self, request):
def blob(self, request):
template = self.view.get_template("repo/blob.html")
repo = Repo.retrieve(name=request.params['repo'])
query = request.query
branch = query.get('branch', 'master')
head = request.params.get('head', 'master')
entity = git.Repo(
self.app.project_dir / 'repos/{}.git'.format(repo.name),
)
head = getattr(
current_head = getattr(
entity.heads,
branch
head
) if hasattr(
entity.heads,
branch
head
) else None
tree = head.commit.tree or None
content = None
for obj in tree:
if obj.name == request.params['object']:
content = obj.data_stream.read().decode("utf-8")
tree = current_head.commit.tree or None
data = tree / request.params['object']
content = (
data.data_stream.read().decode("utf-8")
if isinstance(data, git.objects.blob.Blob)
else None
)
above = Path("/" + request.params['object']) / '../'
print(above.resolve())
return Response.render(template, {
'repo': repo,
'branch': branch,
'head': head,
'current_head': head,
'tree': tree,
'entity': entity,
'name': request.params['object'],
'data': data,
'above': str(above.resolve()),
'content': content
})

Expand Down
2 changes: 1 addition & 1 deletion izanami/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class App(App):
view("/<repo>/update", RepoController, 'update'),
view("/<repo>/delete", RepoController, 'delete'),
view("/<repo>/tree/<head>", RepoController, 'retrieve'),
view("/<repo>/blob/<head>/<object>", RepoController, 'blob'),
view("/<repo>/blob/<head>/<object:path>", RepoController, 'blob'),
view("/<repo>/commit/<commit>", RepoController, 'commit'),
view("/<repo>/log", RepoController, 'log'),
view("/<repo>/log/<head>", RepoController, 'log'),
Expand Down
18 changes: 18 additions & 0 deletions izanami/templates/repo/blob.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<a class='nav-link' href='{{ url('/' + repo.name + '/hook') }}'>フック</a>
</li>
</ul>
{% if content != None %}
<div class='card'>
<div class='card-body'>
<h5 class='card-title'>{{ name }}</h5>
Expand All @@ -22,4 +23,21 @@ <h5 class='card-title'>{{ name }}</h5>
</div>
</div>
</div>
{% else %}
<h5 class='card-title'>{{ name }}/</h5>
<ul>
<li class='list-group-item'>
{% if above == "/" %}
<a href='{{ url('/' + repo.name + '/tree/' + current_head) }}'>../</a>
{% else %}
<a href='{{ url('/' + repo.name + '/blob/' + current_head + '/' + above|string) }}'>../</a>
{% endif %}
</li>
{% for obj in data %}
<li class='list-group-item'>
<a href='{{ url('/' + repo.name + '/blob/' + current_head + '/' + obj.path) }}'>{{ obj.name }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}
4 changes: 0 additions & 4 deletions izanami/templates/repo/retrieve.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@
{% if tree %}
{% for obj in tree %}
<li class='list-group-item'>
{% if isblob(obj) %}
<a href='{{ url('/' + repo.name + '/blob/' + current_head + '/' + obj.name) }}'>{{ obj.name }}</a>
{% else %}
<a href='{{ url('/' + repo.name + '/tree/' + obj.path) }}'>{{ obj.path }}</a>
{% endif %}
</li>
{% endfor %}
{% endif %}
Expand Down

0 comments on commit 8ea57ef

Please sign in to comment.