Skip to content

Commit 863c75d

Browse files
authored
integration script fixes (#13)
- added support for codeowners /**/* notation - skip section default owners for now - prevent empty arrays from creating invalid configs
1 parent aa37501 commit 863c75d

17 files changed

+133
-74
lines changed

codeowner2infection-filter.pl renamed to codeowner2commaseparatedlist.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
my %config = (
1414
owner => $owner,
1515
codeowners => './CODEOWNERS',
16-
excludes => @excludes
16+
excludes => \@excludes,
1717
);
1818

1919
my $gitlab = GPH::Gitlab->new(%config);

codeowner2phpstan.pl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
use GPH::Gitlab;
99
use GPH::PHPStan;
1010

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

16-
my $gitlab = GPH::Gitlab->new((owner => $owner, codeowners => './CODEOWNERS', excludes => @excludes));
14+
my %gitlabConfig = (
15+
owner => $owner,
16+
codeowners => './CODEOWNERS',
17+
excludes => \@excludes,
18+
);
19+
20+
my $gitlab = GPH::Gitlab->new(%gitlabConfig);
1721

1822
my @includes = split /,/, ($ENV{'PHPSTAN_INCLUDES'} || './phpstan.ci.neon');
1923
my @ignored = split /,/, ($ENV{'PHPSTAN_IGNORED_DIRS'} || '');
@@ -22,9 +26,9 @@
2226

2327
my %config = (
2428
level => $ENV{'PHPSTAN_LEVEL'} || 6,
25-
paths => \$gitlab->getPaths(),
29+
paths => $gitlab->getPaths(),
2630
baseline => $ENV{'PHPSTAN_BASELINE'},
27-
ignoredDirectories => \@ignored,
31+
ignoredDirectories => @ignored,
2832
cacheDir => $ENV{'PHPSTAN_CACHE_DIR'},
2933
includes => \@includes,
3034
threads => $ENV{'PHPSTAN_THREADS'}

codeowner2psalm.pl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,27 @@
88
use GPH::Gitlab;
99
use GPH::Psalm;
1010

11-
use constant PSALM_CONFIG => './psalm.xml';
12-
1311
my $owner = $ENV{'DEV_TEAM'} or die "please define owner in DEV_TEAM env var";
1412
my @excludes = split /,/, ($ENV{'EXCLUDE_PATHS'} || '');
1513

16-
my $gitlab = GPH::Gitlab->new((owner => $owner, codeowners => './CODEOWNERS', excludes => @excludes));
14+
my %gitlabConfig = (
15+
owner => $owner,
16+
codeowners => './CODEOWNERS',
17+
excludes => \@excludes,
18+
);
19+
20+
my $gitlab = GPH::Gitlab->new(%gitlabConfig);
1721

1822
my @ignored = split /,/, ($ENV{'PSALM_IGNORED_DIRS'} || '');
1923
my @plugins = split /,/, ($ENV{'PSALM_PLUGINS'} || '');
20-
my $clone = defined($ENV{'PSALM_CLONE_HANDLERS'}) ? $ENV{'PSALM_CLONE_HANDLERS'} : 1;
24+
my $clone = (defined($ENV{'PSALM_CLONE_HANDLERS'}) ? $ENV{'PSALM_CLONE_HANDLERS'} : 1);
2125

2226
# merge ignored dirs with blacklist
23-
@ignored = (@ignored, $gitlab->getBlacklistPaths());
27+
@ignored = (@ignored, @{$gitlab->getBlacklistPaths()});
2428

2529
my %config = (
2630
level => $ENV{'PSALM_LEVEL'} || 4,
27-
paths => \$gitlab->getPaths(),
31+
paths => $gitlab->getPaths(),
2832
ignoredDirectories => \@ignored,
2933
baseline => $ENV{'PSALM_BASELINE'},
3034
baselineCheck => $ENV{'PSALM_BASELINE_CHECK'},
@@ -37,7 +41,7 @@
3741
if ($clone eq 1) {
3842
my @blacklist = split /,/, ($ENV{'PSALM_EXCLUDE_HANDLERS'} || '');
3943

40-
print $psalm->getConfigWithIssueHandlers(PSALM_CONFIG, @blacklist);
44+
print $psalm->getConfigWithIssueHandlers('./psalm.xml', @blacklist);
4145
}
4246
else {
4347
print $psalm->getConfig();

doc/Infection.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ though configurable in the `stdin2codeowner-filter.pl` file, for now no plans to
6565
> MIN_MSI: '95.00'
6666
> before_script:
6767
> - composer dump-autoload --optimize --ignore-platform-reqs
68-
> - git fetch --depth=1 origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
69-
> - export INFECTION_FILTER=$(git diff origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME --diff-filter=AM --name-only | .stdin2codeowner-filter.pl)
68+
> - git fetch --depth=1 origin $CI_MERGE_REQUEST_DIFF_BASE_SHA
69+
> - export INFECTION_FILTER=$(git diff $CI_MERGE_REQUEST_DIFF_BASE_SHA..$CI_COMMIT_SHA --diff-filter=AMR --name-only -- '***.php' | .stdin2codeowner-filter.pl)
7070
> script:
7171
> - ./vendor/bin/infection -j$(nproc) --filter=$INFECTION_FILTER --min-msi=$MIN_MSI --min-covered-msi=$MIN_COVERED_MSI --coverage=./coverage --skip-initial-tests
7272
> ```

infection2escapee-warning.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99

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

12-
exit $infection->Parse();
12+
exit $infection->parse();

lib/GPH/Gitlab.pm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ sub new {
3131

3232
# build excludes hash for quick lookup
3333
if (exists($args{excludes})) {
34-
foreach my $item ($args{excludes}) {
34+
foreach my $item (@{$args{excludes}}) {
3535
$excludeHash{$item} = 1;
3636
}
3737
}
@@ -44,9 +44,15 @@ sub new {
4444

4545
for my $line (@lines) {
4646

47+
# skip section line. default codeowners not yet supported
48+
next if $line =~ /[\[\]]/;
4749
# skip if line does not contain @
4850
next unless $line =~ /^.*\s\@[\w]+\/.*$/x;
4951

52+
# replace /**/* with a trailing forward slash
53+
my $pat = quotemeta('/**/* ');
54+
$line =~ s|$pat|/ |;
55+
5056
my ($class_path, $owners) = split(' ', $line, 2);
5157

5258
# skip if path is excluded

lib/GPH/PHPStan.pm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ sub new {
3030

3131
(exists($args{level}) and exists($args{paths})) or die "$!";
3232

33+
# filter out empty arrays
34+
my $excludes = ((exists($args{ignoredDirectories}) and scalar(@{$args{ignoredDirectories}}) != 0) ? $args{ignoredDirectories} : undef);
35+
3336
my $self = {
3437
level => $args{level},
3538
paths => $args{paths},
36-
ignoredDirectories => $args{ignoredDirectories} || undef,
39+
ignoredDirectories => $excludes,
3740
baseline => $args{baseline} || undef,
3841
cacheDir => $args{cacheDir} || 'var',
3942
includes => $args{includes} || undef,

lib/GPH/Psalm.pm

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,18 @@ sub new {
3838

3939
(exists($args{level}) and exists($args{paths})) or die "$!";
4040

41+
# prevent empty arrays
42+
my $ignored = ((exists($args{ignoredDirectories}) and scalar(@{$args{ignoredDirectories}}) != 0) ? $args{ignoredDirectories} : undef);
43+
my $plugins = ((exists($args{plugins}) and scalar(@{$args{plugins}}) != 0) ? $args{plugins} : undef);
44+
4145
my $self = {
4246
level => $args{level},
4347
paths => $args{paths},
44-
ignoredDirectories => $args{ignoredDirectories} || undef,
48+
ignoredDirectories => $ignored,
4549
baseline => $args{baseline} || undef,
4650
baselineCheck => $args{baselineCheck} || 'true',
4751
cacheDir => $args{cacheDir} || './psalm',
48-
plugins => $args{plugins} || undef,
52+
plugins => $plugins,
4953
generator => GPH::XMLHelper->new(),
5054
};
5155

@@ -60,6 +64,7 @@ sub new {
6064
# Returns: psalm.xml config file string
6165
sub getConfig {
6266
my $self = shift;
67+
my $type;
6368

6469
my $psalm = $self->{generator}->buildElement((name => 'psalm', attributes => {
6570
'resolveFromConfigFile' => 'true',
@@ -76,7 +81,9 @@ sub getConfig {
7681
my $projectFiles = $self->{generator}->buildElement((name => 'projectFiles', parent => $psalm));
7782

7883
foreach my $path (@{$self->{paths}}) {
79-
$self->{generator}->buildElement((name => 'directory', parent => $projectFiles, attributes => {
84+
$type = ($path =~ /.*\.[a-z]+$/) ? 'file' : 'directory';
85+
86+
$self->{generator}->buildElement((name => $type, parent => $projectFiles, attributes => {
8087
'name' => $path,
8188
}));
8289
}
@@ -85,7 +92,9 @@ sub getConfig {
8592
my $ignoreFiles = $self->{generator}->buildElement((name => 'ignoreFiles', parent => $projectFiles));
8693

8794
foreach my $path (@{$self->{ignoredDirectories}}) {
88-
$self->{generator}->buildElement((name => 'directory', parent => $ignoreFiles, attributes => {
95+
$type = ($path =~ /.*\.[a-z]+$/) ? 'file' : 'directory';
96+
97+
$self->{generator}->buildElement((name => $type, parent => $ignoreFiles, attributes => {
8998
'name' => $path,
9099
}));
91100
}
@@ -102,6 +111,7 @@ sub getConfig {
102111
}
103112

104113
my $dom = $self->{generator}->getDom();
114+
105115
$dom->setDocumentElement($psalm);
106116

107117
return ($dom->toString(1));
@@ -121,6 +131,8 @@ sub getConfigWithIssueHandlers {
121131
my ($handlers) = $dom->findnodes('//*[local-name()="issueHandlers"]');
122132

123133
foreach my $exclude ($blacklist) {
134+
next if not defined $exclude;
135+
124136
my ($remove) = $handlers->findnodes("//*[local-name()=\"${exclude}\"]");
125137

126138
if (defined $remove) {

stdin2codeowner-filter.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
my %config = (
1313
owner => $owner,
1414
codeowners => './CODEOWNERS',
15-
excludes => @excludes
15+
excludes => \@excludes
1616
);
1717

1818
my $gitlab = GPH::Gitlab->new(%config);

t/share/Gitlab/CODEOWNERS

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[alpha]
2-
/src/Command @teams/alpha
3-
/src/Service @teams/alpha @#!$%^
2+
/src/Command/**/* @teams/alpha
3+
/src/Service/ @teams/alpha @#!$%^
44
.gitlab-ci.yml @teams/alpha
55

66
[beta]
7-
/src/Command/Config @teams/beta
8-
/src/DependencyInjection @teams/beta
7+
/src/Command/Config/ConfigPhraseKeyCommand.php @teams/beta
8+
/src/DependencyInjection/ @teams/beta
99
.gitlab-ci.yml @teams/beta

0 commit comments

Comments
 (0)