aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorColin Guthrie <colin@mageia.org>2014-08-06 10:04:45 +0100
committerColin Guthrie <colin@mageia.org>2014-08-06 10:04:45 +0100
commitb2821c8b67818ef61c51a13826307ddcf1723582 (patch)
tree2329416040f0bc8f733d83d98d658d609bb6ae50 /lib
parent9ae0647d09880f32529750509bfeeee31ce578e0 (diff)
downloadmgaadvisories-b2821c8b67818ef61c51a13826307ddcf1723582.tar
mgaadvisories-b2821c8b67818ef61c51a13826307ddcf1723582.tar.gz
mgaadvisories-b2821c8b67818ef61c51a13826307ddcf1723582.tar.bz2
mgaadvisories-b2821c8b67818ef61c51a13826307ddcf1723582.tar.xz
mgaadvisories-b2821c8b67818ef61c51a13826307ddcf1723582.zip
Add support for automatically committing advisories after assigning ID.
This currently integrates with subversion, but it will be trivial to switch it to git.
Diffstat (limited to 'lib')
-rw-r--r--lib/MGA/Advisories.pm50
1 files changed, 50 insertions, 0 deletions
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 {