问题描述
我下载了Slack集成提供的SVN提交后示例挂钩.
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";
(此处为完整文件: 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
我已经了解了隔离的(真空)SVN钩子环境,因此我假设我需要在脚本中声明语言环境,但是由于我对Perl不感兴趣,所以我真的不知道如何.
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.
我的提交尝试:
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 $
推荐答案
将以下几行添加到您的钩子中. Slack现在应该可以说捷克语了. :)
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);
这篇关于Perl SVN带有捷克字符的钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!