-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[WIP] Happy days git integration wp3 #12773
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
base: main
Are you sure you want to change the base?
Changes from all commits
01dec74
eb1b9a8
c761db5
2c9dad4
ed6eb4a
9cbdd76
62defc4
bbc6b38
69e0f9a
d578bd5
cf32088
c670625
9026eb9
40cdd64
8db799c
af0c3c8
1f2de0a
cfd46db
6ecf1a8
a0e2dc7
c8be361
5127bca
2bf349d
bff9857
c197264
f7c21c4
980c748
caf405b
4ed64cd
45c453e
3ff8bc3
63d86f1
837311f
53286d4
cd6ff23
f2fae4b
7b0e930
c28b84f
0e0ddba
b9ca978
e71d3ad
27b0355
6a7e013
e3885b7
0fd12cc
b1458b2
98ec8a8
d9162bc
e800a28
0c51c0e
5e0015c
d5b72bb
2586df7
bed8cc7
4b71771
d52d62a
f232305
4d91985
2ea0d72
2fe1066
8f683f0
cdb4c76
1884dd7
bde293a
37e0b92
f87ab7a
dcc5a06
b11f155
854af5c
95197c2
51e6fd6
f1fe7f5
e3fc84e
3070087
4e1c577
5b278aa
c305e53
9b0bf8f
493775b
92df862
0c0a094
6e731cf
355ff89
86edd20
14e6d52
0b7db48
6ad7f25
74398a8
ee71915
9bf27ad
7cfb3e4
6775c8b
a696800
f166255
1b46b89
1c47c25
8d8273e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.jabref.gui.importer.actions; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Optional; | ||
|
||
import org.jabref.gui.DialogService; | ||
import org.jabref.logic.git.GitClientHandler; | ||
import org.jabref.logic.importer.ParserResult; | ||
import org.jabref.logic.preferences.CliPreferences; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* This action checks whether this BIB file is contained in a Git repository. If so, | ||
* then the file is tagged as "versioned" in BibDatabaseContext and a git pull is | ||
* attempted. | ||
*/ | ||
public class CheckForVersionControlAction implements GUIPostOpenAction { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(CheckForVersionControlAction.class); | ||
private GitClientHandler gitClientHandler; | ||
|
||
@Override | ||
public boolean isActionNecessary(ParserResult parserResult, DialogService dialogService, CliPreferences preferences) { | ||
Optional<Path> path = parserResult.getDatabaseContext().getDatabasePath(); | ||
if (path.isEmpty()) { | ||
return false; | ||
} | ||
this.gitClientHandler = new GitClientHandler(path.get(), | ||
dialogService, | ||
preferences.getGitPreferences()); | ||
Comment on lines
+30
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a side effect of a simple Maybe bind the GitClienthandler to the BibDatbaseContext? |
||
return gitClientHandler.isGitRepository(); | ||
} | ||
|
||
@Override | ||
public void performAction(ParserResult parserResult, DialogService dialogService, CliPreferences preferencesService) { | ||
parserResult.getDatabaseContext().setVersioned(true); | ||
|
||
try { | ||
this.gitClientHandler.pullOnCurrentBranch(); | ||
} catch (IOException e) { | ||
LOGGER.error("Failed to pull.", e); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,4 +120,18 @@ | |
<Insets top="-4.0"/> | ||
</VBox.margin> | ||
</HBox> | ||
|
||
<Label styleClass="sectionHeader" text="%Git"/> | ||
<HBox spacing="10"> | ||
<Label text="Git Username:"/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please see two lines above how localiaztion works. Moreover, no : at the end |
||
<TextField fx:id="gitHubUsernameField" promptText="Enter your username here"/> | ||
</HBox> | ||
|
||
<HBox spacing="10"> | ||
<Label text="Git Personal Access Token:"/> | ||
<TextField fx:id="gitHubPasskeyField" promptText="Enter your PAT here"/> | ||
</HBox> | ||
<HBox alignment="CENTER_LEFT" spacing="4.0"> | ||
<CheckBox fx:id="autoPushCheckbox" text="Auto push on save"/> | ||
</HBox> | ||
</fx:root> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.jabref.gui.shared; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Optional; | ||
|
||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.StateManager; | ||
import org.jabref.gui.actions.SimpleCommand; | ||
import org.jabref.gui.preferences.GuiPreferences; | ||
import org.jabref.logic.git.GitClientHandler; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class GitPullAction extends SimpleCommand { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(GitPullAction.class); | ||
|
||
private final GuiPreferences preferences; | ||
private final DialogService dialogService; | ||
private final StateManager stateManager; | ||
|
||
public GitPullAction( | ||
GuiPreferences preferences, | ||
DialogService dialogService, | ||
StateManager stateManager) { | ||
this.preferences = preferences; | ||
this.dialogService = dialogService; | ||
this.stateManager = stateManager; | ||
} | ||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a space above |
||
* Contains logic for performing Git operations on the active database repository. | ||
* The method verifies that an active database exists and is not empty | ||
* then creates a GitClientHandler with the parent directory of the database path. | ||
* If the directory is a Git repository, performs a pull operation on the current branch. | ||
* Will log any errors that occur during the pull operation. | ||
*/ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove empty line - JavaDoc is connected to the method directly. |
||
@Override | ||
public void execute() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
if (stateManager.getActiveDatabase().isEmpty()) { | ||
return; | ||
} | ||
BibDatabaseContext databaseContext = stateManager.getActiveDatabase().get(); | ||
|
||
Optional<Path> path = databaseContext.getDatabasePath(); | ||
if (path.isEmpty()) { | ||
return; | ||
} | ||
|
||
GitClientHandler gitClientHandler = new GitClientHandler(path.get().getParent(), | ||
dialogService, | ||
preferences.getGitPreferences()); | ||
if (gitClientHandler.isGitRepository()) { | ||
try { | ||
gitClientHandler.pullOnCurrentBranch(); | ||
} catch (IOException e) { | ||
LOGGER.error("Failed to Pull", e); | ||
} | ||
} else { | ||
LOGGER.info("Not a git repository at path: {}", path.get()); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.jabref.gui.shared; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Optional; | ||
|
||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.StateManager; | ||
import org.jabref.gui.actions.SimpleCommand; | ||
import org.jabref.gui.preferences.GuiPreferences; | ||
import org.jabref.logic.git.GitClientHandler; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
|
||
import org.eclipse.jgit.api.errors.GitAPIException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class GitPushAction extends SimpleCommand { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(GitPushAction.class); | ||
|
||
private final GuiPreferences preferences; | ||
private final DialogService dialogService; | ||
private final StateManager stateManager; | ||
|
||
public GitPushAction( | ||
GuiPreferences preferences, | ||
DialogService dialogService, | ||
StateManager stateManager) { | ||
this.preferences = preferences; | ||
this.dialogService = dialogService; | ||
this.stateManager = stateManager; | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
if (stateManager.getActiveDatabase().isEmpty()) { | ||
return; | ||
} | ||
BibDatabaseContext databaseContext = stateManager.getActiveDatabase().get(); | ||
|
||
Optional<Path> path = databaseContext.getDatabasePath(); | ||
if (path.isEmpty()) { | ||
return; | ||
} | ||
|
||
GitClientHandler gitClientHandler = new GitClientHandler(path.get().getParent(), | ||
dialogService, | ||
preferences.getGitPreferences()); | ||
if (gitClientHandler.isGitRepository()) { | ||
try { | ||
gitClientHandler.createCommitOnCurrentBranch("Automatic update via JabRef", false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This string appears twice in your code - please introduce a constant. |
||
gitClientHandler.pushCommitsToRemoteRepository(); | ||
} catch (IOException | GitAPIException e) { | ||
dialogService.showErrorDialogAndWait(e); | ||
} | ||
} else { | ||
LOGGER.info("Not a git repository at path: {}", path); | ||
} | ||
} | ||
} |
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.
Lifecycle is strange - the
GitClientHandler
should be bound to theBibdatabaseContext
(orlibraryTab
), shouldn't it?There is also an instance in
src/main/java/org/jabref/gui/importer/actions/CheckForVersionControlAction.java
. I think, the instance should be shared?