From d1489df29cba94ddf3a9f6dc6a1f310033a90924 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 11 Feb 2013 10:02:26 +0100 Subject: [PATCH] Loginbildschirm: Unter Versionsnummer auch aktuelle Git-Revisionsnummer anzeigen Conflicts: locale/de/all --- SL/Git.pm | 69 ++++++++++++++++++++++ bin/mozilla/login.pl | 4 ++ locale/de/all | 1 + templates/webpages/login/company_logo.html | 5 +- 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 SL/Git.pm diff --git a/SL/Git.pm b/SL/Git.pm new file mode 100644 index 000000000..a292a78ef --- /dev/null +++ b/SL/Git.pm @@ -0,0 +1,69 @@ +package SL::Git; + +use strict; +use warnings; + +use parent qw(Rose::Object); + +use Carp; +use List::Util qw(first); + +sub is_git_installation { + my ($self) = @_; + + return $self->git_exe && -d ".git" && -f ".git/config" ? 1 : 0; +} + +sub git_exe { + my ($self) = @_; + + return $self->{git_exe} if $self->{_git_exe_search}; + + $self->{_git_exe_search} = 1; + $self->{git_exe} = first { -x } map { "${_}/git" } split m/:/, $ENV{PATH}; + + return $self->{git_exe}; +} + +sub get_log { + my ($self, %params) = @_; + + croak "No git executable found" if !$self->git_exe; + + my $since_until = join '..', $params{since}, $params{until}; + my $in = IO::File->new($self->git_exe . qq! log --format='tformat:\%H|\%an|\%ae|\%ai|\%s' ${since_until} |!); + + if (!$in) { + $::lxdebug->message(LXDebug::WARN(), "Error spawning git: $!"); + return (); + } + + my @log = grep { $_ } map { $self->_parse_log_line($_) } <$in>; + $in->close; + + return @log; +} + +sub _parse_log_line { + my ($self, $line) = @_; + + chomp $line; + + my @fields = split m/\|/, $line, 5; + return undef unless scalar(@fields) == 5; + + my %commit = ( + hash => $fields[0], + author_name => $fields[1], + author_email => $fields[2], + subject => $fields[4], + ); + + if ($fields[3] =~ m/^(\d+)-(\d+)-(\d+)\s+(\d+):(\d+):(\d+)\s+?([\+\-]?\d+)?$/) { + $commit{author_date} = DateTime->new(year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6, time_zone => $7); + } + + return \%commit; +} + +1; diff --git a/bin/mozilla/login.pl b/bin/mozilla/login.pl index e79b6af5f..caf49c44e 100644 --- a/bin/mozilla/login.pl +++ b/bin/mozilla/login.pl @@ -31,6 +31,7 @@ use DBI; use SL::Auth; use SL::User; use SL::Form; +use SL::Git; require "bin/mozilla/common.pl"; require "bin/mozilla/todo.pl"; @@ -51,6 +52,9 @@ sub company_logo { $form->{title} = $::locale->text('kivitendo'); $form->{interface} = $::dispatcher->interface_type; + my $git = SL::Git->new; + ($form->{git_head}) = $git->get_log(since => 'HEAD~1', until => 'HEAD') if $git->is_git_installation; + # create the logo screen $form->header() unless $form->{noheader}; diff --git a/locale/de/all b/locale/de/all index 10942f558..fc689ccd5 100644 --- a/locale/de/all +++ b/locale/de/all @@ -930,6 +930,7 @@ $self->{texts} = { 'General ledger and cash' => 'Finanzbuchhaltung und Zahlungsverkehr', 'General ledger corrections' => 'Korrekturen im Hauptbuch', 'Generic Tax Report' => 'USTVA Bericht', + 'Git revision: #1, #2 #3' => 'Git-Revision: #1, #2 #3', 'Given Name' => 'Vorname', 'Go one step back' => 'Einen Schritt zurück', 'Go one step forward' => 'Einen Schritt vorwärts', diff --git a/templates/webpages/login/company_logo.html b/templates/webpages/login/company_logo.html index 92dc8d242..1939fc3c8 100644 --- a/templates/webpages/login/company_logo.html +++ b/templates/webpages/login/company_logo.html @@ -12,6 +12,10 @@

[% 'kivitendo' | $T8 %] [% version %]

+[%- IF git_head %] +

[%- LxERP.t8("Git revision: #1, #2 #3", git_head.hash.substr(0, 7), git_head.author_date.to_kivitendo, git_head.author_date.strftime('%H:%M:%S %Z')) %]

+[%- END %] +

[% 'companylogo_subtitle' | $T8 %]

@@ -56,4 +60,3 @@ [%- todo_list %] - -- 2.20.1