Skip to content

Commit 7cb56bb

Browse files
authored
Merge pull request #24 from RonasIT/20_add-dependabot-configuration-step
20_add dependabot configuration step
2 parents 5521c2b + 93232bd commit 7cb56bb

File tree

9 files changed

+302
-7
lines changed

9 files changed

+302
-7
lines changed

resources/md/readme/CREDENTIALS_AND_ACCESS.md

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

1111
{nova_credentials}Laravel Nova access:
1212
- email `:nova_email`
13-
- password `:nova_password`{/nova_credentials}
13+
- password `:nova_password`{/nova_credentials}

resources/md/readme/RENOVATE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Renovate
2+
3+
The application uses Renovate dependabot for automatically updating dependencies. You can configure it more precisely using the `renovate.json` file. Available configuration described here https://docs.renovatebot.com/config-overview

src/Commands/InitCommand.php

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Contracts\Console\Isolatable;
77
use Illuminate\Support\Arr;
88
use Illuminate\Support\Carbon;
9+
use Illuminate\Support\Facades\Validator;
910
use Illuminate\Support\Str;
1011
use RonasIT\ProjectInitializator\Enums\RoleEnum;
1112
use Illuminate\Support\Facades\Artisan;
@@ -24,9 +25,11 @@ class InitCommand extends Command implements Isolatable
2425
'nova' => 'Laravel Nova',
2526
];
2627

28+
public const string CONTACTS_TEAM_LEAD = 'team_lead';
29+
2730
public const array CONTACTS_ITEMS = [
2831
'manager' => 'Manager',
29-
'team_lead' => 'Code Owner/Team Lead',
32+
self::CONTACTS_TEAM_LEAD => 'Code Owner/Team Lead',
3033
];
3134

3235
public const array CREDENTIALS_ITEMS = [
@@ -63,6 +66,8 @@ class InitCommand extends Command implements Isolatable
6366

6467
protected string $appName;
6568

69+
protected ?string $reviewer = null;
70+
6671
public function handle(): void
6772
{
6873
$this->prepareAppName();
@@ -88,7 +93,7 @@ public function handle(): void
8893
$this->createAdminUser($kebabName);
8994
}
9095

91-
if ($this->confirm('Do you want to generate a README file?', true)) {
96+
if ($shouldGenerateReadme = $this->confirm('Do you want to generate a README file?', true)) {
9297
$this->fillReadme();
9398

9499
if ($this->confirm('Do you need a `Resources & Contacts` part?', true)) {
@@ -126,6 +131,16 @@ public function handle(): void
126131
}
127132
}
128133

134+
if ($this->confirm('Would you use Renovate dependabot?')) {
135+
$this->saveRenovateJSON();
136+
137+
if ($shouldGenerateReadme) {
138+
$this->fillRenovate();
139+
140+
$this->saveReadme();
141+
}
142+
}
143+
129144
if ($this->confirm('Do you want to install media package?')) {
130145
$this->shellCommands[] = 'composer require ronasit/laravel-media';
131146
}
@@ -219,6 +234,10 @@ protected function fillContacts(): void
219234

220235
foreach (self::CONTACTS_ITEMS as $key => $title) {
221236
if ($link = $this->ask("Please enter a {$title}'s email", '')) {
237+
if (!empty($link) && $key === self::CONTACTS_TEAM_LEAD) {
238+
$this->reviewer = $link;
239+
}
240+
222241
$this->setReadmeValue($filePart, "{$key}_link", $link);
223242
} else {
224243
$this->emptyValuesList[] = "{$title}'s email";
@@ -371,4 +390,44 @@ protected function prepareAppName(): void
371390
$this->appName = $pascalCaseAppName;
372391
}
373392
}
393+
394+
protected function saveRenovateJSON(): void
395+
{
396+
$this->reviewer = $this->validateInput(
397+
method: fn () => $this->ask('Please type username of the project reviewer', Str::before($this->reviewer, '@')),
398+
field: 'username of the project reviewer',
399+
rules: 'required|alpha_dash',
400+
);
401+
402+
$data = [
403+
'$schema' => 'https://docs.renovatebot.com/renovate-schema.json',
404+
'extends' => ['config:recommended'],
405+
'enabledManagers' => ['composer'],
406+
'assignees' => [$this->reviewer],
407+
];
408+
409+
file_put_contents('renovate.json', json_encode($data, JSON_PRETTY_PRINT));
410+
}
411+
412+
protected function validateInput(callable $method, string $field, string|array $rules): string
413+
{
414+
$value = $method();
415+
416+
$validator = Validator::make([$field => $value], [$field => $rules]);
417+
418+
if ($validator->fails()) {
419+
$this->warn($validator->errors()->first());
420+
421+
$value = $this->validateInput($method, $field, $rules);
422+
}
423+
424+
return $value;
425+
}
426+
427+
protected function fillRenovate(): void
428+
{
429+
$filePart = $this->loadReadmePart('RENOVATE.md');
430+
431+
$this->updateReadmeFile($filePart);
432+
}
374433
}

tests/InitCommandTest.php

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ public function testRunWithoutAdminAndReadmeCreation()
2424
$this->mockFilePutContent(
2525
'env.example_app_name_pascal_case.yml',
2626
'env.development_app_name_pascal_case.yml',
27+
[
28+
'renovate.json',
29+
$this->getFixture('renovate.json'),
30+
'optionalParameter',
31+
'optionalParameter',
32+
],
2733
);
2834

2935
$this->mockShellExec(
@@ -40,6 +46,8 @@ public function testRunWithoutAdminAndReadmeCreation()
4046
->expectsQuestion('Please enter an application URL', 'https://mysite.com')
4147
->expectsConfirmation('Do you want to generate an admin user?')
4248
->expectsConfirmation('Do you want to generate a README file?')
49+
->expectsConfirmation('Would you use Renovate dependabot?', 'yes')
50+
->expectsQuestion('Please type username of the project reviewer', 'reviewer')
4351
->expectsConfirmation('Do you want to install media package?')
4452
->expectsConfirmation('Do you want to uninstall project-initializator package?')
4553
->assertExitCode(0);
@@ -78,6 +86,7 @@ public function testRunWithoutAdminAndReadmeCreationConvertAppNameToPascalCase()
7886
->expectsQuestion('Please enter an application URL', 'https://mysite.com')
7987
->expectsConfirmation('Do you want to generate an admin user?')
8088
->expectsConfirmation('Do you want to generate a README file?')
89+
->expectsConfirmation('Would you use Renovate dependabot?')
8190
->expectsConfirmation('Do you want to install media package?')
8291
->expectsConfirmation('Do you want to uninstall project-initializator package?')
8392
->assertExitCode(0);
@@ -126,6 +135,7 @@ public function testRunWithAdminAndWithoutReadmeCreation()
126135
->expectsQuestion('Please enter an admin password', '123456')
127136
->expectsQuestion('Please enter an admin role id', 1)
128137
->expectsConfirmation('Do you want to generate a README file?')
138+
->expectsConfirmation('Would you use Renovate dependabot?')
129139
->expectsConfirmation('Do you want to install media package?')
130140
->expectsConfirmation('Do you want to uninstall project-initializator package?')
131141
->assertExitCode(0);
@@ -174,6 +184,10 @@ public function testRunWithAdminAndDefaultReadmeCreation()
174184
'arguments' => ['/app/resources/md/readme/CREDENTIALS_AND_ACCESS.md'],
175185
'result' => $this->getTemplate('CREDENTIALS_AND_ACCESS.md'),
176186
],
187+
[
188+
'arguments' => ['/app/resources/md/readme/RENOVATE.md'],
189+
'result' => $this->getTemplate('RENOVATE.md'),
190+
],
177191
);
178192

179193
$this->mockFilePutContent(
@@ -190,7 +204,19 @@ public function testRunWithAdminAndDefaultReadmeCreation()
190204
$this->getFixture('default_readme.md'),
191205
'optionalParameter',
192206
'optionalParameter',
193-
]
207+
],
208+
[
209+
'renovate.json',
210+
$this->getFixture('renovate.json'),
211+
'optionalParameter',
212+
'optionalParameter',
213+
],
214+
[
215+
'README.md',
216+
$this->getFixture('default_readme_after_using_renovate.md'),
217+
'optionalParameter',
218+
'optionalParameter',
219+
],
194220
);
195221

196222
$this->mockShellExec(
@@ -267,6 +293,8 @@ public function testRunWithAdminAndDefaultReadmeCreation()
267293
->expectsOutput('- ArgoCD link')
268294
->expectsOutput('- Manager\'s email')
269295
->expectsOutput('- Code Owner/Team Lead\'s email')
296+
->expectsConfirmation('Would you use Renovate dependabot?', 'yes')
297+
->expectsQuestion('Please type username of the project reviewer', 'reviewer')
270298
->expectsConfirmation('Do you want to install media package?')
271299
->expectsConfirmation('Do you want to uninstall project-initializator package?')
272300
->assertExitCode(0);
@@ -382,6 +410,7 @@ public function testRunWithAdminAndPartialReadmeCreation()
382410
->expectsOutput('Don`t forget to fill the following empty values:')
383411
->expectsOutput('- Issue Tracker link')
384412
->expectsOutput('- Code Owner/Team Lead\'s email')
413+
->expectsConfirmation('Would you use Renovate dependabot?')
385414
->expectsConfirmation('Do you want to install media package?')
386415
->expectsConfirmation('Do you want to uninstall project-initializator package?')
387416
->assertExitCode(0);
@@ -430,6 +459,10 @@ public function testRunWithAdminAndFullReadmeCreationAndRemovingInitializatorIns
430459
'arguments' => ['/app/resources/md/readme/CREDENTIALS_AND_ACCESS.md'],
431460
'result' => $this->getTemplate('CREDENTIALS_AND_ACCESS.md'),
432461
],
462+
[
463+
'arguments' => ['/app/resources/md/readme/RENOVATE.md'],
464+
'result' => $this->getTemplate('RENOVATE.md'),
465+
],
433466
);
434467

435468
$this->mockFilePutContent(
@@ -446,7 +479,19 @@ public function testRunWithAdminAndFullReadmeCreationAndRemovingInitializatorIns
446479
$this->getFixture('full_readme.md'),
447480
'optionalParameter',
448481
'optionalParameter',
449-
]
482+
],
483+
[
484+
'renovate.json',
485+
$this->getFixture('renovate.json'),
486+
'optionalParameter',
487+
'optionalParameter',
488+
],
489+
[
490+
'README.md',
491+
$this->getFixture('full_readme_after_using_renovate.md'),
492+
'optionalParameter',
493+
'optionalParameter',
494+
],
450495
);
451496

452497
$this->mockShellExec(
@@ -519,6 +564,8 @@ public function testRunWithAdminAndFullReadmeCreationAndRemovingInitializatorIns
519564
->expectsQuestion('Please enter a Laravel Nova\'s admin email', '[email protected]')
520565
->expectsQuestion('Please enter a Laravel Nova\'s admin password', '654321')
521566
->expectsOutput('README generated successfully!')
567+
->expectsConfirmation('Would you use Renovate dependabot?', 'yes')
568+
->expectsQuestion('Please type username of the project reviewer', 'reviewer')
522569
->expectsConfirmation('Do you want to install media package?', 'yes')
523570
->expectsConfirmation('Do you want to uninstall project-initializator package?', 'yes')
524571
->assertExitCode(0);

tests/fixtures/InitCommandTest/default_readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ Laravel Telescope access:
8080

8181
Laravel Nova access:
8282
83-
- password `123456`
83+
- password `123456`
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# My App
2+
3+
This project implements an API for the My App Multiplatform app.
4+
5+
## Project Resources & Contacts
6+
7+
This section provides quick links to various resources and contacts associated
8+
with this project. It's here to streamline your navigation and communication
9+
process, so you can efficiently find what you need or reach out to who you need.
10+
11+
### Resources
12+
13+
Below are links to tools and services used in this project:
14+
- [Issue Tracker](): Here, you can report any issues or bugs related to the project. (will be added later)
15+
- [Figma](): This is where we maintain all our design assets and mock-ups. (will be added later)
16+
- [Sentry](): To monitor application performance and error tracking. (will be added later)
17+
- [DataDog](): This is where we monitor our logs, and server performance, and receive alerts. (will be added later)
18+
- [ArgoCD](): Is a kubernetes controller which continuously monitors running applications. (will be added later)
19+
- [Laravel Telescope](): This is debug assistant for the Laravel framework. (will be added later)
20+
- [Laravel Nova](): This is admin panel for the Laravel framework. (will be added later)
21+
- [API Documentation](https://mysite.com)
22+
23+
### Contacts
24+
25+
Should you need assistance or have questions, feel free to connect with the following individuals:
26+
- Manager: If you have any high-level project concerns, feel free to get in touch with our project manager. [Connect with Manager](mailto::manager_link)
27+
- Code Owner/Team Lead: For specific questions about the codebase or technical aspects, reach out to our team lead. [Connect with Team Lead](mailto::team_lead_link)
28+
29+
Please be mindful of each individual's preferred contact method and office hours.
30+
31+
## Prerequisites
32+
33+
To work with this repository, you will need to have the following
34+
installed:
35+
36+
- [Docker](https://www.docker.com)
37+
38+
## Getting Started
39+
40+
To get started with this repository, follow these steps:
41+
42+
Clone this repository to your local machine:
43+
44+
```sh
45+
git clone https://github.com/ronasit/laravel-helpers.git
46+
```
47+
48+
Open project directory:
49+
50+
```sh
51+
cd laravel-helpers
52+
```
53+
54+
Build and start containers, it may takes some time:
55+
56+
```sh
57+
docker compose up -d
58+
```
59+
60+
## Environments
61+
62+
This repository by default supports three environments: `local`, `development`,
63+
and `testing`. Each environment is represented by an appropriate environment file:
64+
65+
| Environment | File | URL |
66+
| --- | --- |--------------------------------------|
67+
| local | .env | [http://localhost](http://localhost) |
68+
| testing | .env.testing | - |
69+
| development | .env.development | [https://mysite.com](https://mysite.com) |
70+
71+
## Credentials and Access
72+
73+
Default admin access:
74+
75+
- password `123456`
76+
77+
Laravel Telescope access:
78+
79+
- password `123456`
80+
81+
Laravel Nova access:
82+
83+
- password `123456`
84+
85+
### Renovate
86+
87+
The application uses Renovate dependabot for automatically updating dependencies. You can configure it more precisely using the `renovate.json` file. Available configuration described here https://docs.renovatebot.com/config-overview

tests/fixtures/InitCommandTest/full_readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ Laravel Telescope access:
8080

8181
Laravel Nova access:
8282
83-
- password `654321`
83+
- password `654321`

0 commit comments

Comments
 (0)