示例#1
0
        public ActionResult <IEnumerable <RemoteRepository> > PostRemoteRepository(RemoteRepository remoteRepository)
        {
            //先取得資料庫內已有的倉儲資料
            IEnumerable <RemoteRepository> allRemoteRepositories   = GetAllRemoteRepository().Result.Value;
            RemoteRepositoryService        remoteRepositoryService = new RemoteRepositoryService();
            //檢查是否重複新增
            var exist = remoteRepositoryService.CheckRomoteRepository(remoteRepository.RemoteRepositoryUrl, allRemoteRepositories);

            if (exist)
            {
                string error = "此倉儲已經存在";
                return(StatusCode(StatusCodes.Status405MethodNotAllowed, error));
            }
            else
            {
                //在本地端clone專案
                GitCommandService gitCommandService = new GitCommandService();
                var cloneResult = gitCommandService.ExcuteCommand(new GitCommandInfo
                {
                    Command  = "clone",
                    GitUrl   = remoteRepository.RemoteRepositoryUrl,
                    FilePath = ProjectPath.Path
                });
                //在資料庫新增此倉儲資料
                if (cloneResult.IsSuccessful)
                {
                    remoteRepository.RemoteRepositoryId = Guid.NewGuid();
                    remoteRepository.ServerPath         = cloneResult.Result + "/" + remoteRepositoryService.GetFolderName(remoteRepository.RemoteRepositoryUrl);
                    remoteRepositoryRepository.Create(remoteRepository);
                    return(CreatedAtAction(nameof(GetAllRemoteRepository), remoteRepository));
                }
                else
                {
                    //當clone失敗
                    return(StatusCode(StatusCodes.Status405MethodNotAllowed, cloneResult.ErrorMessage));
                }
                //return CreatedAtAction(nameof(GetRemoteRepository), GetRemoteRepository().Result.Value);
            }
        }
示例#2
0
 public RemoteRepositoryCommand(RemoteRepositoryService remoteRepoService, EntityConvertor entityConvertor)
 {
     _remoteRepoService = remoteRepoService;
     _entityConvertor   = entityConvertor;
 }