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

[WIP] Happy days git integration wp3 #12773

Draft
wants to merge 83 commits into
base: gitintegration
Choose a base branch
from

Conversation

11raphael
Copy link
Contributor

This PR addresses Working Package 3 for #12350

We shall go through org.jabref.model.database.BibDatabaseContext to execute on-save functionality.

We have decided to instead execute on-save functionality as a single line method call in org/jabref/gui/exporter/SaveDatabaseAction.java

“With regards to implementing preferences- we shall proceed with adding preferences to the current 'Saving' under the "General" tab as suggested. If the segment gets cluttered we shall opt for a new "Saving" tab.”

We have currently added git preferences under “Saving” in “General”. Is this okay? And if not should we proceed to making a new segment for it in preferences?
image
image

Small architecture concern: We opted to pass preferences information into GitHandler through method updateCredentials but are unsure if this is good practice.

Mandatory checks

  • I own the copyright of the code submitted and I licence it under the MIT license
  • Change in CHANGELOG.md described in a way that is understandable for the average user (if change is visible to the user)
  • [x ] Tests created for changes (if applicable)
  • [x ] Manually tested changed features in running JabRef (always required)
  • [ x] Screenshots added in PR description (if change is visible to the user)
  • [ x] Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • [ x] Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

RapidShotzz and others added 30 commits February 26, 2025 13:09
Update GitHandler constructor to optionally not create a repository if
none exists
…d-pull' into library-under-version-control-and-pull

# Conflicts:
#	src/test/java/org/jabref/gui/importer/actions/CheckForVersionControlActionTest.java
removed the logic that required the download of additional libraries/dependencies
…d-pull' into library-under-version-control-and-pull

# Conflicts:
#	src/main/java/org/jabref/logic/preferences/CliPreferences.java
11raphael and others added 2 commits March 18, 2025 15:22
- Checkstyle issue in GitPreferences.java fixed. (Incorrect import order)
- Broad catch blocks in GitPullAction and GitPushAction fixed
- Also fixed incorrect logger usage.
Comment on lines 35 to 38
BibDatabaseContext databaseContext = stateManager.getActiveDatabase().get();
if (stateManager.getActiveDatabase().isEmpty()) {
return;
}
Copy link

Choose a reason for hiding this comment

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

Potential NPE as get() is called before isEmpty() check. The code retrieves the database before checking if it exists, violating the fail-fast principle and risking exceptions.

Copy link
Member

Choose a reason for hiding this comment

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

Still valid comment

dialogService.showErrorDialogAndWait(e);
}
} else {
LOGGER.info("Not a git repository at path: {}", path.get());
Copy link

Choose a reason for hiding this comment

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

The log message directly calls path.get() without checking if the value is present, which could lead to NoSuchElementException. The Optional should be handled properly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Screenshot 2025-03-18 at 3 56 16 PM

As per intelliJ's response when trying to set a condition, it can be said that there will always be a path and hence this comment is irrelevant?

Copy link
Member

Choose a reason for hiding this comment

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

Just log path, will appear properly. Try it out!

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you that works!

SihasA and others added 7 commits March 18, 2025 16:20
- fixed incorrect order of statements for GitPullAction
- removed .get() for path in LOGGER statements
- checkstyle error fixed
- fixed used of a hardcoded path instead of leveraging JUnit's @tempdir annotation.
… logic inside a complex if condition. Should check conditions individually and return early if any fails."
… logic inside a complex if condition. Should check conditions individually and return early if any fails."
… logic inside a complex if condition. Should check conditions individually and return early if any fails."
preferences.getAutoPushEnabled()) {
this.updateCredentials(preferences);
try {
this.createCommitOnCurrentBranch("Automatic update via JabRef", false);
Copy link

Choose a reason for hiding this comment

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

Boolean parameter in public method should be avoided. Consider creating separate methods with meaningful names instead of using a boolean flag.

Copy link
Contributor

Choose a reason for hiding this comment

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

This function was produced for the previous SLR functionality, so we will avoid changing it.

@@ -160,6 +160,7 @@ dependencies {
// Include all jar-files in the 'lib' folder as dependencies
implementation fileTree(dir: 'lib', includes: ['*.jar'])


Copy link
Member

Choose a reason for hiding this comment

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

Does an AI bot create these empty lines?

I would recommend to review a commit using git gui!

Copy link
Contributor

Choose a reason for hiding this comment

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

My accident actually! A member of my team had accidentally added a few dependencies and removed some when trying to add the git functionality to the main menu (He wanted to add an icon next to "Git"). I was removing these dependencies manually and left a line. Will fix that and review the changes properly next time, thank you.

Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

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

Quick comment; I am in the road currently

SihasA and others added 4 commits March 19, 2025 14:32
- Localisation tests were failing. Added keys yo JabRef_en.properties.
- Bot mentioned issues with logger, these have been resolved.
…t fix.

- Removed CheckForVersionControlActionTest.java and working on a replacement.
- fixed properties file issue
Comment on lines 23 to 26
public void postSaveDatabaseAction(GitPreferences preferences) {
if (this.isGitRepository() &&
preferences.getAutoPushMode() == AutoPushMode.ON_SAVE &&
preferences.getAutoPushEnabled()) {
Copy link

Choose a reason for hiding this comment

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

The method should validate the preferences parameter for null before accessing its methods. Current implementation may throw NullPointerException if preferences is null.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am going to delete the enum in its entirety as the combo-box is no longer necessary for the scope of this PR. Will make the adjustments as necessary.

}

@Override
public void execute() {
Copy link

Choose a reason for hiding this comment

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

The method lacks JavaDoc despite being a public method that performs complex Git operations. Complex public methods should have comprehensive documentation.

.setRef(commit.toString())
.call();
} catch (GitAPIException e) {
LOGGER.error("Failed to rever to commit");
Copy link

Choose a reason for hiding this comment

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

Typo in error message ('rever' instead of 'revert') and the exception 'e' is not included in the log message, losing valuable debugging information

.setRebase(true)
.call();
} catch (GitAPIException e) {
LOGGER.error("Failed to pull and rebase");
Copy link

Choose a reason for hiding this comment

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

Exception 'e' is not included in the log message, which loses stack trace and error details needed for debugging

Comment on lines +50 to +53
try {
this.pullAndRebaseOnCurrentBranch();
dialogService.notify(Localization.lang("Successfully pulled"));
} catch (IOException e) {
Copy link

Choose a reason for hiding this comment

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

Try block covers multiple statements including notification, violating the principle of minimal try block coverage

Copy link
Contributor

JUnit tests are failing. In the area "Some checks were not successful", locate "Tests / Unit tests (pull_request)" and click on "Details". This brings you to the test output.

You can then run these tests in IntelliJ to reproduce the failing tests locally. We offer a quick test running howto in the section Final build system checks in our setup guide.

@koppor
Copy link
Member

koppor commented Mar 19, 2025

We have currently added git preferences under “Saving” in “General”. Is this okay? And if not should we proceed to making a new segment for it in preferences?

I think, we "discussed" this for 10 secons in one of our meetings. This was too fast.

If possible Move it below "General" with "Saving" as heading.

grafik

(Hint to me and you for a next project: More time for discussions / issue refinement. Write and check minutes. Wirte minitues in a shared manner - e.g., Etherpad (https://pad.riseup.net/) or Microsoft Word online on OneDrive)

@koppor
Copy link
Member

koppor commented Mar 19, 2025

If possible Move it below "General" with "Saving" as heading.

Update. Seems to be hard. Just add a new heading below "Saving". - When it comes to integrate WP4, there surely will be a new tab "Git" or "Saving". Due to time constraints, I think, this integration is out of scope of your project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants