public void SearchRegisteredUser() { GitLabWrapper gitLabWrapper = new GitLabWrapper(TestCredentials.GitServer, TestCredentials.GitLabToken); DXVcsWrapper vcsWrapper = new DXVcsWrapper(TestCredentials.VcsServer); RegisteredUsers users = new RegisteredUsers(gitLabWrapper, vcsWrapper); var user = users.GetUser("litvinov"); Assert.IsNotNull(user); Assert.IsTrue(user.IsRegistered); var user2 = users.GetUser("Litvinov"); Assert.IsNotNull(user2); Assert.IsTrue(user2.IsRegistered); }
public void RegisterUser() { GitLabWrapper gitLabWrapper = new GitLabWrapper(TestCredentials.GitServer, TestCredentials.GitLabToken); DXVcsWrapper vcsWrapper = new DXVcsWrapper(TestCredentials.VcsServer); RegisteredUsers users = new RegisteredUsers(gitLabWrapper, vcsWrapper); var user = users.GetUser("Barakhov"); }
static void ProcessHistoryInternal(DXVcsWrapper vcsWrapper, GitWrapper gitWrapper, RegisteredUsers users, User defaultUser, string localGitDir, TrackBranch branch, IList<CommitItem> commits, SyncHistoryWrapper syncHistory) { ProjectExtractor extractor = new ProjectExtractor(commits, (item) => { var localCommits = vcsWrapper.GetCommits(item.TimeStamp, item.Items).Where(x => !IsLabel(x)).ToList(); bool hasModifications = false; GitCommit last = null; string token = syncHistory.CreateNewToken(); foreach (var localCommit in localCommits) { string localProjectPath = Path.Combine(localGitDir, localCommit.Track.ProjectPath); DirectoryHelper.DeleteDirectory(localProjectPath); string trackPath = branch.GetTrackRoot(localCommit.Track); vcsWrapper.GetProject(vcsServer, trackPath, localProjectPath, item.TimeStamp); Log.Message($"git stage {localCommit.Track.ProjectPath}"); gitWrapper.Stage(localCommit.Track.ProjectPath); string author = CalcAuthor(localCommit, defaultUser); var comment = CalcComment(localCommit, author, token); User user = users.GetUser(author); try { gitWrapper.Commit(comment.ToString(), user, localCommit.TimeStamp, false); last = gitWrapper.FindCommit(x => true); hasModifications = true; } catch (Exception) { Log.Message($"Empty commit detected for {localCommit.Author} {localCommit.TimeStamp}."); } } if (hasModifications) { gitWrapper.PushEverything(); syncHistory.Add(last.Sha, item.TimeStamp.Ticks, token); } else { var head = syncHistory.GetHead(); syncHistory.Add(head.GitCommitSha, item.TimeStamp.Ticks, token); string author = CalcAuthor(item, defaultUser); Log.Message($"Push empty commits rejected for {author} {item.TimeStamp}."); } syncHistory.Save(); }); int i = 0; while (extractor.PerformExtraction()) Log.Message($"{++i} from {commits.Count} push to branch {branch.Name} completed."); }
static void AssignBackConflictedMergeRequest(GitLabWrapper gitLabWrapper, RegisteredUsers users, MergeRequest mergeRequest, string comment) { User author = users.GetUser(mergeRequest.Author.Username); var mr = gitLabWrapper.UpdateMergeRequestAssignee(mergeRequest, author.UserName); gitLabWrapper.AddCommentToMergeRequest(mr, comment); }
static int DoSyncWork(SyncOptions clo) { string localGitDir = clo.LocalFolder != null && Path.IsPathRooted(clo.LocalFolder) ? clo.LocalFolder : Path.Combine(Environment.CurrentDirectory, clo.LocalFolder ?? repoPath); EnsureGitDir(localGitDir); string gitRepoPath = clo.Repo; string username = clo.Login; string password = clo.Password; string gitlabauthtoken = clo.AuthToken; string branchName = clo.Branch; string trackerPath = clo.Tracker; string gitServer = clo.Server; DXVcsWrapper vcsWrapper = new DXVcsWrapper(vcsServer, username, password); TrackBranch branch = FindBranch(branchName, trackerPath, vcsWrapper); if (branch == null) return 1; string historyPath = GetVcsSyncHistory(vcsWrapper, branch.HistoryPath); if (historyPath == null) return 1; SyncHistory history = SyncHistory.Deserialize(historyPath); if (history == null) return 1; SyncHistoryWrapper syncHistory = new SyncHistoryWrapper(history, vcsWrapper, branch.HistoryPath, historyPath); var head = syncHistory.GetHistoryHead(); if (head == null) return 1; GitLabWrapper gitLabWrapper = new GitLabWrapper(gitServer, gitlabauthtoken); RegisteredUsers registeredUsers = new RegisteredUsers(gitLabWrapper, vcsWrapper); User defaultUser = registeredUsers.GetUser(username); if (!defaultUser.IsRegistered) { Log.Error($"default user {username} is not registered in the active directory."); return 1; } var checkMergeChangesResult = CheckChangesForMerging(gitLabWrapper, gitRepoPath, branchName, head, vcsWrapper, branch, syncHistory, defaultUser); if (checkMergeChangesResult == CheckMergeChangesResult.NoChanges) return 0; if (checkMergeChangesResult == CheckMergeChangesResult.Error) return 1; GitWrapper gitWrapper = CreateGitWrapper(gitRepoPath, localGitDir, branch.Name, username, password); if (gitWrapper == null) return 1; ProcessHistoryResult processHistoryResult = ProcessHistory(vcsWrapper, gitWrapper, registeredUsers, defaultUser, gitRepoPath, localGitDir, branch, clo.CommitsCount, syncHistory, true); if (processHistoryResult == ProcessHistoryResult.NotEnough) return 0; if (processHistoryResult == ProcessHistoryResult.Failed) return 1; int result = ProcessMergeRequests(vcsWrapper, gitWrapper, gitLabWrapper, registeredUsers, defaultUser, gitRepoPath, localGitDir, clo.Branch, clo.Tracker, syncHistory, username); if (result != 0) return result; return 0; }