public GetBuilds ( NGitLab.Models.MergeRequest mergeRequest, NGitLab.Sha1 sha ) : IEnumerable |
||
mergeRequest | NGitLab.Models.MergeRequest | |
sha | NGitLab.Sha1 | |
리턴 | IEnumerable |
static void ForceSyncBuild(GitLabWrapper gitLabWrapper, MergeRequest mergeRequest, Project targetProject, MergeRequestHookClient hook) { var xmlComments = gitLabWrapper.GetComments(mergeRequest).Where(x => IsXml(x.Note)); var options = xmlComments.Select(x => MergeRequestOptions.ConvertFromString(x.Note)).FirstOrDefault(); if (options != null && options.ActionType == MergeRequestActionType.sync) { var action = (MergeRequestSyncAction)options.Action; if (action.PerformTesting) { Log.Message("Check build status before force build."); var commit = gitLabWrapper.GetMergeRequestCommits(mergeRequest).FirstOrDefault(); var build = commit != null ? gitLabWrapper.GetBuilds(mergeRequest, commit.Id).FirstOrDefault() : null; var buildStatus = build?.Status ?? BuildStatus.undefined; Log.Message($"Build status = {buildStatus}."); if (buildStatus == BuildStatus.success) ForceBuild(action.SyncTask); return; } Log.Message("Build forces without checking tests status."); ForceBuild(action.SyncTask); return; } string task = FarmIntegrator.FindTask($"{mergeRequest.TargetBranch}@{targetProject.PathWithNamespace}"); if (!string.IsNullOrEmpty(task)) { Log.Message($"Sync task {task} found by heuristic."); ForceBuild(task); return; } Log.Message("Merge request can`t be merged because merge request notes has no farm config."); Log.Message(""); }
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; }