Skip to content

Commit

Permalink
Use CiDetector
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtARTs36 committed Nov 16, 2021
1 parent 58d62da commit a2cc80d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"illuminate/config": "^8.0",
"illuminate/console": "^8.0",
"illuminate/filesystem": "^8.69",
"illuminate/support": "^8.0"
"illuminate/support": "^8.0",
"ondram/ci-detector": "^4.1"
},
"require-dev": {
"squizlabs/php_codesniffer": "*"
Expand Down
8 changes: 5 additions & 3 deletions src/Ports/Console/GenerateDocCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@
use ArtARTs36\ArtisanDocumentator\Support\Repo;
use Illuminate\Console\Command;
use Illuminate\Contracts\Config\Repository;
use OndraM\CiDetector\CiDetector;
use OndraM\CiDetector\CiDetectorInterface;

class GenerateDocCommand extends Command
{
protected $signature = 'command:doc {path} {--documentator=} {--ci}';

protected $description = 'Generate commands documentation';

public function handle(DocGenerator $generator, Repository $config, Repo $repo)
public function handle(DocGenerator $generator, Repository $config, Repo $repo, CiDetector $ciDetector)
{
$modified = $generator->generate(
$this->option('documentator') ?? $config->get('artisan_documentator.documentators.default'),
$path = $this->argument('path')
);

if ($this->option('ci') && $modified) {
$repo->commitAndPush($path);
if ($this->option('ci') && $ciDetector->isCiDetected() && $modified) {
$repo->commitAndPush($path, $ciDetector->detect()->getBranch());
}
}
}
6 changes: 3 additions & 3 deletions src/Support/Repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public function __construct(
//
}

public function commitAndPush(string $path): void
public function commitAndPush(string $path, string $branch): void
{
$this->git->index()->add($path);
$this->git->commits()->commit($this->message);

$this->git->pushes()->send(function (MakingPush $push) {
$this->git->pushes()->send(function (MakingPush $push) use ($branch) {
$push->onRemote(function (UriInterface $uri) {
return $uri->withUserInfo($this->login, $this->token);
})->onSetUpStream()->onCurrentBranchHead();
})->onSetUpStream()->onBranchHead($branch);
});
}
}

0 comments on commit a2cc80d

Please sign in to comment.