private void LogUniqueUserToFile(GitMigrationRequest request, string checkoutPath) { var filePath = FileSystemHelper.GetFilePath("knownUsernames.json"); var knownUsers = JsonConvert.DeserializeObject <KnownUserList>(File.ReadAllText(filePath)); var authorsFilePath = Path.Combine(checkoutPath, "authors-transform.txt"); var uniqueAuthors = _svnService.LogUniqueUsers(request, checkoutPath).ToArray(); StringBuilder authorText = new StringBuilder(); foreach (var uniqueAuthor in uniqueAuthors) { var knownUser = knownUsers.Users.SingleOrDefault(x => x.Svnname == uniqueAuthor); if (knownUser != null) { authorText.AppendFormat("{1} = {0} <{1}@parliament.uk>", knownUser.Author, knownUser.Svnname); } else { authorText.AppendFormat("{0} = {0} <{0}@parliament.uk>", uniqueAuthor); } authorText.AppendLine(); } File.WriteAllText(authorsFilePath, authorText.ToString()); }
public MigrationResult Migrate(GitMigrationRequest request, Action <string> callback) { var migrationResult = new MigrationResult(); callback("Creating group: " + request.GitGroupName + Environment.NewLine); var createGroupResult = CreateGitLabGroup(request, callback); if (createGroupResult) { callback("Creating project: " + request.GitProjectName + Environment.NewLine); var groupId = createGroupResult.Outputs.FirstOrDefault().ToString(); var createProjectResult = CreateGitLabProject(request, groupId, callback); if (createProjectResult) { var gitLabProjectUrl = createProjectResult.Outputs.FirstOrDefault().ToString(); var originUrl = ExtractGitOriginUrl(gitLabProjectUrl, request.GitLabUrl, request.GitUserName, request.GitPassword); callback("Created origin at : " + gitLabProjectUrl + Environment.NewLine); var checkoutPath = SetWorkingFolder(request.RepositorylUrl); // create new gitlab project LogUniqueUserToFile(request, checkoutPath); callback("Migrating repository" + Environment.NewLine); var cloneResult = CloneRepository(request, checkoutPath, originUrl, callback); if (cloneResult) { callback("SVN Repository successfully migrated!" + Environment.NewLine); migrationResult.Success = true; } else { migrationResult.Success = false; callback(ErrorMigratingRepository + Environment.NewLine); migrationResult.ErrorMessages.Add(ErrorMigratingRepository); } } else { callback(ErrorCreatingProject + Environment.NewLine); OutputErrors(createProjectResult, callback); migrationResult.Success = false; migrationResult.ErrorMessages.Add(ErrorCreatingProject); } } else { callback(ErrorCreatingGroup + Environment.NewLine); OutputErrors(createGroupResult, callback); migrationResult.Success = false; migrationResult.ErrorMessages.Add(ErrorCreatingGroup); } return(migrationResult); }
private ScriptExecutionResult CreateGitLabGroup(GitMigrationRequest request, Action <string> callback) { var powerScript = new CreateGitLabGroup(callback); powerScript.AddArgument("groupname", request.GitGroupName); powerScript.AddArgument("groupPath", request.GitGroupPath); powerScript.AddArgument("gitlabUrl", request.GitLabUrl); powerScript.AddArgument("privatetoken", request.PrivateToken); return(powerScript.Execute()); }
private ScriptExecutionResult CreateGitLabProject(GitMigrationRequest request, string groupId, Action <string> callback) { var powerScript = new CreateGitLabProject(callback); powerScript.AddArgument("projectname", request.GitProjectName); powerScript.AddArgument("gitlabUrl", request.GitLabUrl); powerScript.AddArgument("path", request.GitProjectPath); powerScript.AddArgument("namespaceid", groupId); powerScript.AddArgument("privatetoken", request.PrivateToken); return(powerScript.Execute()); }
private ScriptExecutionResult CloneRepository(GitMigrationRequest request, string checkoutPath, string originUrl, Action <string> callback) { var powerScript = new MigrateToGitRepository(callback); powerScript.AddArgument("repoUrl", request.RepositorylUrl); powerScript.AddArgument("checkoutPath", checkoutPath); powerScript.AddArgument("username", request.Username); powerScript.AddArgument("password", request.Password); powerScript.AddArgument("gitUserEmail", request.GitUserEmail); powerScript.AddArgument("gitUserName", request.GitUserName); powerScript.AddArgument("originUrl", originUrl); powerScript.AddArgument("nonstandardfolder", request.NonStandardFolder.ToString()); return(powerScript.ExecuteAync()); }
public ActionResult MigrateRepo(GitMigrationRequest request) { var result = new WebResult(); try { var migrationResult = _migrationService.Migrate(request, NotifyUpdates); result.Error = !migrationResult.Success; result.Message = string.Join(Environment.NewLine, migrationResult.ErrorMessages.ToArray()); } catch (SvnMigrationException ex) { result.Error = true; result.Message = ex.Message; } return(Json(result)); }
public IEnumerable <string> LogUniqueUsers(GitMigrationRequest request, string checkoutPath) { var authors = new List <string>(); SetCredentials(request); try { using (var client = GetSvnClient()) { var repoUrl = SvnUriTarget.FromString(request.RepositorylUrl); var args = GetSvnLogArgs(); client.Log(repoUrl.Uri, args, (o, e) => { authors.Add(e.Author); }); } } catch (SvnRepositoryIOException ex) { throw new SvnMigrationException(ex.Message, ex); } return(authors.Distinct()); }