Skip to content

Commit 1750a0a

Browse files
authored
[Feature] [Logger] Print date and time in logs (#47)
* print date time * add notes to event rule was failed * Add ApplicationNotCreatedException * add exceptions * check tz in LocalClock * fix lint * update docs * update doc * update docs: add event descriptions * fix tests * add test * add test * add test * Add covers * add test * update version
1 parent 5dfc7e5 commit 1750a0a

File tree

28 files changed

+267
-31
lines changed

28 files changed

+267
-31
lines changed

CHANGELOG.md

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

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

9+
## [v0.13.1 (2023-05-26)](https://github.com/ArtARTs36/php-merge-request-linter/compare/0.13.0..0.13.1)
10+
11+
### Added
12+
* [Logger] Print date and time in logs
13+
* Added array of notes in event `rule_was_failed`
14+
15+
### Internal
16+
* [Docs] Added event descriptions into config JSON Schema
17+
18+
[💾 Assets](https://github.com/ArtARTs36/php-merge-request-linter/releases/tag/0.13.1)
19+
20+
-----------------------------------------------------------------
21+
922
## [v0.13.0 (2023-05-25)](https://github.com/ArtARTs36/php-merge-request-linter/compare/0.12.1..0.13.0)
1023

1124
### Added

bin/mr-linter

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<?php
33

44
use ArtARTs36\MergeRequestLinter\Presentation\Console\Application\ApplicationFactory;
5+
use ArtARTs36\MergeRequestLinter\Presentation\Console\Exceptions\ApplicationNotCreatedException;
56
use Symfony\Component\Console\Output\ConsoleOutput;
67

78
$loaded = false;
@@ -28,6 +29,15 @@ if ($loaded === false) {
2829

2930
$output = new ConsoleOutput();
3031

31-
$application = (new ApplicationFactory())->create($output);
32+
try {
33+
$application = (new ApplicationFactory())->create($output);
34+
} catch (ApplicationNotCreatedException $e) {
35+
$output->writeln(sprintf(
36+
'Error: Application not created: %s',
37+
$e->getMessage(),
38+
));
39+
40+
exit(1);
41+
}
3242

3343
$application->run(output: $output);

docs/Builder/ConfigJsonSchema/Generator.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use ArtARTs36\MergeRequestLinter\DocBuilder\EventFinder;
77
use ArtARTs36\MergeRequestLinter\Domain\Notifications\ChannelType;
88
use ArtARTs36\MergeRequestLinter\Domain\Request\MergeRequest;
9+
use ArtARTs36\MergeRequestLinter\Shared\Reflector\ClassSummary;
10+
use ArtARTs36\MergeRequestLinter\Shared\Reflector\Reflector;
911

1012
class Generator
1113
{
@@ -183,6 +185,13 @@ private function mapEvents(): array
183185
'when' => $this->operatorSchemaArrayGenerator->generate($class),
184186
],
185187
];
188+
189+
$reflector = new \ReflectionClass($class);
190+
$description = Reflector::findPHPDocSummary($reflector);
191+
192+
if (! empty($description)) {
193+
$map[$eventName]['description'] = $description;
194+
}
186195
}
187196

188197
return $map;

docs/notifications.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
#### The following events are currently available for notifications:
77

8-
| Event | Description | Arguments |
9-
|---------------|----------------------------------------------------------------------------|-----------------|
10-
| lint_started | The event is created at the moment when the linter has just started | request |
11-
| lint_finished | The event is created at the moment when the linter has completed its work. | request, result |
8+
| Event | Description | Arguments |
9+
|---------------------|----------------------------------------------------------------------------|-----------------|
10+
| lint_started | The event is created at the moment when the linter has just started. | request |
11+
| lint_finished | The event is created at the moment when the linter has completed its work. | request, result |
12+
| rule_was_failed | The event is created at the moment when the linter rule was failed. | rule, notes |
13+
| rule_was_successful | The event is created at the moment when the linter rule was successful. | rule |
1214

1315
#### Templating
1416

mr-linter-config-schema.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,8 @@
12941294
},
12951295
"additionalProperties": false
12961296
}
1297-
}
1297+
},
1298+
"description": "The event is created at the moment when the linter has just started."
12981299
},
12991300
"rule_was_failed": {
13001301
"type": "object",
@@ -1403,11 +1404,17 @@
14031404
}
14041405
},
14051406
"additionalProperties": false
1407+
},
1408+
"notes": {
1409+
"type": "object",
1410+
"properties": [],
1411+
"additionalProperties": false
14061412
}
14071413
},
14081414
"additionalProperties": false
14091415
}
1410-
}
1416+
},
1417+
"description": "The event is created at the moment when the linter rule was failed."
14111418
},
14121419
"lint_finished": {
14131420
"type": "object",
@@ -2500,7 +2507,8 @@
25002507
},
25012508
"additionalProperties": false
25022509
}
2503-
}
2510+
},
2511+
"description": "The event is created at the moment when the linter has completed its work."
25042512
},
25052513
"rule_was_successful": {
25062514
"type": "object",
@@ -2613,7 +2621,8 @@
26132621
},
26142622
"additionalProperties": false
26152623
}
2616-
}
2624+
},
2625+
"description": "The event is created at the moment when the linter rule was successful."
26172626
}
26182627
}
26192628
}

src/Application/Linter/Linter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function run(MergeRequest $request): LintResult
5757
if (count($ruleNotes) === 0) {
5858
$this->events->dispatch(new RuleWasSuccessfulEvent($rule->getName()));
5959
} else {
60-
$this->events->dispatch(new RuleWasFailedEvent($rule->getName()));
60+
$this->events->dispatch(new RuleWasFailedEvent($rule->getName(), $ruleNotes));
6161
}
6262
} catch (EvaluatorCrashedException $e) {
6363
$notes[] = new LintNote(sprintf('[%s] Invalid condition value: %s', $rule->getName(), $e->getMessage()));

src/Domain/Linter/LintFinishedEvent.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use ArtARTs36\MergeRequestLinter\Domain\Request\MergeRequest;
66

77
/**
8+
* The event is created at the moment when the linter has completed its work.
89
* @codeCoverageIgnore
910
*/
1011
class LintFinishedEvent

src/Domain/Linter/LintStartedEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use ArtARTs36\MergeRequestLinter\Domain\Request\MergeRequest;
66

77
/**
8-
* Event for lint starting.
8+
* The event is created at the moment when the linter has just started.
99
* @codeCoverageIgnore
1010
*/
1111
class LintStartedEvent

src/Domain/Linter/RuleWasFailedEvent.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,22 @@
22

33
namespace ArtARTs36\MergeRequestLinter\Domain\Linter;
44

5+
use ArtARTs36\MergeRequestLinter\Domain\Note\Note;
6+
57
/**
8+
* The event is created at the moment when the linter rule was failed.
69
* @codeCoverageIgnore
710
*/
811
class RuleWasFailedEvent
912
{
1013
public const NAME = 'rule_was_failed';
1114

15+
/**
16+
* @param array<Note> $notes
17+
*/
1218
public function __construct(
1319
public readonly string $ruleName,
20+
public readonly array $notes,
1421
) {
1522
//
1623
}

src/Domain/Linter/RuleWasSuccessfulEvent.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace ArtARTs36\MergeRequestLinter\Domain\Linter;
44

55
/**
6+
* The event is created at the moment when the linter rule was successful.
67
* @codeCoverageIgnore
78
*/
89
class RuleWasSuccessfulEvent

0 commit comments

Comments
 (0)