|
|
@ -21,8 +21,6 @@ public class GitServiceImpl implements GitService { |
|
|
|
|
|
|
|
|
|
|
|
private final String tempDirectoryPath; |
|
|
|
private final String tempDirectoryPath; |
|
|
|
|
|
|
|
|
|
|
|
private UsernamePasswordCredentialsProvider userPass; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public GitServiceImpl(){ |
|
|
|
public GitServiceImpl(){ |
|
|
|
tempDirectoryPath = new File(System.getProperty("user.dir")).getParent() + "\\AssistDB_AdditionalFiles"; |
|
|
|
tempDirectoryPath = new File(System.getProperty("user.dir")).getParent() + "\\AssistDB_AdditionalFiles"; |
|
|
|
} |
|
|
|
} |
|
|
@ -32,23 +30,28 @@ public class GitServiceImpl implements GitService { |
|
|
|
@Value("${ACCESS_TOKEN_GIT}") |
|
|
|
@Value("${ACCESS_TOKEN_GIT}") |
|
|
|
private String accesToken; |
|
|
|
private String accesToken; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${URI_GIT}") |
|
|
|
|
|
|
|
private String uriGit; |
|
|
|
|
|
|
|
private static final String NAME_URI = "origin"; |
|
|
|
|
|
|
|
private static final String COMMIT_MESSAGE = "commited"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void pushToGit() throws IOException, GitAPIException, URISyntaxException { |
|
|
|
public void pushToGit() throws IOException, GitAPIException, URISyntaxException { |
|
|
|
log.debug("Starting pushToGit method."); |
|
|
|
log.debug("Starting pushToGit method."); |
|
|
|
|
|
|
|
pullFromGit(); |
|
|
|
try (Git git = Git.open(new File(tempDirectoryPath))){ |
|
|
|
try (Git git = Git.open(new File(tempDirectoryPath))){ |
|
|
|
RemoteAddCommand remoteAddCommand = git.remoteAdd(); |
|
|
|
RemoteAddCommand remoteAddCommand = git.remoteAdd(); |
|
|
|
remoteAddCommand.setName("origin"); |
|
|
|
remoteAddCommand.setName(NAME_URI); |
|
|
|
remoteAddCommand.setUri(new URIish("https://gitea.ci.apside-top.fr/Prudence_Creole/AssistDB_AdditionalFiles.git")); |
|
|
|
remoteAddCommand.setUri(new URIish(uriGit)); |
|
|
|
// you can add more settings here if needed
|
|
|
|
// you can add more settings here if needed
|
|
|
|
remoteAddCommand.call(); |
|
|
|
remoteAddCommand.call(); |
|
|
|
|
|
|
|
|
|
|
|
git.add().setUpdate(true).addFilepattern(".").call(); |
|
|
|
git.add().setUpdate(true).addFilepattern(".").call(); |
|
|
|
git.add().addFilepattern(".").call(); |
|
|
|
git.add().addFilepattern(".").call(); |
|
|
|
git.commit().setMessage("commited").call(); |
|
|
|
git.commit().setMessage(COMMIT_MESSAGE).call(); |
|
|
|
|
|
|
|
|
|
|
|
userPass = new UsernamePasswordCredentialsProvider(userGit, accesToken); |
|
|
|
git.push().setCredentialsProvider(createCredential()).call(); |
|
|
|
|
|
|
|
|
|
|
|
git.push().setCredentialsProvider(userPass).call(); |
|
|
|
|
|
|
|
log.info("Push to Git successful."); |
|
|
|
log.info("Push to Git successful."); |
|
|
|
} catch (IOException|GitAPIException exception){ |
|
|
|
} catch (IOException|GitAPIException exception){ |
|
|
|
log.error("Error push from git", exception); |
|
|
|
log.error("Error push from git", exception); |
|
|
@ -60,7 +63,7 @@ public class GitServiceImpl implements GitService { |
|
|
|
public void pullFromGit() throws IOException, GitAPIException { |
|
|
|
public void pullFromGit() throws IOException, GitAPIException { |
|
|
|
log.debug("Starting pullFromGit method."); |
|
|
|
log.debug("Starting pullFromGit method."); |
|
|
|
try (Git git = Git.open(new File(tempDirectoryPath))){ |
|
|
|
try (Git git = Git.open(new File(tempDirectoryPath))){ |
|
|
|
git.pull().setCredentialsProvider(new UsernamePasswordCredentialsProvider(userGit, accesToken)).setRemote("origin").setRemoteBranchName("main").call(); |
|
|
|
git.pull().setCredentialsProvider(createCredential()).setRemote("origin").setRemoteBranchName("main").call(); |
|
|
|
log.info("Pull from Git successful."); |
|
|
|
log.info("Pull from Git successful."); |
|
|
|
} catch (IOException|GitAPIException exception){ |
|
|
|
} catch (IOException|GitAPIException exception){ |
|
|
|
log.error("Error push from git", exception); |
|
|
|
log.error("Error push from git", exception); |
|
|
@ -68,4 +71,8 @@ public class GitServiceImpl implements GitService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public UsernamePasswordCredentialsProvider createCredential() { |
|
|
|
|
|
|
|
return new UsernamePasswordCredentialsProvider(userGit, accesToken); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|