diff --git a/src/main/java/net/geedge/asw/common/util/RCode.java b/src/main/java/net/geedge/asw/common/util/RCode.java index 6fd4efa..d43dd33 100644 --- a/src/main/java/net/geedge/asw/common/util/RCode.java +++ b/src/main/java/net/geedge/asw/common/util/RCode.java @@ -66,6 +66,7 @@ public enum RCode { GIT_PARENT_COMMITID_NOT_FOUND(203003, "Parent commitId not found"), GIT_BINARY_CONFLICT_ERROR(203004, "Binary file conflict found; resolve conflicts in binary files manually"), GIT_MERGE_NOT_SUPPORTED(203005, "Cannot merge in the {0} state"), + GIT_MERGE_TARGET_BRANCH_NOT_EXIST(203006, "The target branch {0} does not exist."), // Runner diff --git a/src/main/java/net/geedge/asw/module/app/dao/ApplicationDao.java b/src/main/java/net/geedge/asw/module/app/dao/ApplicationDao.java deleted file mode 100644 index f1c6954..0000000 --- a/src/main/java/net/geedge/asw/module/app/dao/ApplicationDao.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.geedge.asw.module.app.dao; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import net.geedge.asw.module.app.entity.ApplicationEntity; -import org.apache.ibatis.annotations.Mapper; - -import java.util.List; -import java.util.Map; - -@Mapper -public interface ApplicationDao extends BaseMapper{ - - List queryList(Page page, Map params); -} diff --git a/src/main/java/net/geedge/asw/module/app/service/IGitService.java b/src/main/java/net/geedge/asw/module/app/service/IGitService.java index 7fbb532..66ce20e 100644 --- a/src/main/java/net/geedge/asw/module/app/service/IGitService.java +++ b/src/main/java/net/geedge/asw/module/app/service/IGitService.java @@ -28,6 +28,8 @@ public interface IGitService { void deleteBranch(String workspaceId, String branch); + boolean isBranchExists(String workspaceId, String branch); + List> listBranchCommit(String workspaceId, String branch, String path); String getParentCommitId(String workspaceId, String branch, String commitId); diff --git a/src/main/java/net/geedge/asw/module/app/service/impl/ApplicationMergeServiceImpl.java b/src/main/java/net/geedge/asw/module/app/service/impl/ApplicationMergeServiceImpl.java index 7d388fa..ef1a408 100644 --- a/src/main/java/net/geedge/asw/module/app/service/impl/ApplicationMergeServiceImpl.java +++ b/src/main/java/net/geedge/asw/module/app/service/impl/ApplicationMergeServiceImpl.java @@ -120,8 +120,10 @@ public class ApplicationMergeServiceImpl extends ServiceImpl() + .eq(ApplicationMergeEntity::getWorkspaceId, workspaceId) + .eq(ApplicationMergeEntity::getSourceBranch, branchName) + .eq(ApplicationMergeEntity::getStatus, MergeRequestStatus.OPEN.toString()) + ); } catch (GitAPIException e) { log.error(e, "[deleteBranch] [error] [workspaceId: {}] [branchName: {}]", workspaceId, branchName); throw new ASWException(RCode.ERROR); } } + @Override + public boolean isBranchExists(String workspaceId, String branch) { + try (Git git = this.getGitInstance(workspaceId)) { + Ref ref = git.getRepository().findRef(T.StrUtil.concat(true, LOCAL_BRANCH_PREFIX, branch)); + return null != ref; + } catch (IOException e) { + log.error(e, "[isBranchExists] [workspaceId: {}] [branch: {}]", workspaceId, branch); + throw new RuntimeException(e); + } + } + @Override public List> listBranchCommit(String workspaceId, String branch, String path) { List> resultList = T.ListUtil.list(true); @@ -1228,70 +1248,6 @@ public class GitServiceImpl implements IGitService { return result; } - /** - * 解决冲突提交到 srcBranch - * 提交指定 srcBranch,tgtBranch 最新 commitId,像 merge commit 一样 - * - * @param workspaceId - * @param srcBranch - * @param tgtBranch - * @param commitId - * @param commitMessage - * @param files - */ -// @Override -// public void resolveMrConflicts(String workspaceId, String srcBranch, String tgtBranch, String commitId, String commitMessage, List> files) { -// try (Git git = this.getGitInstance(workspaceId); -// Repository repository = git.getRepository(); -// TreeWalk treeWalk = new TreeWalk(repository); -// RevWalk revWalk = new RevWalk(repository)) { -// -// ObjectId srcBranchLatestCommitId = repository.resolve(srcBranch); -// -// // branch tree -// treeWalk.addTree(revWalk.parseTree(srcBranchLatestCommitId)); -// treeWalk.setRecursive(true); -// -// DirCache newTree = DirCache.newInCore(); -// DirCacheBuilder newTreeBuilder = newTree.builder(); -// -// List updateFilePath = files.stream().map(map -> T.MapUtil.getStr(map, "path")).collect(Collectors.toList()); -// while (treeWalk.next()) { -// String pathString = treeWalk.getPathString(); -// // 先删 -// if (!updateFilePath.contains(pathString)) { -// DirCacheEntry entry = new DirCacheEntry(pathString); -// entry.setFileMode(treeWalk.getFileMode(0)); -// entry.setObjectId(treeWalk.getObjectId(0)); -// newTreeBuilder.add(entry); -// } -// } -// // 后增 -// for (Map map : files) { -// String path = T.MapUtil.getStr(map, "path"); -// DirCacheEntry dirCacheEntry = new DirCacheEntry(path); -// dirCacheEntry.setFileMode(FileMode.REGULAR_FILE); -// -// String content = T.MapUtil.getStr(map, "content"); -// ObjectId objectId = this.insertBlobFileToDatabase(repository, content.getBytes()); -// dirCacheEntry.setObjectId(objectId); -// newTreeBuilder.add(dirCacheEntry); -// } -// newTreeBuilder.finish(); -// -// // merge commit -// ObjectId parentId1 = ObjectId.fromString(commitId); -// RevCommit revCommit = revWalk.parseCommit(repository.resolve(tgtBranch)); -// ObjectId parentId2 = revCommit.getId(); -// -// boolean success = this.commitIndex(repository, srcBranch, newTree, parentId1, parentId2, commitMessage); -// log.info("[resolveMrConflicts] [workspaceId: {}] [srcBranch: {}] [tgtBranch: {}] [commitId: {}] [success: {}]", workspaceId, srcBranch, tgtBranch, commitId, success); -// } catch (IOException | ConcurrentRefUpdateException e) { -// log.error(e, "[resolveMrConflicts] [error] [workspaceId: {}] [srcBranch: {}] [tgtBranch: {}] [commitId: {}]", workspaceId, srcBranch, tgtBranch, commitId); -// throw new RuntimeException(e); -// } -// } - /** * commit * diff --git a/src/main/resources/db/mapper/app/ApplicationMapper.xml b/src/main/resources/db/mapper/app/ApplicationMapper.xml deleted file mode 100644 index 315215f..0000000 --- a/src/main/resources/db/mapper/app/ApplicationMapper.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/resources/db/migration/R__AZ_sys_i18n.sql b/src/main/resources/db/migration/R__AZ_sys_i18n.sql index bd4c075..4bb6672 100644 --- a/src/main/resources/db/migration/R__AZ_sys_i18n.sql +++ b/src/main/resources/db/migration/R__AZ_sys_i18n.sql @@ -155,5 +155,7 @@ INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_ INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (247, '203004', 'GIT_BINARY_CONFLICT_ERROR', '发现二进制文件冲突;手动解决二进制文件中的冲突', 'zh', '', 'admin', 1724030366000); INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (248, '203005', 'GIT_MERGE_NOT_SUPPORTED', 'Cannot merge in the {0} state', 'en', '', 'admin', 1724030366000); INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (249, '203005', 'GIT_MERGE_NOT_SUPPORTED', '无法在{0}状态下合并', 'zh', '', 'admin', 1724030366000); +INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (250, '203006', 'GIT_MERGE_TARGET_BRANCH_NOT_EXIST', 'The target branch {0} does not exist.', 'en', '', 'admin', 1724030366000); +INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (251, '203006', 'GIT_MERGE_TARGET_BRANCH_NOT_EXIST', '目标分支 {0} 不存在', 'zh', '', 'admin', 1724030366000); SET FOREIGN_KEY_CHECKS = 1;