Skip to content

Commit

Permalink
Merge pull request docker-library#49 from infosiftr/script-bugs
Browse files Browse the repository at this point in the history
Fix a few minor issues with the push script (especially UTF-8 compatibility)
  • Loading branch information
yosifkit committed Sep 24, 2014
2 parents 785c744 + 3e21ed7 commit c8f5fc0
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions push.pl
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/perl -w
use strict;
use warnings;
use open ':encoding(utf8)';

use File::Temp;
use Getopt::Long;
use Mojo::UserAgent;
use Mojo::Util qw(slurp spurt trim);
use Mojo::Util qw(decode encode slurp spurt trim);
use Term::ReadKey;

my $username;
Expand Down Expand Up @@ -112,19 +113,19 @@ sub get_form_bits {
}

while (my $repo = shift) { # '/_/hylang', '/u/tianon/perl', etc
$repo =~ s!/+$!!;
$repo = '/_/' . $repo unless $repo =~ m!/!;
$repo = '/' . $repo unless $repo =~ m!^/!;
$repo =~ s!/+$!!;

my $repoName = $repo;
$repoName =~ s!^.*/!!; # 'hylang', 'perl', etc

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;

my $longFile = $repoName . '/README.md';
my $long = slurp $longFile or die 'missing ' . $longFile;
my $long = slurp $longFile or warn 'missing ' . $longFile;
$long = trim $long;

my $repoUrl = 'https://registry.hub.docker.com' . $repo . '/settings/';
Expand All @@ -141,17 +142,17 @@ sub get_form_bits {
if ($hubShort ne $short) {
my $file = File::Temp->new(SUFFIX => '.txt');
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";
$hubShort = trim(slurp($filename));
$hubShort = trim(decode('UTF-8', slurp($filename)));
}

if ($hubLong ne $long) {
my $file = File::Temp->new(SUFFIX => '.md');
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";
$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;
Expand Down

0 comments on commit c8f5fc0

Please sign in to comment.