-
Notifications
You must be signed in to change notification settings - Fork 28
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
Fix relative paths failing to resolve in diffs #11
Conversation
The previous implementation used git difftool to automatically run a script against the files that had changed. git difftool automatically created copies of the files being diffed in a temporary location, but did not copy rest of the project, causing relative paths to no longer resolve. This change removes the use of git difftool, and instead exports a copy of the repo at the pull request target before invoking the diff generator on the changed VIs. This allows relative paths to be resolved correctly, leading to nicer diffs. This change also enables generating diffs for .vit and .vim files.
I did some additional configuration work on one of the custom devices (making it pull in the testing tools through a submodule) to demonstrate these changes working. Here is a diff with the testing tools being loaded from a submodule and resolving correctly. |
Previously we were only importing it on error, since this script was called once per file by git difftool. Now that it is only called once, we should import traceback at the top level.
This is cleaner than changing the working directory of the parent process twice.
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.
Looks good to me. My python is only passable, but I don't see anything glaring.
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.
just some thoughts . . .
traceback.print_exc() | ||
|
||
with open(working_dir + "\\diff_failures.txt", "a+") as file: | ||
file.write(vi1 + "\n") | ||
with open(output_dir + "\\diff_failures.txt", "a+") 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.
os.path.join . . .
# and the temporary directory can be returned directly | ||
for root, dirs, files in os.walk(directory.name): | ||
for file in files: | ||
os.chmod(root + "/" + file, stat.S_IWRITE) |
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.
os.path.join . . .
|
||
with export_repo(target_branch) as directory: | ||
for status, filename in diffs: | ||
if status == "A": |
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.
"A" ?? this should probably be an enum (if status == difModes.Add.value)
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 was debating between adding a type and leaving it as a string. We're parsing this from git's output, and we get them back as "A" and "M". Adding a type would make it a little more robust. Good catch.
What does this Pull Request accomplish?
Fix diffs not resolving relative paths properly.
The previous implementation used git difftool to automatically run a
script against the files that had changed. git difftool automatically
created copies of the files being diffed in a temporary location, but
did not copy rest of the project, causing relative paths to no longer
resolve.
This change removes the use of git difftool, and instead exports a copy
of the repo at the pull request target before invoking the diff
generator on the changed VIs. This allows relative paths to be resolved
correctly, leading to nicer diffs.
This change also enables generating diffs for .vit and .vim files. Fixes #10.
This change also makes running the diffing code locally easier, by pushing
environment variable handling into the Groovy layer and adding argument
parsing to the Python layer.
Why should this Pull Request be merged?
This makes the diffs look a lot nicer, and be significantly more useful.
What testing has been done?
Building a custom device pull request: http://coordinator/job/VeriStand/job/rtzoeller/job/niveristand-chassis-timesync-custom-device/view/change-requests/job/PR-2/18/
Resulting diff bot post: https://github.com/rtzoeller/niveristand-chassis-timesync-custom-device/pull/2