Skip to content

Commit 872ab1a

Browse files
authored
[Feature] Not intersect evaluator (#64)
* add evaluator * up doc * split feature bug * fix stat analyse * clean make * add test * fix make docs * up docs * fix evaluator when values count > 2 * catch invalid environment variable value * up version * up version * add unreleased link to changelog
1 parent cdbd295 commit 872ab1a

17 files changed

+334
-120
lines changed

.mr-linter.yml

+7
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ rules:
7575
labels:
7676
has: "Feature"
7777

78+
- definition: "Split feature / bug PR"
79+
rules:
80+
labels:
81+
notIntersect:
82+
- Feature
83+
- Bug
84+
7885
notifications:
7986
channels:
8087
dev:

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ This file contains changelogs.
44

55
[View all Releases](https://github.com/ArtARTs36/php-merge-request-linter/releases)
66

7+
## [Unreleased](https://github.com/ArtARTs36/php-merge-request-linter/compare/0.19.1..master)
8+
9+
## [v0.19.1 (2023-09-12)](https://github.com/ArtARTs36/php-merge-request-linter/compare/0.19.0..0.19.1)
10+
11+
### Added
12+
* Added an Evaluator `notIntersect` to check that the array does not intersect with the user array.
13+
14+
[💾 Assets](https://github.com/ArtARTs36/php-merge-request-linter/releases/tag/0.19.1)
15+
716
-----------------------------------------------------------------
817

918
## [v0.19.0 (2023-09-11)](https://github.com/ArtARTs36/php-merge-request-linter/compare/0.18.1..0.19.0)

Makefile

+65-61
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,65 @@ ifneq ("$(wildcard .env)","")
44
endif
55

66
.PHONY: docs
7+
.DEFAULT_GOAL: help
78

8-
env:
9+
# Thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
10+
help: ## Show this help
11+
@printf "\033[33m%s:\033[0m\n" 'Available commands'
12+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {printf " \033[32m%-18s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
13+
14+
env: ## Create environment file for local testing
915
echo "MR_LINTER_GITHUB_HTTP_TOKEN=token\nMR_LINTER_GITLAB_HTTP_TOKEN=token\n" > .env
1016
echo "E2E_MR_LINTER_GITHUB_HTTP_TOKEN=token\nE2E_MR_LINTER_GITLAB_HTTP_TOKEN=token" >> .env
1117
echo "E2E_MR_LINTER_BITBUCKET_APP_USER=token\nE2E_MR_LINTER_BITBUCKET_APP_PASSWORD=token\n" >> .env
1218

13-
# usage as `make try MR_ID=1`
14-
try:
15-
GITHUB_ACTIONS=1 \
16-
GITHUB_REPOSITORY=artarts36/php-merge-request-linter \
17-
GITHUB_GRAPHQL_URL=https://api.github.com/graphql \
18-
GITHUB_REF_NAME=${MR_ID}/merge \
19-
./bin/mr-linter lint --debug --metrics
20-
21-
# usage as `make try-phar MR_ID=1`
22-
try-phar: build-phar
23-
GITHUB_ACTIONS=1 \
24-
GITHUB_REPOSITORY=artarts36/php-merge-request-linter \
25-
GITHUB_GRAPHQL_URL=https://api.github.com/graphql \
26-
GITHUB_REF_NAME=${MR_ID}/merge \
27-
./bin/build/mr-linter.phar lint --debug --metrics
19+
#######################################
20+
# Locally run of MR-Linter
21+
######################################
2822

29-
# usage as `make try MR_ID=1`
30-
try-docker: docker-build
23+
try: docker-build ## Try lint on docker with GitHub Actions: usage as `make try MR_ID=1`
3124
docker run \
25+
--rm \
3226
--env-file .env \
3327
--env GITHUB_ACTIONS=1 \
3428
--env GITHUB_REPOSITORY=artarts36/php-merge-request-linter \
3529
--env GITHUB_GRAPHQL_URL=https://api.github.com/graphql \
3630
--env GITHUB_REF_NAME=${MR_ID}/merge \
3731
artarts36/merge-request-linter:testing "lint" --debug --metrics
3832

39-
# usage as `make try-gitlab MR_ID=1`
40-
try-gitlab:
41-
GITLAB_CI=1 \
42-
CI_MERGE_REQUEST_IID=${MR_ID} \
43-
CI_MERGE_REQUEST_PROJECT_ID=41749211 \
44-
CI_SERVER_URL=https://gitlab.com \
45-
./bin/mr-linter lint --debug --metrics
46-
47-
# usage as `make try-bitbucket MR_ID=2`
48-
try-bitbucket:
49-
BITBUCKET_PROJECT_KEY=ArtARTs36 \
50-
BITBUCKET_PR_ID=${MR_ID} \
51-
BITBUCKET_WORKSPACE=ArtARTs36 \
52-
BITBUCKET_REPO_SLUG=test-repo \
53-
./bin/mr-linter lint --debug --metrics
54-
55-
docker-build:
56-
docker build . -t artarts36/merge-request-linter:testing
33+
try-gitlab: ## Try lint on docker with Gitlab CI: usage as `make try-gitlab MR_ID=1`
34+
docker run \
35+
--rm \
36+
--env-file .env \
37+
--env GITLAB_CI=1 \
38+
--env CI_MERGE_REQUEST_IID=${MR_ID} \
39+
--env CI_MERGE_REQUEST_PROJECT_ID=41749211 \
40+
--env CI_SERVER_URL=https://gitlab.com \
41+
artarts36/merge-request-linter:testing "lint" --debug --metrics
42+
43+
try-bitbucket: ## Try lint on docker with Gitlab CI: usage as `make try-bitbucket MR_ID=1`
44+
docker run \
45+
--rm \
46+
--env-file .env \
47+
--env BITBUCKET_PROJECT_KEY=ArtARTs36 \
48+
--env BITBUCKET_PR_ID=${MR_ID} \
49+
--env BITBUCKET_WORKSPACE=ArtARTs36 \
50+
--env BITBUCKET_REPO_SLUG=test-repo \
51+
artarts36/merge-request-linter:testing "lint" --debug --metrics
5752

58-
docker-lint: docker-build
59-
docker run artarts36/merge-request-linter lint
53+
try-phar: build-phar ## Try lint on PHAR: usage as `make try-phar MR_ID=1`
54+
GITHUB_ACTIONS=1 \
55+
GITHUB_REPOSITORY=artarts36/php-merge-request-linter \
56+
GITHUB_GRAPHQL_URL=https://api.github.com/graphql \
57+
GITHUB_REF_NAME=${MR_ID}/merge \
58+
./bin/build/mr-linter.phar lint --debug --metrics
59+
60+
#######################################
61+
# Build of MR-Linter
62+
######################################
63+
64+
docker-build: ## Build docker image for local testing
65+
docker build . -t artarts36/merge-request-linter:testing
6066

6167
# usage as `make docker-pub-build MR_LINTER_VERSION=0.2.0`
6268
docker-pub-build:
@@ -85,17 +91,12 @@ docker-pub-try:
8591
-v "${PWD}/.mr-linter.yml:/app/.mr-linter.yml:ro" \
8692
artarts36/merge-request-linter:${MR_LINTER_VERSION} lint
8793

88-
docs:
89-
php docs/Builder/build_rules.php
90-
php docs/Builder/build_config_json_schema.php
91-
php docs/Builder/build_conditions.php
92-
93-
docs-docker: docker-build
94+
docs: ## Build documentation
9495
docker run \
9596
--rm \
9697
--volume ./:/app \
9798
--env-file .env \
98-
--entrypoint "make" \
99+
--entrypoint "composer" \
99100
artarts36/merge-request-linter:testing "docs"
100101

101102
deps-check:
@@ -110,16 +111,18 @@ check: deps-check
110111
composer deptrac
111112
composer test
112113

113-
info:
114-
./bin/mr-linter info
115-
116-
dump:
117-
./bin/mr-linter dump
114+
info: ## Run "mr-linter info" on docker
115+
docker run \
116+
--rm \
117+
--volume ./:/app \
118+
--env-file .env \
119+
artarts36/merge-request-linter:testing "info"
118120

119-
dump-docker: docker-build
121+
dump: ## Run "mr-linter dump" on docker
120122
docker run \
123+
--rm \
121124
--volume ./:/app \
122-
--entrypoint "make" \
125+
--env-file .env \
123126
artarts36/merge-request-linter:testing "dump"
124127

125128
push-docs:
@@ -139,37 +142,38 @@ lint-fix-docker: docker-build
139142
--entrypoint "composer" \
140143
artarts36/merge-request-linter:testing "lint-fix"
141144

142-
stat-analyse-docker: docker-build
145+
stat-analyse: docker-build
143146
docker run \
147+
--rm \
144148
--env-file .env \
145149
--entrypoint "composer" \
146150
artarts36/merge-request-linter:testing "stat-analyse"
147151

148-
test-e2e:
149-
composer test-e2e
150-
151-
test-e2e-docker: docker-build
152+
test-e2e: docker-build
152153
docker run \
154+
--rm \
153155
--env-file .env \
154156
--entrypoint "composer" \
155157
artarts36/merge-request-linter:testing "test-e2e"
156158

157-
test-docker: docker-build
159+
test: docker-build ## Run tests
158160
docker run \
161+
--rm \
159162
--volume ./:/app/ \
160163
--env-file .env \
161164
--entrypoint "composer" \
162165
artarts36/merge-request-linter:testing "test"
163166

164-
deptrac-docker: docker-build
167+
deptrac: docker-build ## Run deptrac
165168
docker run \
169+
--rm \
166170
--env-file .env \
167171
--entrypoint "composer" \
168172
artarts36/merge-request-linter:testing "deptrac"
169173

170-
check-docker: lint-docker stat-analyse-docker test-docker deptrac-docker
174+
check-docker: lint-docker stat-analyse test deptrac
171175

172-
build-phar:
176+
build-phar: ## Build PHAR
173177
composer install --no-interaction --no-dev --prefer-dist --optimize-autoloader
174178
cd dev/build/ && composer install
175179
./dev/build/vendor/bin/box compile

composer.json

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@
8383
],
8484
"test-e2e": [
8585
"./vendor/bin/phpunit --filter testLint ./tests/E2E/LintE2ETest.php"
86+
],
87+
"docs": [
88+
"@php ./docs/builder/build.php"
8689
]
8790
},
8891
"config": {

docs/Builder/ConfigJsonSchema/OperatorSchemaArrayGenerator.php

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use ArtARTs36\MergeRequestLinter\Application\Condition\Evaluators\NotEqualsEvaluator;
2222
use ArtARTs36\MergeRequestLinter\Application\Condition\Evaluators\NotHasAnyEvaluator;
2323
use ArtARTs36\MergeRequestLinter\Application\Condition\Evaluators\NotHasEvaluator;
24+
use ArtARTs36\MergeRequestLinter\Application\Condition\Evaluators\NotIntersectEvaluator;
2425
use ArtARTs36\MergeRequestLinter\Application\Condition\Evaluators\Strings\Cases\IsCamelCaseEvaluator;
2526
use ArtARTs36\MergeRequestLinter\Application\Condition\Evaluators\Strings\Cases\IsKebabCaseEvaluator;
2627
use ArtARTs36\MergeRequestLinter\Application\Condition\Evaluators\Strings\Cases\IsLowerCaseEvaluator;
@@ -110,6 +111,7 @@ class OperatorSchemaArrayGenerator
110111
IsEmptyEvaluator::class,
111112
AllEvaluator::class,
112113
AnyEvaluator::class,
114+
NotIntersectEvaluator::class,
113115
],
114116
Map::class => [
115117
CountMinEvaluator::class,
@@ -124,6 +126,7 @@ class OperatorSchemaArrayGenerator
124126
IsEmptyEvaluator::class,
125127
AllEvaluator::class,
126128
AnyEvaluator::class,
129+
NotIntersectEvaluator::class,
127130
],
128131
Arrayee::class => [
129132
CountMinEvaluator::class,
@@ -138,6 +141,7 @@ class OperatorSchemaArrayGenerator
138141
IsEmptyEvaluator::class,
139142
AllEvaluator::class,
140143
AnyEvaluator::class,
144+
NotIntersectEvaluator::class,
141145
],
142146
'bool' => [
143147
EqualsEvaluator::class,

docs/Builder/build.php

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
use ArtARTs36\MergeRequestLinter\DocBuilder\ConditionsPageBuilder;
4+
use ArtARTs36\MergeRequestLinter\DocBuilder\RulesPageBuilder;
5+
6+
require __DIR__ . '/../../vendor/autoload.php';
7+
8+
$builders = [
9+
[
10+
'name' => 'Rules page',
11+
'path' => __DIR__ . '/../rules.md',
12+
'builder' => function () {
13+
$builder = new RulesPageBuilder();
14+
15+
return $builder->build();
16+
},
17+
],
18+
[
19+
'name' => 'Config JSON Schema',
20+
'path' => __DIR__ . '/../../mr-linter-config-schema.json',
21+
'builder' => function () {
22+
$jsonSchema = new \ArtARTs36\MergeRequestLinter\DocBuilder\ConfigJsonSchema\Generator();
23+
24+
return $jsonSchema->generate()->toJson();
25+
},
26+
],
27+
[
28+
'name' => 'Conditions page',
29+
'path' => __DIR__ . '/../conditions.md',
30+
'builder' => function () {
31+
$builder = new ConditionsPageBuilder();
32+
33+
return $builder->build();
34+
},
35+
],
36+
];
37+
38+
$saver = new \ArtARTs36\MergeRequestLinter\DocBuilder\Saver();
39+
40+
foreach ($builders as $builder) {
41+
$result = $builder['builder']();
42+
43+
$updated = $saver->save($builder['path'], $result);
44+
45+
if ($updated) {
46+
echo sprintf('-> %s: Documentation page updated', $builder['name']) . "\n";
47+
} else {
48+
echo sprintf('-> %s: Documentation page is actually', $builder['name']) . "\n";
49+
}
50+
}

docs/Builder/build_conditions.php

-14
This file was deleted.

docs/Builder/build_config_json_schema.php

-29
This file was deleted.

docs/Builder/build_rules.php

-14
This file was deleted.

docs/conditions.md

+1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ Currently is available that operators:
4848
| containsHeading4 | Check if a markdown-string contains a heading. | string |
4949
| containsHeading5 | Check if a markdown-string contains a heading. | string |
5050
| containsHeading6 | Check if a markdown-string contains a heading. | string |
51+
| notIntersect | Check that the array does not intersect with the user array. | array of strings |
5152

0 commit comments

Comments
 (0)