-
Notifications
You must be signed in to change notification settings - Fork 448
Add Mago as task #1216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
johnatas-x
wants to merge
3
commits into
phpro:v2.x
Choose a base branch
from
johnatas-x:mago-task
base: v2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Mago as task #1216
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| # Mago | ||
|
|
||
| The Mago task runs the Mago's toolchain. | ||
|
|
||
| ***Composer*** | ||
|
|
||
| ``` | ||
| composer require --dev carthage-software/mago | ||
| ``` | ||
|
|
||
| ***Config*** | ||
|
|
||
| The task lives under the `mago` namespace and has following configurable parameters: | ||
|
|
||
| ```yaml | ||
| # grumphp.yml | ||
| grumphp: | ||
| tasks: | ||
| mago: | ||
| formatter: ~ | ||
| formatter_options: ~ | ||
| linter: ~ | ||
| linter_options: ~ | ||
| analyzer: ~ | ||
| analyzer_options: ~ | ||
| guard: ~ | ||
| guard_options: ~ | ||
| ``` | ||
|
|
||
| **formatter** | ||
|
|
||
| *Default: `true`* | ||
|
|
||
| Enable the Mago's formatter. | ||
|
|
||
|
|
||
| **formatter_options** | ||
|
|
||
| *Default: `['--staged']`* | ||
|
|
||
| [Options](https://mago.carthage.software/tools/formatter/command-reference#options) for the `mago format` command. | ||
| Each option must be an array's element. | ||
| If the option needs a value, add it after the option name with an equal sign like this: `--option=value`. | ||
|
|
||
|
|
||
| **linter** | ||
|
|
||
| *Default: `true`* | ||
|
|
||
| Enable the Mago's linter. | ||
|
|
||
|
|
||
| **linter_options** | ||
|
|
||
| *Default: `['--staged']`* | ||
|
|
||
| [Options](https://mago.carthage.software/tools/linter/command-reference#options) for the `mago lint` command. | ||
| Each option must be an array's element. | ||
| If the option needs a value, add it after the option name with an equal sign like this: `--option=value`. | ||
|
|
||
|
|
||
| **analyzer** | ||
|
|
||
| *Default: `true`* | ||
|
|
||
| Enable the Mago's analyzer. | ||
|
|
||
|
|
||
| **analyzer_options** | ||
|
|
||
| *Default: `['--staged']`* | ||
|
|
||
| [Options](https://mago.carthage.software/tools/analyzer/command-reference#options) for the `mago analyze` command. | ||
| Each option must be an array's element. | ||
| If the option needs a value, add it after the option name with an equal sign like this: `--option=value`. | ||
|
|
||
|
|
||
| **guard** | ||
|
|
||
| *Default: `false`* | ||
|
|
||
| Enable the architectural guard. | ||
|
|
||
|
|
||
| **guard_options** | ||
|
|
||
| *Default: `[]`* | ||
|
|
||
| [Options](https://mago.carthage.software/tools/guard/command-reference#options) for the `mago guard` command. | ||
| Each option must be an array's element. | ||
| If the option needs a value, add it after the option name with an equal sign like this: `--option=value`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace GrumPHP\Task; | ||
|
|
||
| use GrumPHP\Formatter\ProcessFormatterInterface; | ||
| use GrumPHP\Runner\TaskResult; | ||
| use GrumPHP\Runner\TaskResultInterface; | ||
| use GrumPHP\Task\Config\ConfigOptionsResolver; | ||
| use GrumPHP\Task\Context\ContextInterface; | ||
| use GrumPHP\Task\Context\GitPreCommitContext; | ||
| use GrumPHP\Task\Context\RunContext; | ||
| use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
|
||
| /** | ||
| * @extends AbstractExternalTask<ProcessFormatterInterface> | ||
| */ | ||
| class Mago extends AbstractExternalTask | ||
| { | ||
|
|
||
| public static function getConfigurableOptions(): ConfigOptionsResolver | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed when abstract. |
||
| { | ||
| $resolver = new OptionsResolver(); | ||
| $resolver->setDefaults([ | ||
| 'formatter' => true, | ||
| 'formatter_options' => ['--staged'], | ||
|
johnatas-x marked this conversation as resolved.
Outdated
|
||
| 'linter' => true, | ||
| 'linter_options' => ['--staged'], | ||
| 'analyzer' => true, | ||
| 'analyzer_options' => ['--staged'], | ||
| 'guard' => false, | ||
| 'guard_options' => [], | ||
| ]); | ||
|
|
||
| $resolver->addAllowedTypes('formatter', ['bool']); | ||
| $resolver->addAllowedTypes('formatter_options', ['array']); | ||
|
johnatas-x marked this conversation as resolved.
Outdated
|
||
| $resolver->addAllowedTypes('linter', ['bool']); | ||
| $resolver->addAllowedTypes('linter_options', ['array']); | ||
| $resolver->addAllowedTypes('analyzer', ['bool']); | ||
| $resolver->addAllowedTypes('analyzer_options', ['array']); | ||
| $resolver->addAllowedTypes('guard', ['bool']); | ||
| $resolver->addAllowedTypes('guard_options', ['array']); | ||
|
|
||
| return ConfigOptionsResolver::fromOptionsResolver($resolver); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function canRunInContext(ContextInterface $context): bool | ||
| { | ||
| return $context instanceof GitPreCommitContext || $context instanceof RunContext; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function run(ContextInterface $context): TaskResultInterface | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed when abstract. |
||
| { | ||
| $config = $this->getConfig()->getOptions(); | ||
|
|
||
| if ($config['formatter'] === false | ||
|
johnatas-x marked this conversation as resolved.
Outdated
|
||
| && $config['linter'] === false | ||
| && $config['analyzer'] === false | ||
| && $config['guard'] === false) { | ||
| return TaskResult::createSkipped($this, $context); | ||
| } | ||
|
|
||
| $commandMap = [ | ||
| 'formatter' => 'fmt', | ||
| 'linter' => 'lint', | ||
| 'analyzer' => 'analyze', | ||
| 'guard' => 'guard', | ||
| ]; | ||
|
|
||
| foreach ($commandMap as $configKey => $command) { | ||
| if ($config[$configKey] !== true) { | ||
| continue; | ||
| } | ||
|
|
||
| $arguments = $this->processBuilder->createArgumentsForCommand('mago'); | ||
| $arguments->add($command); | ||
|
|
||
| $arguments->addArgumentArray('%s', $config[$configKey . '_options']); | ||
|
|
||
| $process = $this->processBuilder->buildProcess($arguments); | ||
| $process->run(); | ||
|
|
||
| if (!$process->isSuccessful()) { | ||
| return TaskResult::createFailed($this, $context, $this->formatter->format($process)); | ||
| } | ||
| } | ||
|
|
||
| return TaskResult::createPassed($this, $context); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better to have it abstract as wel? There is no such thing as a mago task