<commit_before>#!/usr/bin/env perl
#############################################################################
##
## Copyright (C) 2015 The Qt Company Ltd.
## Contact: http://www.qt.io/licensing/
##
## This file is part of the Quality Assurance module of the Qt Toolkit.
##
## $QT_BEGIN_LICENSE:LGPL21$
## Commercial License Usage
## Licensees holding valid commercial Qt licenses may use this file in
## accordance with the commercial license agreement provided with the
## Software or, alternatively, in accordance with the terms contained in
## a written agreement between you and The Qt Company. For licensing terms
## and conditions see http://www.qt.io/terms-conditions. For further
## information use the contact form at http://www.qt.io/contact-us.
##
## GNU Lesser General Public License Usage
## Alternatively, this file may be used under the terms of the GNU Lesser
## General Public License version 2.1 or version 3 as published by the Free
## Software Foundation and appearing in the file LICENSE.LGPLv21 and
## LICENSE.LGPLv3 included in the packaging of this file. Please review the
## following information to ensure the GNU Lesser General Public License
## requirements will be met: https://www.gnu.org/licenses/lgpl.html and
## http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
##
## As a special exception, The Qt Company gives you certain additional
## rights. These rights are described in The Qt Company LGPL Exception
## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
##
## $QT_END_LICENSE$
##
#############################################################################

use strict;
use warnings;
use v5.10;

=head1 NAME

testconfig_enforcer - set Qt CI test configurations enforcing when appropriate

=head1 SYNOPSIS

  # from a daily cron job, or similar...
  ./testconfig_enforcer.pl --testconfig-path [path to local qtqa/testconfig]

Check the latest test results on testresults.qt-project.org, cross-reference
with the settings in the testconfig repository, and push a commit removing
any appropriate `forcesuccess' or `*insignificant*' properties.

=head2 OPTIONS

=over

=item --testconfig-path PATH

Path to a local clone of the qtqa/testconfig repository.
This must exist prior to running the script.

=item --no-update

If set, do not attempt to update the local testconfig clone to the newest
version.

=item --dry-run

If set, use `--dry-run' when performing the git push to gerrit; in other words,
the commit is not actually pushed. A `git log' in the local testconfig repository
will show what would have been pushed.

=item --reviewer <reviewer1> [ --reviewer <reviewer2> ... ]

=item -r <reviewer1> [ -r <reviewer2> ... ]

Add the named reviewer(s) to the change in gerrit.
Reviewers may be specified by email address or username.

=item --random

Randomly remove some properties regardless of the test results.

For testing purposes only (i.e. to make it likely that the script will decide
to do something, since the stable state is always that there is nothing to do).

=item --author-only

When creating the git commit, only set the git author field to this script's
identity; don't set the git committer field.

Use this if pushing to gerrit fails due to missing "forge identity" permissions.

=item --man

Show extended documentation (man page).

=back

=head1 DESCRIPTION

When introducing new test configurations into the Qt Project CI system, the
standard practice is to first introduce the configurations in a non-enforcing
mode, then progressively set configurations enforcing for each project as they
are verified passing. The latter can be partially automated by this script,
which performs roughly the following steps:

=over

=item *

updates the qtqa/testconfig repository to the latest version

=item *

enumerates all properties under qtqa/testconfig which represent a non-enforcing
(or partially non-enforcing) test configuration - e.g. forcesuccess, qt.tests.insignificant

=item *

for each non-enforcing test configuration, the latest successful test log is downloaded
from testresults.qt-project.org and scanned; if the log indicates that the test
configuration would pass if it were enforcing, the appropriate files are removed from
the local copy of qtqa/testconfig

=item *

local changes to qtqa/testconfig are committed and pushed to gerrit for review

=back

The script attempts to re-use the same Change-Id for each commit until that commit
is accepted; for example, if run daily and nobody reviews the generated commits
for three days, there will be one change with three patch sets rather than three
changes.

=cut

package QtQA::QtTestconfigEnforcer;

use Const::Fast;
use English qw(-no_match_vars);
use File::Basename;
use File::Find::Rule;
use File::chdir;
use Getopt::Long qw(GetOptionsFromArray);
use LWP::UserAgent::Determined;
use Memoize;
use Pod::Usage;
use Text::Wrap;
use autodie;

use FindBin;
use lib "$FindBin::Bin/../lib/perl5";

use QtQA::Gerrit;

const my $CI_BASE_URL => 'http://testresults.qt-project.org/ci';

const my $BOT_NAME => 'Qt Testconfig Enforcer Bot';

const my @UNDESIRABLES => qw(<commit_msg>Update testenforcer script with new qt.io domain<commit_after>#!/usr/bin/env perl
#############################################################################
##
## Copyright (C) 2015 The Qt Company Ltd.
## Contact: http://www.qt.io/licensing/
##
## This file is part of the Quality Assurance module of the Qt Toolkit.
##
## $QT_BEGIN_LICENSE:LGPL21$
## Commercial License Usage
## Licensees holding valid commercial Qt licenses may use this file in
## accordance with the commercial license agreement provided with the
## Software or, alternatively, in accordance with the terms contained in
## a written agreement between you and The Qt Company. For licensing terms
## and conditions see http://www.qt.io/terms-conditions. For further
## information use the contact form at http://www.qt.io/contact-us.
##
## GNU Lesser General Public License Usage
## Alternatively, this file may be used under the terms of the GNU Lesser
## General Public License version 2.1 or version 3 as published by the Free
## Software Foundation and appearing in the file LICENSE.LGPLv21 and
## LICENSE.LGPLv3 included in the packaging of this file. Please review the
## following information to ensure the GNU Lesser General Public License
## requirements will be met: https://www.gnu.org/licenses/lgpl.html and
## http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
##
## As a special exception, The Qt Company gives you certain additional
## rights. These rights are described in The Qt Company LGPL Exception
## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
##
## $QT_END_LICENSE$
##
#############################################################################

use strict;
use warnings;
use v5.10;

=head1 NAME

testconfig_enforcer - set Qt CI test configurations enforcing when appropriate

=head1 SYNOPSIS

  # from a daily cron job, or similar...
  ./testconfig_enforcer.pl --testconfig-path [path to local qtqa/testconfig]

Check the latest test results on testresults.qt.io, cross-reference
with the settings in the testconfig repository, and push a commit removing
any appropriate `forcesuccess' or `*insignificant*' properties.

=head2 OPTIONS

=over

=item --testconfig-path PATH

Path to a local clone of the qtqa/testconfig repository.
This must exist prior to running the script.

=item --no-update

If set, do not attempt to update the local testconfig clone to the newest
version.

=item --dry-run

If set, use `--dry-run' when performing the git push to gerrit; in other words,
the commit is not actually pushed. A `git log' in the local testconfig repository
will show what would have been pushed.

=item --reviewer <reviewer1> [ --reviewer <reviewer2> ... ]

=item -r <reviewer1> [ -r <reviewer2> ... ]

Add the named reviewer(s) to the change in gerrit.
Reviewers may be specified by email address or username.

=item --random

Randomly remove some properties regardless of the test results.

For testing purposes only (i.e. to make it likely that the script will decide
to do something, since the stable state is always that there is nothing to do).

=item --author-only

When creating the git commit, only set the git author field to this script's
identity; don't set the git committer field.

Use this if pushing to gerrit fails due to missing "forge identity" permissions.

=item --man

Show extended documentation (man page).

=back

=head1 DESCRIPTION

When introducing new test configurations into the Qt Project CI system, the
standard practice is to first introduce the configurations in a non-enforcing
mode, then progressively set configurations enforcing for each project as they
are verified passing. The latter can be partially automated by this script,
which performs roughly the following steps:

=over

=item *

updates the qtqa/testconfig repository to the latest version

=item *

enumerates all properties under qtqa/testconfig which represent a non-enforcing
(or partially non-enforcing) test configuration - e.g. forcesuccess, qt.tests.insignificant

=item *

for each non-enforcing test configuration, the latest successful test log is downloaded
from testresults.qt.io and scanned; if the log indicates that the test
configuration would pass if it were enforcing, the appropriate files are removed from
the local copy of qtqa/testconfig

=item *

local changes to qtqa/testconfig are committed and pushed to gerrit for review

=back

The script attempts to re-use the same Change-Id for each commit until that commit
is accepted; for example, if run daily and nobody reviews the generated commits
for three days, there will be one change with three patch sets rather than three
changes.

=cut

package QtQA::QtTestconfigEnforcer;

use Const::Fast;
use English qw(-no_match_vars);
use File::Basename;
use File::Find::Rule;
use File::chdir;
use Getopt::Long qw(GetOptionsFromArray);
use LWP::UserAgent::Determined;
use Memoize;
use Pod::Usage;
use Text::Wrap;
use autodie;

use FindBin;
use lib "$FindBin::Bin/../lib/perl5";

use QtQA::Gerrit;

const my $CI_BASE_URL => 'http://testresults.qt.io/ci';

const my $BOT_NAME => 'Qt Testconfig Enforcer Bot';

const my @UNDESIRABLES => qw(
{'fraction_non_alphanumeric': 0.1044427123928293, 'fraction_numerical': 0.005455962587685113, 'mean_word_length': 4.637012630422845, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 10, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2350742', 'n_tokens_mistral': 2897, 'n_tokens_neox': 2757, 'n_words': 1329}