aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Vigier <boklm@mageia.org>2013-06-17 14:31:27 +0000
committerNicolas Vigier <boklm@mageia.org>2013-06-17 14:31:27 +0000
commit24aae489c51512f98564d8a44b08051560b7c08e (patch)
tree74c0c12ad87223e50d01002861c46b4d708b7e80
parent78db7e3299de05eb6b720bf594035c7d52f93fbe (diff)
downloadmgaadvisories-24aae489c51512f98564d8a44b08051560b7c08e.tar
mgaadvisories-24aae489c51512f98564d8a44b08051560b7c08e.tar.gz
mgaadvisories-24aae489c51512f98564d8a44b08051560b7c08e.tar.bz2
mgaadvisories-24aae489c51512f98564d8a44b08051560b7c08e.tar.xz
mgaadvisories-24aae489c51512f98564d8a44b08051560b7c08e.zip
Add 'nextid' and 'publish' commands
-rw-r--r--NEWS2
-rw-r--r--config_default5
-rw-r--r--lib/MGA/Advisories.pm23
-rwxr-xr-xmgaadv35
4 files changed, 65 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index b45ef4f..2807504 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,5 @@
+- add 'nextid' and 'publish' commands to assign an ID to an advisory file
+
Version 0.6
- Fix hash which was not dereferenced
diff --git a/config_default b/config_default
index 0b9448b..76cecff 100644
--- a/config_default
+++ b/config_default
@@ -10,3 +10,8 @@ output_format:
out_dir: /var/lib/mga-advisories/out
site_url: http://advisories.mageia.org
advisories_repo_url: svn+ssh://svn.mageia.org/svn/advisories
+advisory_types:
+ bugfix:
+ prefix: MGAA
+ security:
+ prefix: MGASA
diff --git a/lib/MGA/Advisories.pm b/lib/MGA/Advisories.pm
index 848bf24..9601712 100644
--- a/lib/MGA/Advisories.pm
+++ b/lib/MGA/Advisories.pm
@@ -67,6 +67,29 @@ sub get_advisories_from_dir {
return \%advisories;
}
+sub next_id {
+ my $prefix = shift;
+ my $year = DateTime->now->year;
+ my $newid = (0, sort map { m/^$prefix-$year-(\d+)$/ ? int $1 : () } @_)[-1] + 1;
+ return sprintf("%s-%s-%.4d", $prefix, $year, $newid);
+}
+
+sub assign_id {
+ my ($bugnum) = @_;
+ my $advfile = "$config->{advisories_dir}/$bugnum.adv";
+ my $adv = LoadFile($advfile);
+ if ($adv->{ID}) {
+ print STDERR "$bugnum already has an ID assigned: $adv->{ID}\n";
+ return;
+ }
+ $adv->{ID} = next_id($config->{advisory_types}{$adv->{type}}{prefix},
+ keys %{get_advisories_from_dir()});
+ open(my $fh, '>>', $advfile) or die "Error opening $advfile";
+ print $fh "ID: $adv->{ID}\n";
+ close $fh;
+ print "Assigned ID $adv->{ID} to advisory $bugnum\n";
+}
+
sub advdb_dumpfile {
$config->{advdb_dumpfile} || $ENV{HOME} . '/.mga-advisories/advisories.yaml';
}
diff --git a/mgaadv b/mgaadv
index 05308a3..3e6bdc1 100755
--- a/mgaadv
+++ b/mgaadv
@@ -45,6 +45,24 @@ Create a new advisory file. [type] should be security or bugfix and
[bugnum] is the bugzilla bug number.
END
},
+ nextid => {
+ run => \&nextid,
+ descr => 'Print next available ID',
+ usage => <<END,
+$0 nextid [type]
+
+Print the next unused advisory ID for [type].
+END
+ },
+ publish => {
+ run => \&publish,
+ descr => 'Assign an ID to an advisory file',
+ usage => <<END
+$0 publish [bugnum]
+
+Assign a new ID to an advisory file.
+END
+ },
show => {
run => \&showadv,
descr => 'Show an advisory',
@@ -111,6 +129,23 @@ sub newadv {
}
}
+sub nextid {
+ usageexit('usage', $_[0]) unless @_ == 2;
+ my $type = $_[1];
+ if (!$MGA::Advisories::config->{advisory_types}{$type}) {
+ print STDERR "Unknown type $type\n";
+ exit 1;
+ }
+ print MGA::Advisories::next_id(
+ $MGA::Advisories::config->{advisory_types}{$type}{prefix},
+ keys %{MGA::Advisories::get_advisories()}), "\n";
+}
+
+sub publish {
+ usageexit('usage', $_[0]) unless @_ == 2;
+ MGA::Advisories::assign_id($_[1]);
+}
+
sub listadv {
usageexit('usage', $_[0]) unless @_ == 1;
my %advdb;