aboutsummaryrefslogtreecommitdiffstats
path: root/lib/MGA
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 /lib/MGA
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
Diffstat (limited to 'lib/MGA')
-rw-r--r--lib/MGA/Advisories.pm23
1 files changed, 23 insertions, 0 deletions
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';
}