From b2821c8b67818ef61c51a13826307ddcf1723582 Mon Sep 17 00:00:00 2001 From: Colin Guthrie Date: Wed, 6 Aug 2014 10:04:45 +0100 Subject: Add support for automatically committing advisories after assigning ID. This currently integrates with subversion, but it will be trivial to switch it to git. --- lib/MGA/Advisories.pm | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/lib/MGA/Advisories.pm b/lib/MGA/Advisories.pm index c0f4047..d96c039 100644 --- a/lib/MGA/Advisories.pm +++ b/lib/MGA/Advisories.pm @@ -11,6 +11,7 @@ use Email::Simple::Creator; use LWP::UserAgent; use File::Basename; use XMLRPC::Lite; +use Term::ReadKey; #use Data::Dump qw(dd); our $config_file = '/usr/share/mga-advisories/config'; @@ -167,6 +168,18 @@ sub assign_id { my ($advname) = @_; my $advfile = "$config->{advisories_dir}/$advname.adv"; $advfile =~ s/\.adv\.adv$/.adv/; + + if ( ! -f $advfile ) { + print STDERR "Cannot find advisory file '$advname'\n"; + return; + } + + my $exitstatus = system("svn status -q $advfile | grep -q ^M"); + if ( 0 == $exitstatus ) { + print STDERR "$advname appears to be modified. Please commit it first.\n"; + return; + } + my $adv = LoadFile($advfile); if ($adv->{ID}) { print STDERR "$advname already has an ID assigned: $adv->{ID}\n"; @@ -178,6 +191,9 @@ sub assign_id { return; } + # Turn on autoflush + $|++; + if (!init_bz()) { print STDERR "Warning: Cannot check bugzilla. Please double check manually\n"; } else { @@ -256,12 +272,46 @@ sub assign_id { } } + # TODO: Check SRPMs really exist in the media + printf "%-40s", "Assigning ID to advisory $advname… "; $adv->{ID} = next_id($type, keys %{get_advisories_from_dir()}); open(my $fh, '>>', $advfile) or die "Error opening $advfile"; print $fh "ID: $adv->{ID}\n"; close $fh; print "✔ $adv->{ID}\n"; + + + ReadMode 4; # Turn off controls keys + print "Do you want to publish now? [Y/n]: "; + my $key = 'x'; + while ( $key ne "\n" && $key ne "y" && $key ne "Y" && $key ne "n" && $key ne "N" ) { + $key = ReadKey(0); + } + ReadMode 0; # Reset tty mode before exiting + if ( $key ne "\n" && $key ne "y" && $key ne "Y" ) { + print "$key\n"; + return; + } + print " ✔\n"; + + printf "%-40s", "Publishing advisory $adv->{ID}… "; + my $message = $adv->{ID}; + my @pkgs; + foreach my $rel (keys %{$adv->{src}}) { + foreach my $media (keys %{$adv->{src}{$rel}}) { + foreach my $srpm (@{$adv->{src}{$rel}{$media}}) { + push @pkgs, $srpm; + } + } + } + $message .= ': '.join(', ', @pkgs); + $exitstatus = system(('svn', 'commit', '-q', '-m', $message, $advfile)); + if (0 == $exitstatus) { + print "✔\n"; + } else { + print "✘\n"; + } } sub advdb_dumpfile { -- cgit v1.2.1