parent
c4f5863ce0
commit
8512a97924
@ -0,0 +1,50 @@ |
||||
package com.apside.assistDbBackend.service; |
||||
|
||||
import lombok.Data; |
||||
import org.eclipse.jgit.api.Git; |
||||
import org.eclipse.jgit.api.RemoteAddCommand; |
||||
import org.eclipse.jgit.api.errors.GitAPIException; |
||||
import org.eclipse.jgit.transport.URIish; |
||||
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.net.URISyntaxException; |
||||
|
||||
@Data |
||||
@Service |
||||
public class GitService { |
||||
|
||||
private final String tempDirectoryPath; |
||||
|
||||
public GitService(){ |
||||
tempDirectoryPath = new File(System.getProperty("user.dir")).getParent() + "\\AssistDB_AdditionalFiles"; |
||||
} |
||||
@Value("${USERNAME_GIT}") |
||||
private String userGit; |
||||
|
||||
@Value("${ACCESS_TOKEN_GIT}") |
||||
private String accesToken; |
||||
|
||||
public void pushToGit() throws IOException, GitAPIException, URISyntaxException { |
||||
Git git = Git.open(new File(tempDirectoryPath)); |
||||
RemoteAddCommand remoteAddCommand = git.remoteAdd(); |
||||
remoteAddCommand.setName("origin"); |
||||
remoteAddCommand.setUri(new URIish("https://gitea.ci.apside-top.fr/Prudence_Creole/AssistDB_AdditionalFiles.git")); |
||||
// you can add more settings here if needed
|
||||
remoteAddCommand.call(); |
||||
|
||||
git.add().setUpdate(true).addFilepattern(".").call(); |
||||
git.add().addFilepattern(".").call(); |
||||
git.commit().setMessage("commited").call(); |
||||
|
||||
git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(userGit, accesToken)).call(); |
||||
} |
||||
|
||||
public void pullFromGit() throws IOException, GitAPIException { |
||||
Git git = Git.open(new File(tempDirectoryPath)); |
||||
git.pull().setCredentialsProvider(new UsernamePasswordCredentialsProvider(userGit, accesToken)).setRemote("origin").setRemoteBranchName("main").call(); |
||||
} |
||||
} |
Loading…
Reference in new issue