Skip to content

Commit 50c285c

Browse files
authored
[Feature] Add Comments (#51)
* Add comments
1 parent 05c36cf commit 50c285c

File tree

192 files changed

+7338
-441
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+7338
-441
lines changed

.mr-linter.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,12 @@ ci:
102102
github_actions:
103103
credentials:
104104
token: 'env(MR_LINTER_GITHUB_HTTP_TOKEN)'
105+
106+
comments:
107+
strategy: 'single'
108+
messages:
109+
- template: |
110+
I found {{ result.notes.count }} notes in your Pull Request:
111+
{% for note in result.notes %}
112+
- {{ note.description | raw }}
113+
{% endfor %}

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ This file contains changelogs.
66

77
-----------------------------------------------------------------
88

9+
## [v0.16.0 (2023-08-06)](https://github.com/ArtARTs36/php-merge-request-linter/compare/0.15.3..0.16.0)
10+
11+
## Added
12+
* Added comments with lint result for merge requests
13+
14+
[💾 Assets](https://github.com/ArtARTs36/php-merge-request-linter/releases/tag/0.16.0)
15+
16+
-----------------------------------------------------------------
17+
918
## [v0.15.3 (2023-07-29)](https://github.com/ArtARTs36/php-merge-request-linter/compare/0.15.2..0.15.3)
1019

1120
## Added

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ try-gitlab:
3838

3939
# usage as `make try-bitbucket MR_ID=2`
4040
try-bitbucket:
41-
BITBUCKET_PROJECT_KEY=aukrainsky \
42-
BITBUCKET_PR_ID=6 \
43-
BITBUCKET_WORKSPACE=aukrainsky \
44-
BITBUCKET_REPO_SLUG=a1 \
41+
BITBUCKET_PROJECT_KEY=ArtARTs36 \
42+
BITBUCKET_PR_ID=${MR_ID} \
43+
BITBUCKET_WORKSPACE=ArtARTs36 \
44+
BITBUCKET_REPO_SLUG=test-repo \
4545
./bin/mr-linter lint --debug --metrics
4646

4747
docker-build:
@@ -149,7 +149,7 @@ test-e2e-docker: docker-build
149149

150150
test-docker: docker-testing-build
151151
docker run \
152-
--volume ./:/app \
152+
--volume ./:/app/ \
153153
--env-file .env \
154154
--entrypoint "composer" \
155155
artarts36/merge-request-linter "test"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Supported CI Systems: **GitHub Actions**, **Gitlab CI**, **Bitbucket Pipelines**
2323
* [Docker Image](https://hub.docker.com/repository/docker/artarts36/merge-request-linter)
2424
* [Config JSON Schema](mr-linter-config-schema.json)
2525
* [Notifications](docs/notifications.md)
26+
* [Comments](docs/comments.md)
2627
* [Run in Docker](docs/run-in-docker.md)
2728
* [Development](docs/development.md)
2829
* [Changelog](CHANGELOG.md)

docs/Builder/ConditionsPageBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public function build(): string
2121
return TwigRenderer::create()
2222
->render(
2323
file_get_contents(__DIR__ . '/templates/conditions.md.twig'),
24-
new ArrayMap([
24+
[
2525
'operators' => $operators,
26-
]),
26+
],
2727
);
2828
}
2929
}

docs/Builder/ConfigJsonSchema/Generator.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace ArtARTs36\MergeRequestLinter\DocBuilder\ConfigJsonSchema;
44

5+
use ArtARTs36\MergeRequestLinter\Application\Comments\Message\MessageConditions;
56
use ArtARTs36\MergeRequestLinter\DocBuilder\ConfigJsonSchema\Schema\JsonSchema;
67
use ArtARTs36\MergeRequestLinter\DocBuilder\EventFinder;
8+
use ArtARTs36\MergeRequestLinter\Domain\Configuration\CommentsPostStrategy;
79
use ArtARTs36\MergeRequestLinter\Domain\Notifications\ChannelType;
810
use ArtARTs36\MergeRequestLinter\Domain\Request\MergeRequest;
911
use ArtARTs36\MergeRequestLinter\Shared\Reflection\Reflector\Reflector;
@@ -29,6 +31,28 @@ public function generate(): JsonSchema
2931
'additionalProperties' => false,
3032
]);
3133

34+
$schema->addProperty('comments', [
35+
'type' => 'object',
36+
'properties' => [
37+
'strategy' => [
38+
'type' => 'string',
39+
'enum' => array_map(fn (\BackedEnum $enum) => $enum->value, CommentsPostStrategy::cases()),
40+
],
41+
'messages' => [
42+
'type' => 'array',
43+
'items' => [
44+
'type' => 'object',
45+
'properties' => [
46+
'template' => [
47+
'type' => 'string',
48+
],
49+
'when' => $this->operatorSchemaArrayGenerator->generate(MessageConditions::class),
50+
],
51+
],
52+
],
53+
],
54+
], false);
55+
3256
$schema->addProperty('ci', [
3357
'type' => 'object',
3458
'properties' => [

docs/Builder/RulesPageBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ public function build(): string
5858

5959
return TwigRenderer::create()->render(
6060
file_get_contents(__DIR__ . '/templates/rules.md.twig'),
61-
new ArrayMap([
61+
[
6262
'rules' => $rules,
63-
])
63+
],
6464
);
6565
}
6666
}

docs/Builder/build_config_json_schema.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
file_put_contents(__DIR__ . '/../config-schema.md', TwigRenderer::create()->render(
2020
file_get_contents(__DIR__ . '/templates/config-schema.md.twig'),
21-
new \ArtARTs36\MergeRequestLinter\Shared\DataStructure\ArrayMap([
21+
[
2222
'schema' => $json,
23-
]),
23+
],
2424
));
2525

2626
$updated = $prevHash !== md5($json);

docs/comments.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Comments
2+
3+
You can receive comments on merge request page.
4+
5+
#### Post strategies
6+
7+
| Strategy | Description |
8+
|---------------|--------------------------------------------|
9+
| single | Each linter run will overwrite one comment |
10+
| single_append | Each linter run append one comment |
11+
| new | Each linter run creates a new comment |
12+
13+
#### Templating
14+
15+
The template engine [Twig](https://twig.symfony.com) is used to render the message.
16+
17+
Simple template:
18+
```html
19+
Review on PR "{{ request.title }}"
20+
```
21+
22+
#### Example configuration:
23+
24+
```yaml
25+
comments:
26+
strategy: 'single'
27+
messages:
28+
- template: |
29+
I found {{ result.notes.count }} notes in your Pull Request:
30+
{% for note in result.notes %}
31+
- {{ note.description | raw }}
32+
{% endfor %}
33+
```
34+
35+
#### Example configuration (only "master"):
36+
37+
```yaml
38+
comments:
39+
strategy: 'single'
40+
messages:
41+
- template: |
42+
I found {{ result.notes.count }} notes in your Pull Request:
43+
{% for note in result.notes %}
44+
- {{ note.description | raw }}
45+
{% endfor %}
46+
when:
47+
request.targetBranch:
48+
equals: "master"
49+
```
50+

0 commit comments

Comments
 (0)