Skip to content
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

Programming exercises: Fix diff view for renamed files #8634

Merged
merged 14 commits into from
May 21, 2024

Conversation

pzdr7
Copy link
Contributor

@pzdr7 pzdr7 commented May 19, 2024

Checklist

General

Server

  • Important: I implemented the changes with a very good performance and prevented too many (unnecessary) database calls.
  • I strictly followed the server coding and design guidelines.
  • I added multiple integration tests (Spring) related to the features (with a high test coverage).

Client

  • Important: I implemented the changes with a very good performance, prevented too many (unnecessary) REST calls and made sure the UI is responsive, even with large data.
  • I strictly followed the client coding and design guidelines.
  • I added multiple integration tests (Jest) related to the features (with a high test coverage), while following the test guidelines.
  • I added multiple screenshots/screencasts of my UI changes.
  • I translated all newly inserted strings into English and German.

Changes affecting Programming Exercises

  • High priority: I tested all changes and their related features with all corresponding user types on a test server configured with the integrated lifecycle setup (LocalVC and LocalCI).

Motivation and Context

During the review of #8540, I noticed that renaming files wasn't working as expected when viewing commit details. This had two causes:

  • Renamed files that had no diff blocks were not mentioned in the generated diff report.
  • For renamed and modified files, the wrong "before" content was shown (we used the updated file path)

Description

  • We now explicitly track the renamed files in the server and add corresponding diff entries if needed
  • We now use the correct file content when displaying renamed & modified files.
  • For renamed and otherwise unchanged files, we now display a placeholder

When processing the diff, we now keep track of entries like this:

diff --git a/src/de/tum/cit/ase/Client2.java b/src/de/tum/cit/ase/Client23.java
similarity index 98%
rename from src/de/tum/cit/ase/Client2.java
rename to src/de/tum/cit/ase/Client23.java

Steps for Testing

Prerequisites:

  • Test Server with LocalVC enabled
  • 1 Student
  • 1 Programming exercise (clone the repository; it'll be easier to verify that this feature works correctly)
  1. Log in and navigate to the programming exercise
  2. Clone the repository
  3. Take a file and change 1-2 lines, then rename the file. (Note: it's important that you do not change too many lines; otherwise, git will not be able to track the rename. If you're unsure: you should get something like rename src/de/tum/cit/ase/{WillRename.java => HaveRenamed.java} (82%) when committing using the command line)
  4. Commit your changes.
  5. Rename the file again, this time without changing its content.
  6. Commit your changes.
  7. Make some other changes, e.g. delete / create / modify some files.
  8. Commit your changes.
  9. Push your changes.
  10. On Artemis, click "Open repository," then open the commit history.
  11. Verify for each commit that your changes were tracked and are displayed correctly.

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked






Review Progress

Performance Review

  • I (as a reviewer) confirm that the client changes (in particular related to REST calls and UI responsiveness) are implemented with a very good performance
  • I (as a reviewer) confirm that the server changes (in particular related to database calls) are implemented with a very good performance

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Test Coverage

Client

Class/File Line Coverage Confirmation (assert/expect)
git-diff-file.component.ts 100%
git-diff-report.component.ts 100%

Server

Class/File Line Coverage Confirmation (assert/expect)
GitDiffReportParserService.java 86%

Screenshots

image
image

@github-actions github-actions bot added tests server Pull requests that update Java code. (Added Automatically!) client Pull requests that update TypeScript code. (Added Automatically!) labels May 19, 2024
@pzdr7 pzdr7 changed the title Programming exercises: Improve diff view of renamed files Programming exercises: Fix diff view of renamed files May 19, 2024
@pzdr7 pzdr7 temporarily deployed to artemis-test1.artemis.cit.tum.de May 19, 2024 18:39 — with GitHub Actions Inactive
@pzdr7 pzdr7 marked this pull request as ready for review May 20, 2024 16:27
@pzdr7 pzdr7 requested a review from a team as a code owner May 20, 2024 16:27
Copy link

coderabbitai bot commented May 20, 2024

Walkthrough

The recent update enhances the handling of file renaming in Git diffs within the GitDiffReportParserService, ensuring renamed files without changes are properly represented. Additionally, the web application's components now display messages for unchanged files and track renamed file paths. Test cases have been added to validate these functionalities, and new translations for the "No changes to file content" message have been included.

Changes

File Path Change Summary
src/main/java/.../GitDiffReportParserService.java Added logic to handle file renaming in Git diffs, including new constants and a map for renamed file paths. Modified the extractDiffEntries method.
src/main/webapp/app/exercises/programming/hestia/git-diff-report/... Updated HTML and TypeScript components to display messages for unchanged files and handle renamed file paths.
src/main/webapp/i18n/.../repository.json Added new translation key-value pairs for "No changes to file content" in both English and German.
src/test/java/.../ProgrammingExerciseGitDiffReportIntegrationTest.java Added a new test method to simulate file renaming and test Git diff report functionality.
src/test/java/.../HestiaUtilTestService.java Added a new method to delete a file, update Git, and set up a submission.
src/test/javascript/spec/.../git-diff-report.component.spec.ts Added a test case to verify the handling of renamed files in the Git diff report component.

Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between bd9d7d0 and 4f5e7e0.
Files selected for processing (10)
  • src/main/java/de/tum/in/www1/artemis/web/rest/GitDiffReportParserService.java (4 hunks)
  • src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file.component.html (1 hunks)
  • src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file.component.ts (1 hunks)
  • src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-report.component.html (1 hunks)
  • src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-report.component.ts (2 hunks)
  • src/main/webapp/i18n/de/repository.json (1 hunks)
  • src/main/webapp/i18n/en/repository.json (1 hunks)
  • src/test/java/de/tum/in/www1/artemis/hestia/ProgrammingExerciseGitDiffReportIntegrationTest.java (3 hunks)
  • src/test/java/de/tum/in/www1/artemis/util/HestiaUtilTestService.java (1 hunks)
  • src/test/javascript/spec/component/hestia/git-diff-report/git-diff-report.component.spec.ts (1 hunks)
Files not reviewed due to errors (1)
  • src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file.component.html (no review received)
Files skipped from review due to trivial changes (3)
  • src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file.component.ts
  • src/main/webapp/i18n/en/repository.json
  • src/test/javascript/spec/component/hestia/git-diff-report/git-diff-report.component.spec.ts
Additional Context Used
Path-based Instructions (7)
src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file.component.html (1)

Pattern src/main/webapp/**/*.html: @if and @for are new and valid Angular syntax replacing *ngIf and *ngFor. They should always be used over the old style.

src/main/webapp/i18n/de/repository.json (1)

Pattern src/main/webapp/i18n/de/**/*.json: German language translations should be informal (dutzen) and should never be formal (sietzen). So the user should always be addressed with "du/dein" and never with "sie/ihr".

src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-report.component.html (1)

Pattern src/main/webapp/**/*.html: @if and @for are new and valid Angular syntax replacing *ngIf and *ngFor. They should always be used over the old style.

src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-report.component.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

src/main/java/de/tum/in/www1/artemis/web/rest/GitDiffReportParserService.java (1)

Pattern src/main/java/**/*.java: naming:CamelCase; principles:{single_responsibility,small_methods,no_duplication}; db:{perf_queries,datetime_not_timestamp}; rest:{stateless,singleton,delegate_logic,http_only,minimal_dtos}; dtos:{java_records,no_entities,min_data,single_resp}; di:constructor_injection; kiss:simple_code; file_handling:os_indep_paths; practices:{least_access,avoid_transactions,code_reuse,static_member_ref,prefer_primitives}; sql:{param_annotation,uppercase,avoid_subqueries};java:avoid_star_imports

src/test/java/de/tum/in/www1/artemis/hestia/ProgrammingExerciseGitDiffReportIntegrationTest.java (1)

Pattern src/test/java/**/*.java: test_naming: descriptive; test_size: small_specific; fixed_data: true; junit5_features: true; assert_use: assertThat; assert_specificity: true; archunit_use: enforce_package_rules; db_query_count_tests: track_performance; util_service_factory_pattern: true; avoid_db_access: true; mock_strategy: static_mocks; context_restart_minimize: true

src/test/java/de/tum/in/www1/artemis/util/HestiaUtilTestService.java (1)

Pattern src/test/java/**/*.java: test_naming: descriptive; test_size: small_specific; fixed_data: true; junit5_features: true; assert_use: assertThat; assert_specificity: true; archunit_use: enforce_package_rules; db_query_count_tests: track_performance; util_service_factory_pattern: true; avoid_db_access: true; mock_strategy: static_mocks; context_restart_minimize: true

Additional comments not posted (6)
src/main/webapp/i18n/de/repository.json (1)

15-16: The added German localization keys are correctly formatted and use informal language as specified.

src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-report.component.html (1)

74-74: The data binding for templateFileContent correctly utilizes the renamedFilePaths map to handle renamed files.

src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-report.component.ts (1)

38-38: The addition of the renamedFilePaths property and its usage in the ngOnInit method are correctly implemented to track and handle renamed files.

Also applies to: 89-94

src/main/java/de/tum/in/www1/artemis/web/rest/GitDiffReportParserService.java (1)

22-24: The addition of constants for handling renamed files and the logic in extractDiffEntries to track and handle these files, including adding empty diff entries, are correctly implemented.

Also applies to: 38-80

src/test/java/de/tum/in/www1/artemis/hestia/ProgrammingExerciseGitDiffReportIntegrationTest.java (1)

140-158: The new test method getGitDiffReportForCommitsWithRenamedFile correctly simulates the renaming of a file and includes appropriate assertions to verify the behavior.

src/test/java/de/tum/in/www1/artemis/util/HestiaUtilTestService.java (1)

191-198: The method deleteFileAndSetupSubmission correctly handles the deletion of a file and the setup of a submission, which is essential for testing scenarios involving renamed files.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Jan-Thurner Jan-Thurner temporarily deployed to artemis-test1.artemis.cit.tum.de May 20, 2024 17:11 — with GitHub Actions Inactive
Copy link
Contributor

@florian-glombik florian-glombik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Followed the testing steps on ts1, worked as described - all commits and respective changes are displayed, the files are labeled properly

Second Test logs
florianglombik@MBP-von-Florian ge25bastestcoursevisbilitytest-ge25bas % git add .
florianglombik@MBP-von-Florian ge25bastestcoursevisbilitytest-ge25bas % git commit -m "step 3"
[main 09e74b5] step 3
 1 file changed, 1 insertion(+), 1 deletion(-)
 rename src/in/tum/test/{BubbleSort.java => BubbleSortChangeLineAndFileName.java} (83%)
florianglombik@MBP-von-Florian ge25bastestcoursevisbilitytest-ge25bas % git add .
florianglombik@MBP-von-Florian ge25bastestcoursevisbilitytest-ge25bas % git commit -m "step 5"
[main 9fe3542] step 5
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename src/in/tum/test/{BubbleSortChangeLineAndFileName.java => BubbleSort1234.java} (100%)
florianglombik@MBP-von-Florian ge25bastestcoursevisbilitytest-ge25bas % git add .
florianglombik@MBP-von-Florian ge25bastestcoursevisbilitytest-ge25bas % git commit -m "step 8"
[main 492c396] step 8
 3 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 src/in/tum/test/MergeSort1.java
 create mode 100644 src/in/tum/test/NewMergeSort.java
florianglombik@MBP-von-Florian ge25bastestcoursevisbilitytest-ge25bas % git push
Enumerating objects: 28, done.
Counting objects: 100% (28/28), done.
Delta compression using up to 10 threads
Compressing objects: 100% (13/13), done.
Writing objects: 100% (22/22), 1.79 KiB | 1.79 MiB/s, done.
Total 22 (delta 5), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (5/5)
remote: Updating references: 100% (1/1)

I might have found another issue in my first testing attempt, it might not be directly related since I had some conflict with the code editor that I've noticed in the last testing step.

As I didn't review the code I do not know if it is related to the changed: MergeSort2 and MergeSort3 are created and not renamed (see logs below)

Steps to reproduce: #8634 (comment)

image

Screenshots and further information

image
Commit that is not displayed properly https://artemis-test1.artemis.cit.tum.de/courses/12/exercises/72/repository/199/commit-history/4f239016dc8e2d181c823787b1a5c1a024f6a164

Repository https://artemis-test1.artemis.cit.tum.de/courses/12/exercises/72/repository/199

First Test logs
florianglombik@MBP-von-Florian ge25bastestcoursecheckoutdirectoriesjava-ge25bas % git add .
florianglombik@MBP-von-Florian ge25bastestcoursecheckoutdirectoriesjava-ge25bas % git commit -m "renamed file"
[main d241c0e] renamed file
 1 file changed, 2 insertions(+), 2 deletions(-)
 rename src/packageName/{BubbleSort.java => AmazingBubbleSort.java} (81%)
florianglombik@MBP-von-Florian ge25bastestcoursecheckoutdirectoriesjava-ge25bas % git add .
florianglombik@MBP-von-Florian ge25bastestcoursecheckoutdirectoriesjava-ge25bas % git commit -m "rename the file a second time"
[main b9b8684] rename the file a second time
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename src/packageName/{AmazingBubbleSort.java => AmazingButNotIncredibleBubbleSort.java} (100%)
florianglombik@MBP-von-Florian ge25bastestcoursecheckoutdirectoriesjava-ge25bas % git add .
florianglombik@MBP-von-Florian ge25bastestcoursecheckoutdirectoriesjava-ge25bas % git add .
florianglombik@MBP-von-Florian ge25bastestcoursecheckoutdirectoriesjava-ge25bas % git commit -m "adding, deleting and modifying files"
[main 4f23901] adding, deleting and modifying files
 4 files changed, 40 insertions(+), 3 deletions(-)
 rename src/packageName/{MergeSort.java => MergeSort1.java} (75%)
 create mode 100644 src/packageName/MergeSort2.java
 create mode 100644 src/packageName/MergeSort3.java
florianglombik@MBP-von-Florian ge25bastestcoursecheckoutdirectoriesjava-ge25bas % git push
Enumerating objects: 21, done.
Counting objects: 100% (21/21), done.
Delta compression using up to 10 threads
Compressing objects: 100% (14/14), done.
Writing objects: 100% (17/17), 1.54 KiB | 1.54 MiB/s, done.
Total 17 (delta 8), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (8/8)
remote: Updating references: 100% (1/1)
To https://artemis-test1.artemis.cit.tum.de/git/GE25BASTESTCOURSECHECKOUTDIRECTORIESJAVA/ge25bastestcoursecheckoutdirectoriesjava-ge25bas.git
   fae4ba0..4f23901  main -> main

@florian-glombik
Copy link
Contributor

I investigated how to reproduce it:

  1. Copy the MergeSort template file and name the new File and Class MergeSort1
  2. Copy the MergeSort template file and name the new File and Class MergeSort2
  3. Copy the MergeSort template file and name the new File and Class MergeSort3
  4. Delete the the MergeSort template file
  5. See that all MergeSorts are displayed as renamed even though git labels MergeSort2 and MergeSort3 with created

@pzdr7
Copy link
Contributor Author

pzdr7 commented May 21, 2024

@florian-glombik Good catch! Basically, the copy detection of Git is producing diff entries that the Client interprets as renaming. At the moment, we cannot distinguish between copying and moving.

@krusche and I have discussed this and decided that we'll handle it in in a separate PR (we may be able to add some transient fields to the diff report or the diff enteries that carry this information)

Copy link

⚠️ Unable to deploy to test servers ⚠️

The docker build needs to run through before deploying.

@github-actions github-actions bot added the deployment-error Added by deployment workflows if an error occured label May 21, 2024
@pzdr7 pzdr7 removed the deployment-error Added by deployment workflows if an error occured label May 21, 2024
Copy link
Contributor

@rabeatwork rabeatwork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintainer approved

@krusche krusche changed the title Programming exercises: Fix diff view of renamed files Programming exercises: Fix diff view for renamed files May 21, 2024
@krusche krusche added this to the 7.1.0 milestone May 21, 2024
@krusche krusche merged commit 88fba9a into develop May 21, 2024
32 of 40 checks passed
@krusche krusche deleted the bugfix/programming-exercises/renamed-file-diff branch May 21, 2024 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client Pull requests that update TypeScript code. (Added Automatically!) ready for review server Pull requests that update Java code. (Added Automatically!) tests
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

8 participants