|
|
@@ -4,7 +4,6 @@ import cn.reghao.autodop.common.utils.text.TextFile;
|
|
|
import cn.reghao.autodop.dmaster.app.constant.build.RepoAuthType;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.config.build.RepoConfig;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.log.ChangedFile;
|
|
|
-import cn.reghao.autodop.dmaster.app.entity.log.CommitLog;
|
|
|
import cn.reghao.autodop.dmaster.app.exception.UpdateException;
|
|
|
import com.jcraft.jsch.JSch;
|
|
|
import com.jcraft.jsch.JSchException;
|
|
|
@@ -95,7 +94,7 @@ public class GitImpl implements CodeUpdater {
|
|
|
* @date 2020-05-13 下午9:22
|
|
|
*/
|
|
|
@Override
|
|
|
- public CommitLog update(String remote, String branch, String local) throws Exception {
|
|
|
+ public CommitInfo update(String remote, String branch, String local) throws Exception {
|
|
|
String localRepoDir = local + dirname(remote);
|
|
|
File file = new File(localRepoDir);
|
|
|
if (!file.exists() && !file.mkdirs()) {
|
|
|
@@ -103,9 +102,9 @@ public class GitImpl implements CodeUpdater {
|
|
|
}
|
|
|
|
|
|
File localRepo = new File(localRepoDir + "/.git");
|
|
|
- CommitLog commitLog;
|
|
|
+ CommitInfo commitInfo;
|
|
|
if (!localRepo.exists()) {
|
|
|
- commitLog = clone(remote, branch, localRepoDir);
|
|
|
+ commitInfo = clone(remote, branch, localRepoDir);
|
|
|
} else {
|
|
|
try (Repository repo = new FileRepository(localRepo.getAbsolutePath())) {
|
|
|
if (sshSessionFactory != null) {
|
|
|
@@ -122,16 +121,16 @@ public class GitImpl implements CodeUpdater {
|
|
|
gitPull.call();
|
|
|
}
|
|
|
|
|
|
- commitLog = commitInfo(repo, branch);
|
|
|
- commitLog.setChangedFiles(changedFileList(repo, branch));
|
|
|
+ commitInfo = commitInfo(repo, branch);
|
|
|
+ commitInfo.setChangedFiles(changedFileList(repo, branch));
|
|
|
}
|
|
|
}
|
|
|
- commitLog.setRemote(remote);
|
|
|
- commitLog.setBranch(branch);
|
|
|
- return commitLog;
|
|
|
+ commitInfo.setRemote(remote);
|
|
|
+ commitInfo.setBranch(branch);
|
|
|
+ return commitInfo;
|
|
|
}
|
|
|
|
|
|
- private CommitLog clone(String remote, String branch, String local) throws Exception {
|
|
|
+ private CommitInfo clone(String remote, String branch, String local) throws Exception {
|
|
|
CloneCommand gitClone;
|
|
|
if (sshSessionFactory != null) {
|
|
|
gitClone = Git.cloneRepository()
|
|
|
@@ -155,13 +154,13 @@ public class GitImpl implements CodeUpdater {
|
|
|
|
|
|
try (Git git = gitClone.call()) {
|
|
|
Repository repo = git.getRepository();
|
|
|
- CommitLog commitLog = commitInfo(repo, branch);
|
|
|
- commitLog.setChangedFiles(changedFileList(repo, branch));
|
|
|
- return commitLog;
|
|
|
+ CommitInfo commitInfo = commitInfo(repo, branch);
|
|
|
+ commitInfo.setChangedFiles(changedFileList(repo, branch));
|
|
|
+ return commitInfo;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private CommitLog commitInfo(Repository repo, String branch) throws Exception {
|
|
|
+ private CommitInfo commitInfo(Repository repo, String branch) throws Exception {
|
|
|
Ref head = repo.findRef("refs/heads/" + branch);
|
|
|
ObjectId objectId = head.getObjectId();
|
|
|
try (RevWalk walk = new RevWalk(repo)) {
|
|
|
@@ -171,16 +170,16 @@ public class GitImpl implements CodeUpdater {
|
|
|
String commitAuthor = lastCommit.getAuthorIdent().getName();
|
|
|
String commitMsg = lastCommit.getFullMessage();
|
|
|
|
|
|
- CommitLog commitLog = new CommitLog();
|
|
|
- commitLog.setCommitId(objectId.name().substring(0, 8));
|
|
|
- commitLog.setMsCommitTime(commitTime*1000);
|
|
|
- commitLog.setCommitAuthor(commitAuthor);
|
|
|
+ CommitInfo commitInfo = new CommitInfo();
|
|
|
+ commitInfo.setCommitId(objectId.name().substring(0, 8));
|
|
|
+ commitInfo.setMsCommitTime(commitTime*1000);
|
|
|
+ commitInfo.setCommitAuthor(commitAuthor);
|
|
|
if (commitMsg.length() > 1000) {
|
|
|
- commitLog.setCommitMsg(commitMsg.substring(0, 1000));
|
|
|
+ commitInfo.setCommitMsg(commitMsg.substring(0, 1000));
|
|
|
} else {
|
|
|
- commitLog.setCommitMsg(commitMsg);
|
|
|
+ commitInfo.setCommitMsg(commitMsg);
|
|
|
}
|
|
|
- return commitLog;
|
|
|
+ return commitInfo;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -226,12 +225,12 @@ public class GitImpl implements CodeUpdater {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public CommitLog update(String remote, String branch, String local, String commitId) throws Exception {
|
|
|
+ public CommitInfo update(String remote, String branch, String local, String commitId) throws Exception {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public CommitLog lastCommitInfo(String local, String branch) throws Exception {
|
|
|
+ public CommitInfo latestCommitInfo(String local, String branch) throws Exception {
|
|
|
File localRepo = new File(local + "/.git");
|
|
|
if (!localRepo.exists()) {
|
|
|
return null;
|