FindProject() public method

public FindProject ( string project ) : NGitLab.Models.Project
project string
return NGitLab.Models.Project
Example #1
0
 public RepositoryViewModel(string name, TrackRepository trackRepository, RepositoriesViewModel repositories)
 {
     TrackRepository = trackRepository;
     GitLabWrapper = new GitLabWrapper(TrackRepository.Server, TrackRepository.Token);
     HasAdminPrivileges = GitLabWrapper.IsAdmin();
     GitReader = new GitReaderWrapper(trackRepository.LocalPath);
     UpdateConfigs(trackRepository, repositories);
     Repositories = repositories;
     Origin = GitLabWrapper.FindProject(GitReader.GetOriginRepoPath());
     Upstream = GitLabWrapper.FindProject(GitReader.GetUpstreamRepoPath());
     Name = name;
     Update();
 }
Example #2
0
 public void GetProject()
 {
     GitLabWrapper wrapper = new GitLabWrapper(TestCredentials.GitServer, TestCredentials.GitLabToken);
     var project = wrapper.FindProject("tester/testxpfall");
     Assert.IsNotNull(project);
 }
Example #3
0
 public void GetMergeRequests()
 {
     GitLabWrapper wrapper = new GitLabWrapper(TestCredentials.GitServer, TestCredentials.GitLabToken);
     var project = wrapper.FindProject("tester/testxpfall");
     var requests = wrapper.GetMergeRequests(project, x => x.TargetBranch == "test2");
 }
Example #4
0
 static int ProcessMergeRequests(DXVcsWrapper vcsWrapper, GitWrapper gitWrapper, GitLabWrapper gitLabWrapper, RegisteredUsers users, User defaultUser, string gitRepoPath, string localGitDir, string branchName, string tracker, SyncHistoryWrapper syncHistory, string userName) {
     var project = gitLabWrapper.FindProject(gitRepoPath);
     TrackBranch branch = GetBranch(branchName, tracker, vcsWrapper);
     if (branch == null) {
         Log.Error($"Specified branch {branchName} not found in track file.");
         return 1;
     }
     var mergeRequests = GetMergeRequests(gitLabWrapper, branchName, userName, project);
     if (!mergeRequests.Any()) {
         Log.Message("Zero registered merge requests.");
         return 0;
     }
     int result = 0;
     foreach (var mergeRequest in mergeRequests) {
         var mergeRequestResult = ProcessMergeRequest(vcsWrapper, gitWrapper, gitLabWrapper, users, defaultUser, localGitDir, branch, mergeRequest, syncHistory);
         if (mergeRequestResult == MergeRequestResult.Failed)
             return 1;
         if (mergeRequestResult == MergeRequestResult.CheckoutFailed || mergeRequestResult == MergeRequestResult.Conflicts || mergeRequestResult == MergeRequestResult.InvalidState)
             result = 1;
     }
     return result;
 }
Example #5
0
        static CheckMergeChangesResult CheckChangesForMerging(GitLabWrapper gitLabWrapper, string gitRepoPath, string branchName, SyncHistoryItem head, DXVcsWrapper vcsWrapper, TrackBranch branch, SyncHistoryWrapper syncHistory, User defaultUser) {
            var project = gitLabWrapper.FindProject(gitRepoPath);
            if (project == null) {
                Log.Error($"Can`t find git project {gitRepoPath}");
                return CheckMergeChangesResult.Error;
            }

            var gitlabBranch = gitLabWrapper.GetBranches(project).Single(x => x.Name == branchName);
            if (gitlabBranch.Commit.Id.Equals(new Sha1(head.GitCommitSha))) {
                var commits = GenerateCommits(vcsWrapper, branch, syncHistory, false);
                if (commits.Count == 0) {
                    var mergeRequests = GetMergeRequests(gitLabWrapper, branchName, defaultUser.UserName, project);
                    if (!mergeRequests.Any()) {
                        Log.Message("Zero registered merge requests.");
                        return CheckMergeChangesResult.NoChanges;
                    }
                }
            }
            return CheckMergeChangesResult.HasChanges;
        }
Example #6
0
        static int DoPatchWork(PatchOptions clo) {
            string localGitDir = clo.LocalFolder != null && Path.IsPathRooted(clo.LocalFolder) ? clo.LocalFolder : Path.Combine(Environment.CurrentDirectory, clo.LocalFolder ?? repoPath);

            string targetRepoPath = GetSimpleGitHttpPath(clo.Repo);

            if (string.IsNullOrEmpty(targetRepoPath)) {
                Log.Error($"Can`t parse repo path {clo.Repo}");
                return 1;
            }
            string sourceRepoPath = GetSimpleGitHttpPath(clo.SourceRepo);
            if (string.IsNullOrEmpty(sourceRepoPath)) {
                Log.Error($"Can`t parse source repo path {clo.SourceRepo}");
                return 1;
            }

            string username = clo.Login;
            string password = clo.Password;
            string gitlabauthtoken = clo.AuthToken;
            string targetBranchName = clo.Branch;
            string trackerPath = clo.Tracker;
            string gitServer = clo.Server;
            string sourceBranchName = clo.SourceBranch;
            string patchdir = clo.PatchDir ?? localGitDir;

            DXVcsWrapper vcsWrapper = new DXVcsWrapper(vcsServer, username, password);

            TrackBranch trackBranch = FindBranch(targetBranchName, trackerPath, vcsWrapper);
            if (trackBranch == null) {
                return 1;
            }

            string historyPath = GetVcsSyncHistory(vcsWrapper, trackBranch.HistoryPath);
            if (historyPath == null)
                return 1;
            SyncHistory history = SyncHistory.Deserialize(historyPath);
            if (history == null)
                return 1;

            SyncHistoryWrapper syncHistory = new SyncHistoryWrapper(history, vcsWrapper, trackBranch.HistoryPath, historyPath);
            var head = syncHistory.GetHistoryHead();
            if (head == null)
                return 1;

            GitLabWrapper gitLabWrapper = new GitLabWrapper(gitServer, gitlabauthtoken);

            Project targetProject = gitLabWrapper.FindProject(targetRepoPath);
            if (targetProject == null) {
                Log.Error($"Can`t find target project {targetRepoPath}.");
                return 1;
            }
            Log.Message($"Target project url: {targetProject.HttpUrl}");

            Branch targetBranch = gitLabWrapper.GetBranch(targetProject, targetBranchName);
            if (targetBranch == null) {
                Log.Error($"Can`t find targetBranch branch {targetBranchName}");
                return 1;
            }
            Log.Message($"Target branch name: {targetBranch.Name}");

            var sourceProject = gitLabWrapper.FindProjectFromAll(sourceRepoPath);
            if (sourceProject == null) {
                Log.Error($"Can`t find source project {sourceRepoPath}");
                return 1;
            }
            Log.Message($"Source project url: {sourceProject.HttpUrl}");

            var sourceBranch = gitLabWrapper.GetBranch(sourceProject, sourceBranchName);
            if (sourceBranch == null) {
                Log.Error($"Source branch {sourceBranchName} was not found.");
                return 1;
            }
            Log.Message($"Target branch name: {sourceBranch.Name}");

            MergeRequest mergeRequest = gitLabWrapper.GetMergeRequests(targetProject, 
                x => x.SourceBranch == sourceBranchName && x.TargetBranch == targetBranchName && x.SourceProjectId == sourceProject.Id).FirstOrDefault();
            if (mergeRequest == null) {
                Log.Error($"Can`t find merge request.");
                return 1;
            }
            Log.Message($"Merge request id: {mergeRequest.Id}.");
            Log.Message($"Merge request title: {mergeRequest.Title}.");

            var comments = gitLabWrapper.GetComments(mergeRequest);
            var mergeRequestSyncOptions = comments?.Where(x => IsXml(x.Note)).Where(x => {
                var mr = MergeRequestOptions.ConvertFromString(x.Note);
                return mr?.ActionType == MergeRequestActionType.sync;
            }).Select(x => (MergeRequestSyncAction)MergeRequestOptions.ConvertFromString(x.Note).Action).LastOrDefault();

            if (mergeRequest.Assignee?.Name != username || (!mergeRequestSyncOptions?.PerformTesting ?? false)) {
                Log.Error($"Merge request is not assigned to service user {username} or doesn`t require testing.");
                return 1;
            }

            GitWrapper gitWrapper = CreateGitWrapper(sourceRepoPath, localGitDir, sourceBranchName, username, password);
            if (gitWrapper == null) {
                Log.Error("Can`t create git wrapper.");
                return 1;
            }

            var changes = gitLabWrapper
                .GetMergeRequestChanges(mergeRequest)
                .Where(x => trackBranch.TrackItems.FirstOrDefault(track => CheckItemForChangeSet(x, track)) != null)
                .Select(x => new PatchItem() {
                    SyncAction = CalcSyncAction(x),
                    OldPath = x.OldPath,
                    NewPath = x.NewPath,
                    OldVcsPath = CalcVcsPath(trackBranch, x.OldPath),
                    NewVcsPath = CalcVcsPath(trackBranch, x.NewPath),
                }).ToList();

            var patch = new PatchInfo() { TimeStamp = DateTime.Now.Ticks, Items = changes };

            var patchPath = Path.Combine(patchdir, patchZip);
            using (Package zip = Package.Open(patchPath, FileMode.Create)) {
                SavePatchInfo(patchdir, patch);
                AddPart(zip, patchdir, "patch.info");
                foreach (var path in CalcFilesForPatch(patch)) {
                    AddPart(zip, localGitDir, path);
                }
            }

            Log.Message($"Patch.info generated at {patchPath}");
            return 0;
        }
Example #7
0
        static int DoProcessTestResultsWork(ProcessTestsOptions clo) {
            Log.Message("process test results.");
            string targetRepoPath = GetSimpleGitHttpPath(clo.Repo);

            if (string.IsNullOrEmpty(targetRepoPath)) {
                Log.Error($"Can`t parse repo path {clo.Repo}");
                return 1;
            }

            string sourceRepoPath = GetSimpleGitHttpPath(clo.SourceRepo);
            if (string.IsNullOrEmpty(sourceRepoPath)) {
                Log.Error($"Can`t parse source repo path {clo.SourceRepo}");
                return 1;
            }

            string gitlabauthtoken = clo.AuthToken;
            string targetBranchName = clo.Branch;
            string gitServer = clo.Server;
            string sourceBranchName = clo.SourceBranch;

            GitLabWrapper gitLabWrapper = new GitLabWrapper(gitServer, gitlabauthtoken);

            Project targetProject = gitLabWrapper.FindProject(targetRepoPath);
            if (targetProject == null) {
                Log.Error($"Can`t find target project {targetRepoPath}.");
                return 1;
            }
            Branch targetBranch = gitLabWrapper.GetBranch(targetProject, targetBranchName);
            if (targetBranch == null) {
                Log.Error($"Can`t find targetBranch branch {targetBranchName}");
                return 1;
            }

            var sourceProject = gitLabWrapper.FindProjectFromAll(sourceRepoPath);
            if (sourceProject == null) {
                Log.Error($"Can`t find source project {sourceRepoPath}");
                return 1;
            }

            var sourceBranch = gitLabWrapper.GetBranch(sourceProject, sourceBranchName);
            if (sourceBranch == null) {
                Log.Error($"Source branch {sourceBranchName} was not found.");
                return 1;
            }

            MergeRequest mergeRequest = gitLabWrapper.GetMergeRequests(targetProject, x => x.SourceBranch == sourceBranchName && x.TargetBranch == targetBranchName).FirstOrDefault();
            if (mergeRequest == null) {
                Log.Error($"Can`t find merge request.");
                return 1;
            }

            var comments = gitLabWrapper.GetComments(mergeRequest);
            var mergeRequestSyncOptions = comments?.Where(x => IsXml(x.Note)).Where(x => {
                var mr = MergeRequestOptions.ConvertFromString(x.Note);
                return mr?.ActionType == MergeRequestActionType.sync;
            }).Select(x => (MergeRequestSyncAction)MergeRequestOptions.ConvertFromString(x.Note).Action).LastOrDefault();

            if (mergeRequestSyncOptions == null) {
                Log.Message("Merge request sync options not found. Nothing to do.");
                return 0;
            }

            if (!mergeRequestSyncOptions.PerformTesting) {
                Log.Message("Testing is disabled in config.");
                return 0;
            }

            Log.Message("Testing is enabled in config.");
            var commit = gitLabWrapper.GetMergeRequestCommits(mergeRequest).FirstOrDefault();
            if (commit == null) {
                Log.Message("Merge request has no commits.");
                return 0;
            }

            var mergeRequestBuild = gitLabWrapper.GetBuilds(mergeRequest, commit.Id).FirstOrDefault();
            if (mergeRequestBuild == null) {
                Log.Message("Merge request has no build.");
                return 0;
            }

            Log.Message($"Build has {mergeRequestBuild.Status} status.");

            if (mergeRequestBuild.Status == BuildStatus.success) {
                if (mergeRequestSyncOptions.AssignToSyncService) {
                    gitLabWrapper.UpdateMergeRequestAssignee(mergeRequest, mergeRequestSyncOptions.SyncTask);
                    Log.Message($"Success tests. Assigning to sync service {mergeRequestSyncOptions.SyncTask}");
                    return 0;
                }
                else {
                    gitLabWrapper.UpdateMergeRequestAssignee(mergeRequest, mergeRequest.Author.Username);
                    Log.Message($"Success tests. Assigning to back to author {mergeRequest.Author.Username}");
                    return 0;
                }
            }
            if (mergeRequestBuild.Status == BuildStatus.failed) {
                Log.Message($"Failed tests.");
                return 0;
            }
            Log.Message("Nothing happens.");
            return 0;
        }