Skip to content

Commit 1a14ecc

Browse files
committed
Adds support to ensure that the repository wiki is added as a git submodule in .github/wiki during the installation of dev-tools scripts.
Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
1 parent e79878e commit 1a14ecc

3 files changed

Lines changed: 42 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ composer dev-tools wiki
5252
# Generate documentation frontpage and related reports
5353
composer dev-tools reports
5454

55-
# Installs and synchronizes dev-tools scripts, GitHub Actions workflows, and .editorconfig
55+
# Installs and synchronizes dev-tools scripts, GitHub Actions workflows, .editorconfig, and ensures the repository wiki is present as a git submodule in .github/wiki
5656
composer dev-tools install
5757
```
5858

docs/running/specialized-commands.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Structurally consolidates distinct reporting commands, accurately aggregating te
7676
8. Install (``install``)
7777
------------------------
7878

79-
Adds or updates dev-tools scripts in your ``composer.json``, copies reusable GitHub Actions workflows, and ensures the ``.editorconfig`` file is present and up to date. This command helps standardize your team's workflow and automation setup.
79+
Adds or updates dev-tools scripts in your ``composer.json``, copies reusable GitHub Actions workflows, ensures the ``.editorconfig`` file is present and up to date, and guarantees the repository wiki is present as a git submodule in ``.github/wiki``. This command helps standardize your team's workflow and automation setup.
8080

8181
.. code-block:: bash
8282

src/Command/InstallCommand.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Symfony\Component\Console\Output\OutputInterface;
2525
use Symfony\Component\Filesystem\Path;
2626
use Symfony\Component\Finder\Finder;
27+
use Symfony\Component\Process\Process;
2728

2829
/**
2930
* Represents the command responsible for installing development scripts into `composer.json`.
@@ -69,6 +70,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6970
$this->updateComposerJson();
7071
$this->createGitHubActionWorkflows();
7172
$this->copyEditorConfig();
73+
$this->addRepositoryWikiGitSubmodule();
7274

7375
return self::SUCCESS;
7476
}
@@ -164,4 +166,42 @@ private function copyEditorConfig(): void
164166
$content = $this->filesystem->readFile($source);
165167
$this->filesystem->dumpFile($target, $content);
166168
}
169+
170+
/**
171+
* Ensures the repository wiki is added as a git submodule in .github/wiki.
172+
*
173+
* This method checks if the .github/wiki directory exists. If not, it adds the repository's wiki as a submodule
174+
* using the remote origin URL, replacing .git with .wiki.git. This allows automated documentation and wiki updates.
175+
*
176+
* @return void
177+
*/
178+
private function addRepositoryWikiGitSubmodule(): void
179+
{
180+
$repositoryUrl = $this->getGitRepositoryUrl();
181+
182+
$wikiRepoUrl = str_replace('.git', '.wiki.git', $repositoryUrl);
183+
$wikiSubmodulePath = $this->getConfigFile('.github/wiki', true);
184+
185+
if ($this->filesystem->exists($wikiSubmodulePath)) {
186+
return;
187+
}
188+
189+
$process = new Process(['git', 'submodule', 'add', $wikiRepoUrl, $wikiSubmodulePath]);
190+
$process->mustRun();
191+
}
192+
193+
/**
194+
* Retrieves the git remote origin URL for the current repository.
195+
*
196+
* This method runs 'git config --get remote.origin.url' and returns the trimmed output.
197+
*
198+
* @return string The remote origin URL of the repository
199+
*/
200+
private function getGitRepositoryUrl(): string
201+
{
202+
$process = new Process(['git', 'config', '--get', 'remote.origin.url']);
203+
$process->mustRun();
204+
205+
return trim($process->getOutput());
206+
}
167207
}

0 commit comments

Comments
 (0)