Inheritance: ProjectHookClient
Example #1
0
        static void ProcessBuildHook(GitLabWrapper gitLabWrapper, string serviceUser, BuildHookClient hook, bool supportSendingMessages, string farmTaskName) {
            Log.Message($"Build hook title: {hook.BuildName}");
            Log.Message($"Build hook status: {hook.Status}");

            if (supportSendingMessages)
                SendMessage(serviceUser, hook.Json, farmTaskName);

            if (hook.Status == BuildStatus.success) {
                Project project = gitLabWrapper.GetProject(hook.ProjectId);
                if (project == null) {
                    Log.Message($"Can`t find project {hook.ProjectName}.");
                    return;
                }
                Log.Message($"Project: {project.PathWithNamespace}");
                var mergeRequest = CalcMergeRequest(gitLabWrapper, hook, project);
                if (mergeRequest == null) {
                    Log.Message("Can`t find merge request.");
                    return;
                }
                Log.Message($"Merge request: id = {mergeRequest.Id} title = {mergeRequest.Title}");
                Log.Message($"Merge request state = {mergeRequest.State}");
                if (mergeRequest.State == "opened" || mergeRequest.State == "reopened") {
                    var latestCommit = gitLabWrapper.GetMergeRequestCommits(mergeRequest).FirstOrDefault();
                    if (latestCommit == null) {
                        Log.Message("Wrong merge request found.");
                        return;
                    }
                    Log.Message($"Merge request latest commit sha = {latestCommit.Id}");
                    if (!latestCommit.Id.Equals(new Sha1(hook.Commit.Id))) {
                        Log.Message($"Additional commits has been added {hook.Commit.Id}");
                        return;
                    }

                    var xmlComments = gitLabWrapper.GetComments(mergeRequest).Where(x => IsXml(x.Note));
                    var options = xmlComments.Select(x => MergeRequestOptions.ConvertFromString(x.Note)).FirstOrDefault();
                    if (options?.ActionType == MergeRequestActionType.sync) {
                        Log.Message("Sync options found.");
                        var syncOptions = (MergeRequestSyncAction)options.Action;
                        Log.Message($"Sync options perform testing is {syncOptions.PerformTesting}");
                        Log.Message($"Sync options assign to service is {syncOptions.AssignToSyncService}");
                        Log.Message($"Sync options sync task is {syncOptions.SyncTask}");
                        Log.Message($"Sync options sync service is {syncOptions.SyncService}");
                        if (syncOptions.PerformTesting && syncOptions.AssignToSyncService) {
                            gitLabWrapper.UpdateMergeRequestAssignee(mergeRequest, syncOptions.SyncService);
                            ForceBuild(syncOptions.SyncTask);
                        }
                        return;
                    }
                    Log.Message("Sync options not found.");
                }
            }
        }
Example #2
0
 static MergeRequest CalcMergeRequest(GitLabWrapper gitLabWrapper, BuildHookClient hook, Project project) {
     foreach (var checkProject in gitLabWrapper.GetProjects()) {
         var mergeRequests = gitLabWrapper.GetMergeRequests(checkProject, x => x.SourceProjectId == project.Id);
         var mergeRequest = mergeRequests.FirstOrDefault(x => x.SourceBranch == hook.Branch);
         if (mergeRequest != null)
             return mergeRequest;
     }
     return null;
 }
Example #3
0
 void ProcessBuildHook(BuildHookClient hook) {
     var selectedBranch = Repositories.SelectedBranch;
     var mergeRequest = selectedBranch?.MergeRequest;
     if (mergeRequest == null)
         return;
     if (mergeRequest.SourceBranch != hook.Branch)
         return;
     if (selectedBranch.Repository.Origin.Id != hook.ProjectId)
         return;
     selectedBranch.RefreshMergeRequest();
     RepositoriesViewModel.RaiseRefreshSelectedBranch();
 }