Inheritance: ProjectHookClient
Exemple #1
0
 static bool IsOpenedState(MergeRequestHookClient hook) {
     return hook.Attributes.State == MergerRequestState.opened || hook.Attributes.State == MergerRequestState.opened;
 }
Exemple #2
0
        static bool ShouldForceSyncTask(MergeRequest mergeRequest, MergeRequestHookClient hook) {
            var assignee = mergeRequest.Assignee;
            if (assignee == null || !assignee.Name.StartsWith("dxvcs2git")) {
                Log.Message("Force sync rejected because assignee is not set or not sync task.");
                return false;
            }

            if (hook.Attributes.WorkInProcess) {
                Log.Message("Force sync rejected because merge request has work in process flag.");
                return false;
            }

            if (hook.Attributes.MergeStatus == "unchecked" || hook.Attributes.MergeStatus == "can_be_merged")
                return true;
            Log.Message("Force sync rejected because merge request can`t be merged automatically.");
            return false;
        }
Exemple #3
0
        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("");
        }
Exemple #4
0
        static void ProcessMergeRequestHook(GitLabWrapper gitLabWrapper, string serviceUser, MergeRequestHookClient hook, bool supportSendingMessages, string farmTaskName) {
            Log.Message($"Merge hook title: {hook.Attributes.Description}");
            Log.Message($"Merge hook state: {hook.Attributes.State}");

            var targetProject = gitLabWrapper.GetProject(hook.Attributes.TargetProjectId);
            var mergeRequest = gitLabWrapper.GetMergeRequest(targetProject, hook.Attributes.Id);
            if (supportSendingMessages)
                SendMessage(serviceUser, hook.Json, farmTaskName);

            if (!IsOpenedState(hook))
                return;

            Log.Message($"Merge hook action: {hook.Attributes.Action}");
            Log.Message($"Merge hook merge status: {hook.Attributes.MergeStatus}");
            Log.Message($"Merge hook author: {gitLabWrapper.GetUser(hook.Attributes.AuthorId).Name}.");
            Log.Message($"Merge hook target branch: {hook.Attributes.TargetBranch}.");
            Log.Message($"Merge hook sourceBranch branch: {hook.Attributes.SourceBranch}.");

            if (ShouldForceSyncTask(mergeRequest, hook)) {
                ForceSyncBuild(gitLabWrapper, mergeRequest, targetProject, hook);
                return;
            }
        }
Exemple #5
0
 void ShowMergeRequestNotification(BranchViewModel branchViewModel, MergeRequestHookClient hook) {
     var mergeStatus = hook.Attributes.State;
     if (mergeStatus == MergerRequestState.merged) {
         string message = $"Merge request {hook.Attributes.Title} for branch {hook.Attributes.SourceBranch} was merged.";
         var notification = NotificationService.CreatePredefinedNotification(message, null, null, null);
         var task = notification.ShowAsync();
         task.ContinueWith(x => PerformClick(x.Result));
         return;
     }
     if (mergeStatus == MergerRequestState.closed) {
         string message = $"Merge request {hook.Attributes.Title} for branch {hook.Attributes.SourceBranch} was closed.";
         var notification = NotificationService.CreatePredefinedNotification(message, null, null, null);
         var task = notification.ShowAsync();
         task.ContinueWith(x => PerformClick(x.Result));
         return;
     }
     if (branchViewModel.MergeRequest.AssigneeId != hook.Attributes.AssigneeId) {
         string message = $"Assignee for merge request {hook.Attributes.Title} for branch {hook.Attributes.SourceBranch} was changed.";
         var notification = NotificationService.CreatePredefinedNotification(message, null, null, null);
         var task = notification.ShowAsync();
         task.ContinueWith(x => PerformClick(x.Result));
         return;
     }
 }
Exemple #6
0
 void ProcessMergeRequestHook(MergeRequestHookClient hook) {
     if (Repositories == null)
         return;
     int mergeRequestId = hook.Attributes.Id;
     var selectedBranch = Repositories.SelectedBranch;
     if (selectedBranch != null) {
         var mergeRequest = selectedBranch.MergeRequest;
         if (mergeRequest != null) {
             if (mergeRequest.MergeRequestId == mergeRequestId) {
                 selectedBranch.RefreshMergeRequest();
                 RepositoriesViewModel.RaiseRefreshSelectedBranch();
                 Log.Message("Selected branch refreshed.");
             }
         }
     }
     if (Repositories.Repositories == null)
         return;
     foreach (var repo in Repositories.Repositories) {
         var branch = repo.Branches.Where(x => x.MergeRequest != null).FirstOrDefault(x => x.MergeRequest.MergeRequestId == mergeRequestId);
         if (branch != null)
             ShowMergeRequestNotification(branch, hook);
         break;
     }
 }