-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathedit-versions.pl
executable file
·86 lines (78 loc) · 2.33 KB
/
edit-versions.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env perl
use File::Basename qw(dirname);
use Cwd qw(realpath);
use File::Spec::Functions qw(catdir);
BEGIN {
require lib;
my $dir = dirname(realpath(__FILE__));
lib->import(catdir($dir, 'local', 'lib', 'perl5'), catdir($dir, 'lib'));
}
use Mojo::Base -strict, -signatures;
use BMO::Editor;
use BMO::Tool;
use Data::Printer;
use List::Util qw(none);
use Mojo::File qw(path);
use Mojo::JSON qw(decode_json);
use Mojo::URL;
use Mojo::UserAgent;
use Mojo::Util qw(getopt trim slugify html_attr_unescape);
use Set::Object qw(set);
getopt 'product=s' => \my $product,
'urlbase=s' => \$ENV{BMO_URLBASE};
my $tool = BMO::Tool->new;
my $editor = BMO::Editor->new();
my $versions = $tool->get_versions($product);
my ($items, $removed) = $editor->edit('Version', $versions);
my $new = $items->grep('is_new');
my $modified = $items->grep('is_modified');
$new->with_roles('+ProgressBar')->each(
sub ($item, $i) {
my $new = $item->content;
$tool->add_version($product, $new->{value});
unless ($new->{active}) {
$tool->edit_version($product, $new->{value}, sub { $_->{isactive} = 0 });
}
}, 'Add Versions'
);
$modified->with_roles('+ProgressBar')->each(
sub ($item, $i) {
my $old = $versions->[$item->id];
my $new = $item->content;
my %update;
if ($old->{value} ne $new->{value} && $old->{bugs}) {
$tool->add_version($product, $new->{value});
$tool->move_versions($product, $old, $new->{value});
$tool->delete_version($product, $old->{value});
$old->{value} = $new->{value};
$old->{active} = 1;
}
elsif ($old->{value} ne $new->{value}) {
$update{version} = $new->{value};
}
if ($old->{active} xor $new->{active}) {
$update{isactive} = $new->{active};
}
if (keys %update) {
$tool->edit_version(
$product,
$old->{value},
sub($input) {
foreach my $key (keys %update) {
$input->{$key} = $update{$key};
}
}
);
}
}, 'Update Versions'
);
$removed->with_roles('+ProgressBar')->each(
sub ($item, $i) {
if ($item->content->{bugs}) {
warn "Cannot delete ", $item->content->{value}, " because it has bugs";
return;
}
$tool->delete_version($product, $item->content->{value});
}, 'Remove Versions'
);
say "Requests made: ", $tool->browse_counter;