-
Notifications
You must be signed in to change notification settings - Fork 430
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
Pre push testsuites #1136
base: v2.x
Are you sure you want to change the base?
Pre push testsuites #1136
Conversation
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.
Thanks @saidatom,
I've quickly skimmed through the code and added some pointers / questions.
Beside the review comments, A lot of tests are missing at the moment.
/** | ||
* @var StdInFiles | ||
*/ | ||
private $stdInFilesLocator; |
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.
The STDIN files locator is not being used
{ | ||
$this->setDescription('Executed by the pre-push hook'); | ||
$this->addOption( | ||
'skip-success-output', |
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.
should output be ever skipped?
For pre-commit, this is the case because the commit-msg runs in the same git commit command, just behind the other hook.
|
||
public function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$localRef = $this->changedFilesLocator->getLocalRef(); |
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.
I think we need to introduce a new PushedFiles locator which contains all of this logic and the getPushedFiles()
logic. Pollution the ChangedFiles locator doesn't seem like a good idea here.
By moving it to its own locator, you can keep these specific git details "hidden" and just use the pushed files from this command.
I'm not sure how it behaves exactly, but I'm sure test-cases will be added to show how it works exactly.
function (): ?string { | ||
return $this->repository->run('rev-parse', ['--abbrev-ref', '--symbolic-full-name', '@{u}']); | ||
}, | ||
'null' |
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.
having a 'null'
string doesn't seem like a good idea. Instead maybe use null
?
return null; | ||
} | ||
/** | ||
* @psalm-suppress PossiblyUndefinedArrayOffset |
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 validate the format and return null if it's unexpected?
@@ -75,6 +135,6 @@ private function makeFileRelativeToProjectDir(File $file): SplFileInfo | |||
$file->isRename() ? $file->getNewName() : $file->getName() | |||
); | |||
|
|||
return new SplFileInfo($filePath, dirname($filePath), $filePath); | |||
return new SplFileInfo($filePath); |
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.
any specific reason why this was changed?
return new FilesCollection($files); | ||
} | ||
|
||
foreach (explode("\n", $diff) as $file) { |
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.
would this always be \n
or \r\n
dependeing on the system?
@@ -36,7 +37,9 @@ public static function getConfigurableOptions(): ConfigOptionsResolver | |||
|
|||
public function canRunInContext(ContextInterface $context): bool | |||
{ | |||
return $context instanceof GitPreCommitContext || $context instanceof RunContext; | |||
return $context instanceof GitPreCommitContext |
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.
By default, this will run the task in both pre-commit and pre-push scenario?
I think that might be a bit too much for a lot of people.
Would it make sense to have a new metadata field that can be used to change the context instead?
See https://github.com/phpro/grumphp/blob/v2.x/doc/tasks.md#metadata
Something like:
grumphp:
tasks:
anytask:
metadata:
git_stage: ["pre-commit", "pre-push"]
Which can be used to specify at what stages in your git flow you want to run this task.
The canRunInContext will then by based on the metadata configuration, which will default to ["pre-commit"]
.
WDYT?
/** | ||
* @return FilesCollection | ||
*/ | ||
public function locateFromGitDiff(string $fromSha, ?string $toSha): FilesCollection |
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.
What worries me a bit, is that there seem to be a lot of different states possible which require slightly different approaches / solutions.
How sure are you that all possible situations are covered?
Maybe the new PushedFiled locator should also contain details on how it works and what it covers exactly.
return $this->changedFilesLocator->locateFromRawDiffInput('HEAD'); | ||
} | ||
|
||
if ($localRef === '(delete)') { |
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.
should the task run if you delete a branch ?
It is an experiment to get the #1135 working, actually there is the problem that if we have a grumphp.yml like that:
New Task Checklist:
run()
method readable?run()
method using the configuration correctly?