I downloaded the sample SVN post-commit hook provided by Slack integration.
#!/usr/bin/perl
use warnings;
use strict;
use HTTP::Request::Common qw(POST);
use HTTP::Status qw(is_client_error);
use LWP::UserAgent;
use JSON;
my $repository = "myrepo";
my $websvn = "websvn.mydomain.com";
my $opt_domain = "myteam.slack.com";
my $opt_token = "mytoken";
my $log = qx|export LC_ALL="cs_CZ.UTF-8"; /usr/bin/svnlook log -r $ARGV[1] $ARGV[0]|;
my $log = $log." ".unpack('H*',$log);
my $who = `/usr/bin/svnlook author -r $ARGV[1] $ARGV[0]`;
my $url = "http://${websvn}/revision.php?repname=${repository}&rev=$ARGV[1]";
chomp $who;
my $payload = {
'revision' => $ARGV[1],
'url' => $url,
'author' => $who,
'log' => $log,
};
my $ua = LWP::UserAgent->new;
$ua->timeout(15);
my $req = POST( "https://${opt_domain}/services/hooks/subversion?token=${opt_token}", ['payload' => encode_json($payload)] );
my $s = $req->as_string;
print STDERR "Request:\n$s\n";
my $resp = $ua->request($req);
$s = $resp->as_string;
print STDERR "Response:\n$s\n";
(full file here: https://github.com/tinyspeck/services-examples/blob/master/subversion.pl)
Now the problem is, that if I want to commit message containing special characters (Czech), the string is unable to translate properly and the resulting message in slack channel looks like this:
25: falnyr - ÅeÅicha
c59865c5996963686120746573746f766163c3ad20636f6d6d69740a
I have read about the isolated (vacuum) SVN hook environment, so I assume I need to declare the locale inside the script, but since I am untouched by Perl, I really don`t know how.
My commit attempt:
falnyr@cap:test $ export LC_ALL="cs_CZ.UTF-8"
falnyr@cap:test $ touch file.txt
falnyr@cap:test $ svn add file.txt
A file.txt
falnyr@cap:test $ svn commit -m "Řeřicha"
Store password unencrypted (yes/no)? no
Adding file.txt
Transmitting file data .
Committed revision x.
falnyr@cap:test $
Add the following lines to your hook. Slack should now be able to talk Czech. :)
use Encode qw(decode_utf8);
...
my $log = qx|export LC_ALL="cs_CZ.UTF-8"; /usr/bin/svnlook log -r $ARGV[1] $ARGV[0]|;
$log = decode_utf8($log);
来源:https://stackoverflow.com/questions/33156655/perl-svn-hook-with-czech-characters