-
Notifications
You must be signed in to change notification settings - Fork 12
Do not fetch file diff if updated file has no messages #54
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
Conversation
| if ($isNewFile) { | ||
| $debug('Skipping the linting of the orig file version as it is a new file.'); | ||
| } else { | ||
| $debug('Skipping the linting of the orig file version as the new version of the file contains no lint errors.'); |
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.
This logging is handled by the above throw and the below catch.
| if ($isNewFile) { | ||
| $debug('Skipping the linting of the orig file version as it is a new file.'); | ||
| } else { | ||
| $debug('Skipping the linting of the orig file version as the new version of the file contains no lint errors.'); |
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.
This logging is handled by the above throw and the below catch.
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.
Very elegant solution, which allowed a code serving the mere purpose of debugging messaging to be removed. Nice!
| $debug('git status output:', $gitStatusOutput); | ||
| if (! $gitStatusOutput || false === strpos($gitStatusOutput, $gitFile)) { | ||
| throw new ShellException("Cannot get git status for file '{$gitFile}'"); | ||
| return false; |
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'm not sure how this worked before, since git status file.php will be an empty string for an already existing file.
| $shell->registerCommand("cat 'foobar.php' | phpcs", $this->phpcs->getEmptyResults()->toPhpcsJson()); | ||
|
|
||
| $options = [ | ||
| 'no-cache-git-root' => 1, |
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.
This allows us to test without the static variable caching operating.
| $hasNewPhpcsMessages = !empty($newFilePhpcsMessages->getMessages()); | ||
|
|
||
| if (! $hasNewPhpcsMessages) { | ||
| throw new NoChangesException("New file '{$svnFile}' has no PHPCS messages; skipping"); |
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.
It's not an issue of this PR, but we seem to be using "new file" in multiple meanings across the codebase, which might be confusing when reading the output.
Perhaps we should be using "new version of the {$svnFile}" here, similarly to line 272 where "old file version" is used. And limit the usage of "new file" to newly added file? Or perhaps even better, use "newly added file" instead of "new file"?
Edit: The same goes for "old file", where "old version of" might be more appropriate. And while nitpicking about the messaging, perhaps "previous version" might be better. Not sure, tho, if "new" should be replaced by something like "current/working"
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.
Yeah, I agree! I realized this same issue when working on this PR and I wanted to go through and rename everything, but I decided it would be better for a different PR. I'll get that next.
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.
Good job at refactoring the diff generation to situations where it's really necesary.
I also love all the minor touches to the code readability.
I have also manually tested the code, and it seems to work well.
| $fileName = $shell->getFileNameFromPath($gitFile); | ||
| $newFilePhpcsMessages = PhpcsMessages::fromPhpcsJson($newFilePhpcsOutput, $fileName); | ||
| $hasNewFilePhpcsIssues = !empty($newFilePhpcsMessages->getMessages()); | ||
| $hasNewPhpcsMessages = !empty($newFilePhpcsMessages->getMessages()); |
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 like the new variable name way better than the old one, makes the code more readable.
| if ($isNewFile) { | ||
| $debug('Skipping the linting of the orig file version as it is a new file.'); | ||
| } else { | ||
| $debug('Skipping the linting of the orig file version as the new version of the file contains no lint errors.'); |
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.
Very elegant solution, which allowed a code serving the mere purpose of debugging messaging to be removed. Nice!
This is a follow-up to #51, which modifies the automatic mode workflows so that they do not run phpcs on the previous version of a file if the current version has no phpcs messages; in this PR we modify them further to also not generate a VCS diff of the file in that case.
Fixes #53
To do: