Display branch name in footer when not in master branch.

This commit is contained in:
flash 2019-04-10 11:31:24 +02:00
parent 173a538200
commit 031675e3b0
4 changed files with 18 additions and 2 deletions

View file

@ -37,6 +37,7 @@ final class TwigMisuzu extends Twig_Extension
new Twig_Function('get_browser', 'get_browser'),
new Twig_Function('git_commit_hash', 'git_commit_hash'),
new Twig_Function('git_tag', 'git_tag'),
new Twig_Function('git_branch', 'git_branch'),
new Twig_Function('csrf_token', 'csrf_token'),
new Twig_Function('csrf_input', 'csrf_html'),
new Twig_Function('sql_query_count', 'db_query_count'),

View file

@ -13,6 +13,11 @@ function git_commit_hash(bool $long = false): string
return git_commit_info($long ? MSZ_GIT_FORMAT_HASH_LONG : MSZ_GIT_FORMAT_HASH_SHORT);
}
function git_branch(): string
{
return trim(shell_exec('git rev-parse --abbrev-ref HEAD'));
}
function git_tag(): string
{
return trim(shell_exec('git describe --abbrev=0 --tags'));

View file

@ -2,11 +2,16 @@
<div class="footer__background"></div>
<div class="footer__wrapper">
{% autoescape false %}
{% set git_tag = git_tag() %}
{% set git_branch = git_branch() %}
<div class="footer__copyright">
{{ 'https://flash.moe'|html_link('Flashwave', 'footer__link') }} 2013-{{
''|date('Y') }} /
{{ ('https://github.com/flashwave/misuzu/tree/' ~ git_tag())|html_link(git_tag(), 'footer__link') }}
{{ ('https://github.com/flashwave/misuzu/tree/' ~ git_tag)|html_link(git_tag, 'footer__link') }}
# {{ ('https://github.com/flashwave/misuzu/commit/' ~ git_commit_hash(true))|html_link(git_commit_hash(), 'footer__link') }}
{% if git_branch != 'master' %}
({{ ('https://github.com/flashwave/misuzu/tree/' ~ git_branch)|html_link(git_branch, 'footer__link') }})
{% endif %}
{% if constant('MSZ_DEBUG') or current_user.user_id|default(0) == 1 %}
/ SQL Queries: {{ sql_query_count()|number_format }}
/ Took: {{ startup_time()|number_format(5) }} seconds

View file

@ -37,11 +37,16 @@
<div class="footer__background"></div>
<div class="footer__wrapper">
{% autoescape false %}
{% set git_tag = git_tag() %}
{% set git_branch = git_branch() %}
<div class="footer__copyright">
{{ 'https://flash.moe'|html_link('Flashwave', 'footer__link') }} 2013-{{
''|date('Y') }} /
{{ ('https://github.com/flashwave/misuzu/tree/' ~ git_tag())|html_link(git_tag(), 'footer__link') }}
{{ ('https://github.com/flashwave/misuzu/tree/' ~ git_tag)|html_link(git_tag, 'footer__link') }}
# {{ ('https://github.com/flashwave/misuzu/commit/' ~ git_commit_hash(true))|html_link(git_commit_hash(), 'footer__link') }}
{% if git_branch != 'master' %}
({{ ('https://github.com/flashwave/misuzu/tree/' ~ git_branch)|html_link(git_branch, 'footer__link') }})
{% endif %}
</div>
{% endautoescape %}
</div>