我下载了 Slack 集成提供的示例 SVN 提交后挂钩。
#!/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";
(此处的完整文件:https ://github.com/tinyspeck/services-examples/blob/master/subversion.pl )
现在的问题是,如果我想提交包含特殊字符(捷克语)的消息,则字符串无法正确翻译,并且松弛通道中的结果消息如下所示:
25: falnyr - ÅeÅicha
c59865c5996963686120746573746f766163c3ad20636f6d6d69740a
我已经阅读了有关隔离(真空)SVN 钩子环境的信息,所以我假设我需要在脚本中声明语言环境,但是由于我没有被 Perl 触及,我真的不知道如何。
我的提交尝试:
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 $