Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions codeowner2infection-filter.pl
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

use GPH::Gitlab;

use constant CODEOWNERS_FILE => './CODEOWNERS';
my $owner = $ENV{'DEV_TEAM'} or die "please define owner in DEV_TEAM env var";
my @excludes = split /,/, ($ENV{'EXCLUDE_PATHS'} || '');

my $owner = $ENV{'DEV_TEAM'} or die "please define owner in DEV_TEAM env var";
my %config = (
owner => $owner,
codeowners => './CODEOWNERS',
excludes => @excludes
);

my $paths = $ENV{'EXCLUDE_PATHS'} || '';
my @excludes = split /,/, $paths;

my $gitlab = GPH::Gitlab->new(CODEOWNERS_FILE, $owner, @excludes);
my $gitlab = GPH::Gitlab->new(%config);

print $gitlab->getCommaSeparatedPathList();
2 changes: 1 addition & 1 deletion codeowner2phpmd.pl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
my $owner = $ENV{'DEV_TEAM'} or die "please define owner in DEV_TEAM env var";
my $cycloLevel = $ENV{'CYCLO_LEVEL'} || 10;

my $phpmd = GPH::PHPMD->new($owner, $cycloLevel);
my $phpmd = GPH::PHPMD->new((owner => $owner, cyclo_level => $cycloLevel));

print $phpmd->getConfig();
29 changes: 15 additions & 14 deletions codeowner2phpstan.pl
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,25 @@
use constant CODEOWNERS_FILE => './CODEOWNERS';

my $owner = $ENV{'DEV_TEAM'} or die "please define owner in DEV_TEAM env var";
my @excludes = split /,/, ($ENV{'EXCLUDE_PATHS'} || '');

my $exclude = $ENV{'EXCLUDE_PATHS'} || '';
my @excludes = split /,/, $exclude;
my $gitlab = GPH::Gitlab->new((owner => $owner, codeowners => './CODEOWNERS', excludes => @excludes));

my $level = $ENV{'PHPSTAN_LEVEL'} || 6;
my $baseline = $ENV{'PHPSTAN_BASELINE'} || undef;
my $cacheDir = $ENV{'PHPSTAN_CACHE_DIR'} || undef;
my $ignore = $ENV{'PHPSTAN_IGNORED_DIRS'} || '';
my @ignored = split /,/, $ignore;
my $includes = $ENV{'PHPSTAN_INCLUDES'} || './phpstan.ci.neon';
my @includes = split /,/, $includes;
my $threads = $ENV{'PHPSTAN_THREADS'} || undef;
my @includes = split /,/, ($ENV{'PHPSTAN_INCLUDES'} || './phpstan.ci.neon');
my @ignored = split /,/, ($ENV{'PHPSTAN_IGNORED_DIRS'} || '');

my $gitlab = GPH::Gitlab->new(CODEOWNERS_FILE, $owner, @excludes);
@ignored = (@ignored, $gitlab->getBlacklistPaths()); # merge ignored dirs with blacklist

# merge ignored dirs with blacklist
@ignored = (@ignored, $gitlab->getBlacklistPaths());
my %config = (
level => $ENV{'PHPSTAN_LEVEL'} || 6,
paths => \$gitlab->getPaths(),
baseline => $ENV{'PHPSTAN_BASELINE'},
ignoredDirectories => \@ignored,
cacheDir => $ENV{'PHPSTAN_CACHE_DIR'},
includes => \@includes,
threads => $ENV{'PHPSTAN_THREADS'}
);

my $phpstan = GPH::PHPStan->new($level, $gitlab->getPathsReference(), $baseline, \@ignored, $cacheDir, \@includes, $threads);
my $phpstan = GPH::PHPStan->new(%config);

print $phpstan->getConfig();
39 changes: 20 additions & 19 deletions codeowner2psalm.pl
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,37 @@
use GPH::Gitlab;
use GPH::Psalm;

use constant CODEOWNERS_FILE => './CODEOWNERS';
use constant PSALM_CONFIG => './psalm.xml';

my $owner = $ENV{'DEV_TEAM'} or die "please define owner in DEV_TEAM env var";
my $owner = $ENV{'DEV_TEAM'} or die "please define owner in DEV_TEAM env var";
my @excludes = split /,/, ($ENV{'EXCLUDE_PATHS'} || '');

my $exclude = $ENV{'EXCLUDE_PATHS'} || '';
my @excludes = split /,/, $exclude;
my $gitlab = GPH::Gitlab->new((owner => $owner, codeowners => './CODEOWNERS', excludes => @excludes));

my $level = $ENV{'PSALM_LEVEL'} || 4;
my $baseline = $ENV{'PSALM_BASELINE'} || undef;
my $baselineCheck = $ENV{'PSALM_BASELINE_CHECK'} || undef;
my $cacheDir = $ENV{'PSALM_CACHE_DIR'} || undef;
my $ignore = $ENV{'PSALM_IGNORED_DIRS'} || '';
my @ignored = split /,/, $ignore;
my $plugin = $ENV{'PSALM_PLUGINS'} || '';
my @plugins = split /,/, $plugin;
my @ignored = split /,/, ($ENV{'PSALM_IGNORED_DIRS'} || '');
my @plugins = split /,/, ($ENV{'PSALM_PLUGINS'} || '');
my $clone = defined($ENV{'PSALM_CLONE_HANDLERS'}) ? $ENV{'PSALM_CLONE_HANDLERS'} : 1;

my $gitlab = GPH::Gitlab->new(CODEOWNERS_FILE, $owner, @excludes);

# merge ignored dirs with blacklist
@ignored = (@ignored, $gitlab->getBlacklistPaths());

my $psalm = GPH::Psalm->new($level, $gitlab->getPathsReference(), $baseline, $baselineCheck, \@ignored, $cacheDir, \@plugins);
my %config = (
level => $ENV{'PSALM_LEVEL'} || 4,
paths => \$gitlab->getPaths(),
ignoredDirectories => \@ignored,
baseline => $ENV{'PSALM_BASELINE'},
baselineCheck => $ENV{'PSALM_BASELINE_CHECK'},
cacheDir => $ENV{'PSALM_CACHE_DIR'},
plugins => \@plugins,
);

my $psalm = GPH::Psalm->new(%config);

if ($clone) {
my $excludeHandlers = $ENV{'PSALM_EXCLUDE_HANDLERS'} || '';
my @blacklist = split /,/, $excludeHandlers;
if ($clone eq 1) {
my @blacklist = split /,/, ($ENV{'PSALM_EXCLUDE_HANDLERS'} || '');

print $psalm->getConfigWithIssueHandlers(PSALM_CONFIG, @blacklist);
} else {
}
else {
print $psalm->getConfig();
}
23 changes: 11 additions & 12 deletions coverage2codeowner.pl
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@

use GPH::PHPUnit;

use constant CLASSMAP_FILE => './vendor/composer/autoload_classmap.php';
use constant CODEOWNERS_FILE => './CODEOWNERS';

my $owner = $ENV{'DEV_TEAM'} or die "please define owner in DEV_TEAM env var";

my $coverage = $ENV{'MIN_COVERAGE'} || 0.1;

my $paths = $ENV{'EXCLUDE_PATHS'} || '';
my @excludes = split /,/, $paths;

my $baseline = $ENV{'PHPUNIT_BASELINE'} || undef;

my $phpunit = GPH::PHPUnit->new($owner, CODEOWNERS_FILE, CLASSMAP_FILE, $coverage, \@excludes, $baseline);
my @excludes = split /,/, ($ENV{'EXCLUDE_PATHS'} || '');
my %config = (
owner => $owner,
classmap => './vendor/composer/autoload_classmap.php',
codeowners => './CODEOWNERS',
threshold => $ENV{'MIN_COVERAGE'},
excludes => \@excludes,
baseline => $ENV{'PHPUNIT_BASELINE'}
);

my $phpunit = GPH::PHPUnit->new(%config);

exit $phpunit->parse();
2 changes: 1 addition & 1 deletion infection2escapee-warning.pl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

use GPH::Infection;

my $infection = GPH::Infection->new($ENV{'MIN_MSI'}, $ENV{'MIN_COVERED_MSI'}, 8);
my $infection = GPH::Infection->new((msi => $ENV{'MIN_MSI'}, covered => $ENV{'MIN_COVERED_MSI'}));

exit $infection->Parse();
2 changes: 1 addition & 1 deletion lib/GPH.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package GPH;
use strict;
use warnings FATAL => 'all';

our $VERSION = '1.0.0';
our $VERSION = '1.1.0';

1;
10 changes: 8 additions & 2 deletions lib/GPH/Composer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#
# Revisions: 2023-01-20 - created
# 2024-02-10 - namespaced module, bugfixes and unit tests
# 2024-02-11 - constructor now requires named arguments
#------------------------------------------------------------------------------
package GPH::Composer;

Expand All @@ -15,14 +16,19 @@ use warnings FATAL => 'all';
#------------------------------------------------------------------------------
# Construct new class
#
# Inputs: classmap => (string) path to code owners file
#
# Returns: reference to GPH::Composer object
sub new {
my ($class, $path) = @_;
my ($class, %args) = @_;

exists($args{classmap}) or die "$!";

my $self = {};

bless $self, $class;

$self->{classmap} = $self->parseClassMap($path);
$self->{classmap} = $self->parseClassMap($args{classmap});

return $self;
}
Expand Down
21 changes: 13 additions & 8 deletions lib/GPH/Gitlab.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# 2023-02-18 - added GetPathsReference to be used with psalm.pm
# 2023-12-23 - added blacklist for more specific path definition
# 2024-02-10 - namespaced module, bugfixes and unit tests
# 2024-02-11 - constructor now requires named arguments
#------------------------------------------------------------------------------
package GPH::Gitlab;

Expand All @@ -17,21 +18,25 @@ use warnings FATAL => 'all';
#------------------------------------------------------------------------------
# Construct new class
#
# Inputs: 1) string path to code owners file
# 2) string current code owner
# 3) array paths to exclude
# Inputs: codeowners => (string) path to code owners file
# owner => (string) current code owner
# excludes => (array) paths to exclude
#
# Returns: reference to Gitlab object
sub new {
my ($class, $path, $owner, @excludes) = @_;
my ($class, %args) = @_;
my (%codeowners, %excludeHash, %blacklist);

(exists($args{owner}) and exists($args{codeowners})) or die "$!";

# build excludes hash for quick lookup
foreach my $item (@excludes) {
$excludeHash{$item} = 1;
if (exists($args{excludes})) {
foreach my $item ($args{excludes}) {
$excludeHash{$item} = 1;
}
}

open(my $fh, '<', $path) or die "unable to open codeowners file, initialization failed $!";
open(my $fh, '<', $args{codeowners}) or die "unable to open codeowners file, initialization failed $!";

my @lines = <$fh>;

Expand Down Expand Up @@ -69,7 +74,7 @@ sub new {
}

my $self = {
owner => $owner,
owner => $args{owner},
codeowners => \%codeowners,
blacklist => \%blacklist,
};
Expand Down
17 changes: 10 additions & 7 deletions lib/GPH/Infection.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#
# Revisions: 2023-03-27 - created
# 2024-02-10 - namespaced module, bugfixes and unit tests
# 2024-02-11 - constructor now requires named arguments
#------------------------------------------------------------------------------
package GPH::Infection;

Expand All @@ -14,18 +15,20 @@ use warnings FATAL => 'all';
#------------------------------------------------------------------------------
# Construct new GPH::Infection class
#
# Inputs: 0) string minimum msi
# 1) string minimum covered msi
# 2) int exit code for escapees
# Inputs: msi => (string) minimum msi
# covered => (string) minimum covered msi
# exit_code => int exit code for escapees, defaults to 8
#
# Returns: reference to GPH::Infection object
sub new {
my ($class, $msi, $covered, $code) = @_;
my ($class, %args) = @_;

(exists($args{msi}) and exists($args{covered})) or die "$!";

my $self = {
msi => $msi,
covered => $covered,
code => $code || 8,
msi => $args{msi},
covered => $args{covered},
code => $args{exit_code} || 8,
};

bless $self, $class;
Expand Down
13 changes: 8 additions & 5 deletions lib/GPH/PHPMD.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#
# Revisions: 2023-07-05 - created
# 2024-02-10 - namespaced module, bugfixes and unit tests
# 2024-02-11 - constructor now requires named arguments
#------------------------------------------------------------------------------

package GPH::PHPMD;
Expand All @@ -19,16 +20,18 @@ use GPH::XMLHelper;
#------------------------------------------------------------------------------
# Construct new class
#
# Inputs: 0) string code owner
# 1) int maximum cyclomatic complexity level
# Inputs: owner => (string) code owner
# cyclo_level => (int) maximum cyclomatic complexity level
#
# Returns: reference to GPH::PHPMD object
sub new {
my ($class, $owner, $cycloLevel) = @_;
my ($class, %args) = @_;

(exists($args{owner}) and exists($args{cyclo_level})) or die "$!";

my $self = {
owner => $owner,
cycloLevel => $cycloLevel,
owner => $args{owner},
cycloLevel => $args{cyclo_level},
generator => GPH::XMLHelper->new(),
};

Expand Down
Loading