|
24 | 24 | use Symfony\Component\Console\Output\OutputInterface; |
25 | 25 | use Symfony\Component\Filesystem\Path; |
26 | 26 | use Symfony\Component\Finder\Finder; |
| 27 | +use Symfony\Component\Process\Process; |
27 | 28 |
|
28 | 29 | /** |
29 | 30 | * Represents the command responsible for installing development scripts into `composer.json`. |
@@ -69,6 +70,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int |
69 | 70 | $this->updateComposerJson(); |
70 | 71 | $this->createGitHubActionWorkflows(); |
71 | 72 | $this->copyEditorConfig(); |
| 73 | + $this->addRepositoryWikiGitSubmodule(); |
72 | 74 |
|
73 | 75 | return self::SUCCESS; |
74 | 76 | } |
@@ -164,4 +166,42 @@ private function copyEditorConfig(): void |
164 | 166 | $content = $this->filesystem->readFile($source); |
165 | 167 | $this->filesystem->dumpFile($target, $content); |
166 | 168 | } |
| 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 | + } |
167 | 207 | } |
0 commit comments