Perl SVN钩与捷克字符

时间:2015-10-15 19:13:41

标签: perl svn svn-hooks slack

我下载了Slack集成提供的示例SVN post-commit钩子。

header('Content-Type: application/json');
echo json_encode($dataarray);

(完整档案:https://github.com/tinyspeck/services-examples/blob/master/subversion.pl

现在问题是,如果我想提交包含特殊字符(捷克语)的消息,则字符串无法正常转换,并且松弛通道中生成的消息如下所示:

#!/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";

我已经阅读过关于隔离(真空)SVN钩子环境的内容,所以我假设我需要在脚本中声明语言环境,但由于我没有被Perl触及,我真的不知道如何。

我的提交尝试:

25: falnyr - ÅeÅicha
c59865c5996963686120746573746f766163c3ad20636f6d6d69740a

1 个答案:

答案 0 :(得分:1)

将以下行添加到您的钩子中。 Slack现在应该能够和捷克人交谈了。 :)

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);