Fix a few minor issues with the push script (especially UTF-8 compatibility)

This commit is contained in:
Tianon Gravi 2014-09-24 14:31:59 -06:00
parent 1ac6465c73
commit 3e21ed765c
1 changed files with 9 additions and 8 deletions

17
push.pl
View File

@ -1,11 +1,12 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
use strict; use strict;
use warnings; use warnings;
use open ':encoding(utf8)';
use File::Temp; use File::Temp;
use Getopt::Long; use Getopt::Long;
use Mojo::UserAgent; use Mojo::UserAgent;
use Mojo::Util qw(slurp spurt trim); use Mojo::Util qw(decode encode slurp spurt trim);
use Term::ReadKey; use Term::ReadKey;
my $username; my $username;
@ -112,19 +113,19 @@ if ($error->size) {
} }
while (my $repo = shift) { # '/_/hylang', '/u/tianon/perl', etc while (my $repo = shift) { # '/_/hylang', '/u/tianon/perl', etc
$repo =~ s!/+$!!;
$repo = '/_/' . $repo unless $repo =~ m!/!; $repo = '/_/' . $repo unless $repo =~ m!/!;
$repo = '/' . $repo unless $repo =~ m!^/!; $repo = '/' . $repo unless $repo =~ m!^/!;
$repo =~ s!/+$!!;
my $repoName = $repo; my $repoName = $repo;
$repoName =~ s!^.*/!!; # 'hylang', 'perl', etc $repoName =~ s!^.*/!!; # 'hylang', 'perl', etc
my $shortFile = $repoName . '/README-short.txt'; my $shortFile = $repoName . '/README-short.txt';
my $short = slurp $shortFile or die 'missing ' . $shortFile; my $short = slurp $shortFile or warn 'missing ' . $shortFile;
$short = trim $short; $short = trim $short;
my $longFile = $repoName . '/README.md'; my $longFile = $repoName . '/README.md';
my $long = slurp $longFile or die 'missing ' . $longFile; my $long = slurp $longFile or warn 'missing ' . $longFile;
$long = trim $long; $long = trim $long;
my $repoUrl = 'https://registry.hub.docker.com' . $repo . '/settings/'; my $repoUrl = 'https://registry.hub.docker.com' . $repo . '/settings/';
@ -141,17 +142,17 @@ while (my $repo = shift) { # '/_/hylang', '/u/tianon/perl', etc
if ($hubShort ne $short) { if ($hubShort ne $short) {
my $file = File::Temp->new(SUFFIX => '.txt'); my $file = File::Temp->new(SUFFIX => '.txt');
my $filename = $file->filename; my $filename = $file->filename;
spurt $hubShort . "\n", $filename; spurt encode('UTF-8', $hubShort . "\n"), $filename;
system('vimdiff', $filename, $shortFile) == 0 or die "vimdiff on $filename and $shortFile failed"; system('vimdiff', $filename, $shortFile) == 0 or die "vimdiff on $filename and $shortFile failed";
$hubShort = trim(slurp($filename)); $hubShort = trim(decode('UTF-8', slurp($filename)));
} }
if ($hubLong ne $long) { if ($hubLong ne $long) {
my $file = File::Temp->new(SUFFIX => '.md'); my $file = File::Temp->new(SUFFIX => '.md');
my $filename = $file->filename; my $filename = $file->filename;
spurt $hubLong . "\n", $filename; spurt encode('UTF-8', $hubLong . "\n"), $filename;
system('vimdiff', $filename, $longFile) == 0 or die "vimdiff on $filename and $longFile failed"; system('vimdiff', $filename, $longFile) == 0 or die "vimdiff on $filename and $longFile failed";
$hubLong = trim(slurp($filename)); $hubLong = trim(decode('UTF-8', slurp($filename)));
} }
say 'no change to ' . $repoName . '; skipping' and next if $settingsBits->{description} eq $hubShort and $settingsBits->{full_description} eq $hubLong; say 'no change to ' . $repoName . '; skipping' and next if $settingsBits->{description} eq $hubShort and $settingsBits->{full_description} eq $hubLong;