Skip to content

Commit

Permalink
Bug 1877294 - When adding a new version and mileston when new Firefox…
Browse files Browse the repository at this point in the history
… is released, disabled old versions and milestones 10 releases or older
  • Loading branch information
dklawren committed Feb 1, 2024
1 parent c3f0082 commit e60eb21
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 13 deletions.
88 changes: 77 additions & 11 deletions Bugzilla/App/BMO/NewRelease.pm
Expand Up @@ -63,6 +63,7 @@ sub new_release {

my $vars = {
next_release => $current_nightly + 1,
old_release => $current_nightly - 10,
selectable_products => $selectable_products,
default_milestone_products => $default_milestone_products,
default_version_products => $default_version_products,
Expand All @@ -80,37 +81,72 @@ sub new_release {

# Sanity check new values for milestone and version
my $new_milestone = trim($self->param('new_milestone'));
my $old_milestone = trim($self->param('old_milestone'));
my $new_version = trim($self->param('new_version'));
my $old_version = trim($self->param('old_version'));

$new_milestone =~ /^\d+$/
|| return $self->user_error("number_not_numeric",
{field => 'milestone', num => $new_milestone});
|| return $self->user_error('number_not_numeric',
{field => 'new_milestone', num => $new_milestone});
$new_version =~ /^\d+$/
|| return $self->user_error("number_not_numeric",
{field => 'version', num => $new_version});
|| return $self->user_error('number_not_numeric',
{field => 'new_version', num => $new_version});

if ($old_milestone && $old_milestone !~ /^\d+$/) {
return $self->user_error('number_not_numeric',
{field => 'old_milestone', num => $old_milestone});
}

if ($old_version && $old_version !~ /^\d+$/) {
return $self->user_error('number_not_numeric',
{field => 'old_version', num => $old_version});
}

# Process milestones
my @results;
foreach my $product (@{$self->every_param('milestone_products')}) {
my $success = _add_value($product, $new_milestone, 'milestone');
my $result = {
type => 'milestone',
type => 'new_milestone',
product => $product,
value => _get_formatted_value($product, $new_milestone, 'milestone'),
success => $success
};
push @results, $result;

if ($old_milestone) {
$success = _disable_value($product, $old_milestone, 'milestone');
$result = {
type => 'old_milestone',
product => $product,
value => _get_formatted_value($product, $old_milestone, 'milestone'),
success => $success
};
push @results, $result;
}
}

# Process versions
foreach my $product (@{$self->every_param('version_products')}) {
my $success = _add_value($product, $new_version, 'version');
my $result = {
type => 'version',
type => 'new_version',
product => $product,
value => _get_formatted_value($product, $new_version, 'version'),
success => $success
};
push @results, $result;

if ($old_version) {
$success = _disable_value($product, $old_version, 'version');
$result = {
type => 'old_version',
product => $product,
value => _get_formatted_value($product, $old_version, 'version'),
success => $success
};
push @results, $result;
}
}

$self->stash({results => \@results});
Expand Down Expand Up @@ -150,9 +186,6 @@ sub _add_value {
{product => $product, value => $new_milestone, sortkey => $sortkey});
return $new_milestone;
}
else {
return 0;
}
}

# Versions are simple in that they do not use sortkeys yet
Expand All @@ -162,10 +195,43 @@ sub _add_value {
Bugzilla::Version->create({product => $product, value => $new_version});
return $new_version;
}
else {
return 0;
}

return 0;
}

sub _disable_value {
my ($product, $value, $type) = @_;
$product
= blessed $product
? $product
: Bugzilla::Product->new({name => $product, cache => 1});

if ($type eq 'milestone') {
my $old_milestone = _get_formatted_value($product->name, $value, 'milestone');

if (my $milestone_obj
= Bugzilla::Milestone->new({product => $product, name => $old_milestone}))
{
$milestone_obj->set_is_active(0);
$milestone_obj->update();
return 1;
}
}

# Versions are simple in that they do not use sortkeys yet
if ($type eq 'version') {
my $old_version = _get_formatted_value($product->name, $value, 'version');
if (my $version_obj
= Bugzilla::Version->new({product => $product, name => $old_version}))
{
$version_obj->set_is_active(0);
$version_obj->update();
return 1;
}
}

return 0;
}

# Helper function to return a fully formatted version or milestone
Expand Down
7 changes: 7 additions & 0 deletions qa/t/3_test_new_release.t
Expand Up @@ -52,9 +52,16 @@ $sel->click_ok('link=New Firefox Release');
$sel->wait_for_page_to_load_ok(WAIT_TIME);
$sel->select_ok('milestone_products', 'label=Firefox');
$sel->type_ok('new_milestone', '101');
$sel->type_ok('old_milestone', '100');
$sel->select_ok('version_products', 'label=Firefox');
$sel->type_ok('new_version', '101');
$sel->type_ok('old_version', '100');
$sel->click_ok('submit', undef, 'Submit data');
$sel->title_is('New Firefox Release');
$sel->is_text_present_ok('Milestone 101 Branch was added to product Firefox.');
$sel->is_text_present_ok('Milestone 100 Branch was disabled for product Firefox.');
$sel->is_text_present_ok('Version Firefox 101 was added to product Firefox.');
$sel->is_text_present_ok('Version Firefox 100 was disabled for product Firefox.');

# Verify that the new milestone and version has been create and the proper sortkey is present

Expand Down
33 changes: 31 additions & 2 deletions template/en/default/pages/new_release.html.tmpl
Expand Up @@ -17,17 +17,30 @@
[% IF results %]
[% FOREACH type = ['milestone', 'version'] %]
<p><h4>[% type FILTER ucfirst FILTER html %]s Added</h4>
[% new_type = "new_" _ type %]
[% FOREACH result = results %]
[% NEXT IF result.type != type %]
[% NEXT IF result.type != new_type %]
[% IF result.success %]
[% type FILTER ucfirst FILTER html %] <strong>[% result.value FILTER html %]</strong>
added to product <strong>[% result.product FILTER html %]</strong>.<br>
was added to product <strong>[% result.product FILTER html %]</strong>.<br>
[% ELSE %]
<span style="color:red;">[% type FILTER ucfirst FILTER html %] <strong>[% result.value FILTER html %]</strong>
was not added to product <strong>[% result.product FILTER html %]</strong>.</span><br>
[% END %]
[% END %]
</p>
<p><h4>[% type FILTER ucfirst FILTER html %]s Disabled</h4>
[% old_type = "old_" _ type %]
[% FOREACH result = results %]
[% NEXT IF result.type != old_type %]
[% IF result.success %]
[% type FILTER ucfirst FILTER html %] <strong>[% result.value FILTER html %]</strong>
was disabled for product <strong>[% result.product FILTER html %]</strong>.<br>
[% ELSE %]
<span style="color:red;">[% type FILTER ucfirst FILTER html %] <strong>[% result.value FILTER html %]</strong>
was not disabled for product <strong>[% result.product FILTER html %]</strong>.</span><br>
[% END %]
[% END %]
[% END %]

[% INCLUDE global/footer.html.tmpl %]
Expand Down Expand Up @@ -65,6 +78,14 @@
Milestone will be added in the format of "XXX Branch"
</td>
</tr>
<tr>
<td>Disable Old Milestone</td>
<td>
<input type="text" name="old_milestone" id="old_milestone" required="true"
size="12" value="[% old_release FILTER html %]">
Leave blank to not disable old milestone
</td>
</tr>
</table>

<h4>Select Products for New Version</h4>
Expand All @@ -91,6 +112,14 @@
Version will be added in the format of "Firefox XXX"
</td>
</tr>
<tr>
<td>Disable Old Version</td>
<td>
<input type="text" name="old_version" id="old_version" required="true"
size="10" value="[% old_release FILTER html %]">
Leave blank to not disable old version
</td>
</tr>
</table>
<br>
<input type="submit" id="submit" value="Submit">
Expand Down

0 comments on commit e60eb21

Please sign in to comment.