Exemple #1
0
        private void createNewMergeRequest(string hostname, User currentUser, NewMergeRequestProperties initialProperties,
                                           IEnumerable <Project> fullProjectList, IEnumerable <User> fullUserList)
        {
            DataCache dataCache           = getDataCache(EDataCacheType.Live);
            var       sourceBranchesInUse = GitLabClient.Helpers.GetSourceBranchesByUser(getCurrentUser(), dataCache);

            MergeRequestPropertiesForm form = new NewMergeRequestForm(hostname,
                                                                      _shortcuts.GetProjectAccessor(), currentUser, initialProperties, fullProjectList, fullUserList,
                                                                      sourceBranchesInUse, _expressionResolver.Resolve(Program.ServiceManager.GetSourceBranchTemplate()));

            if (form.ShowDialog() != DialogResult.OK)
            {
                Trace.TraceInformation("[MainForm] User declined to create a merge request");
                return;
            }

            BeginInvoke(new Action(
                            async() =>
            {
                ProjectKey projectKey = new ProjectKey(hostname, form.ProjectName);
                SubmitNewMergeRequestParameters parameters = new SubmitNewMergeRequestParameters(
                    projectKey, form.SourceBranch, form.TargetBranch, form.Title,
                    form.AssigneeUsername, form.Description, form.DeleteSourceBranch, form.Squash,
                    form.IsHighPriority);
                await createNewMergeRequestAsync(parameters, form.SpecialNote);
            }));
        }
        async private Task createNewMergeRequestAsync(SubmitNewMergeRequestParameters parameters, string firstNote)
        {
            buttonCreateNew.Enabled  = false;
            labelWorkflowStatus.Text = "Creating a merge request at GitLab...";

            GitLabInstance  gitLabInstance = new GitLabInstance(parameters.ProjectKey.HostName, Program.Settings);
            MergeRequestKey?mrkOpt         = await MergeRequestEditHelper.SubmitNewMergeRequestAsync(gitLabInstance,
                                                                                                     _modificationNotifier, parameters, firstNote, getCurrentUser());

            if (mrkOpt == null)
            {
                // all error handling is done at the callee side
                string message = "Merge Request has not been created";
                labelWorkflowStatus.Text = message;
                buttonCreateNew.Enabled  = true;
                Trace.TraceInformation("[MainForm] {0}", message);
                return;
            }

            requestUpdates(null, new int[] { Constants.NewOrClosedMergeRequestRefreshListTimerInterval });

            labelWorkflowStatus.Text = String.Format("Merge Request !{0} has been created in project {1}",
                                                     mrkOpt.Value.IId, parameters.ProjectKey.ProjectName);
            buttonCreateNew.Enabled = true;

            _newMergeRequestDialogStatesByHosts[getHostName()] = new NewMergeRequestProperties(
                parameters.ProjectKey.ProjectName, null, null, parameters.AssigneeUserName, parameters.Squash,
                parameters.DeleteSourceBranch);

            Trace.TraceInformation(
                "[MainForm] Created a new merge request. " +
                "Project: {0}, SourceBranch: {1}, TargetBranch: {2}, Assignee: {3}, firstNote: {4}",
                parameters.ProjectKey.ProjectName, parameters.SourceBranch, parameters.TargetBranch,
                parameters.AssigneeUserName, firstNote);
        }
        private NewMergeRequestProperties getDefaultNewMergeRequestProperties(string hostname,
                                                                              User currentUser, string projectName)
        {
            // This state is expected to be used only once, next times 'persistent storage' is used
            NewMergeRequestProperties factoryProperties = new NewMergeRequestProperties(
                projectName, null, null, currentUser.Username, true, true);

            return(_newMergeRequestDialogStatesByHosts.TryGetValue(hostname, out var value) ? value : factoryProperties);
        }
        private void createMergeRequestFromUrl(ParsedNewMergeRequestUrl parsedNewMergeRequestUrl)
        {
            if (!checkIfMergeRequestCanBeCreated())
            {
                return;
            }

            NewMergeRequestProperties defaultProperties = getDefaultNewMergeRequestProperties(
                getHostName(), getCurrentUser(), null);
            NewMergeRequestProperties initialProperties = new NewMergeRequestProperties(
                parsedNewMergeRequestUrl.ProjectKey.ProjectName, parsedNewMergeRequestUrl.SourceBranch,
                parsedNewMergeRequestUrl.TargetBranchCandidates, defaultProperties.AssigneeUsername,
                defaultProperties.IsSquashNeeded, defaultProperties.IsBranchDeletionNeeded);
            var fullProjectList = _liveDataCache?.ProjectCache?.GetProjects() ?? Array.Empty <Project>();

            createNewMergeRequest(getHostName(), getCurrentUser(), initialProperties, fullProjectList);
        }
Exemple #5
0
        internal NewMergeRequestForm(string hostname, ProjectAccessor projectAccessor, User currentUser,
                                     NewMergeRequestProperties initialState, IEnumerable <Project> projects, IEnumerable <User> users,
                                     IEnumerable <ProjectBranchKey> sourceBranchesInUse, string sourceBranchTemplate)
            : base(hostname, projectAccessor, currentUser, isAllowedToChangeSource(initialState), users)
        {
            _initialState         = initialState;
            _projects             = projects ?? throw new ArgumentException("projects argument cannot be null");
            _sourceBranchTemplate = sourceBranchTemplate ?? String.Empty;
            _sourceBranchesInUse  = sourceBranchesInUse;

            if (isAllowedToChangeSource(_initialState))
            {
                comboBoxProject.SelectedIndexChanged +=
                    new System.EventHandler(this.comboBoxProject_SelectedIndexChanged);
                comboBoxSourceBranch.SelectedIndexChanged +=
                    new System.EventHandler(this.comboBoxSourceBranch_SelectedIndexChanged);
            }

            buttonCancel.ConfirmationText = "Do you want to discard creating a new merge request?";
        }
Exemple #6
0
        private void createNewMergeRequestByUserRequest()
        {
            Debug.Assert(getCurrentTabDataCacheType() == EDataCacheType.Live);
            DataCache dataCache = getDataCache(EDataCacheType.Live);

            if (!checkIfMergeRequestCanBeCreated())
            {
                return;
            }

            IEnumerable <Project> fullProjectList = dataCache?.ProjectCache?.GetProjects();
            bool isProjectListReady = fullProjectList?.Any() ?? false;

            if (!isProjectListReady)
            {
                Debug.Assert(false);
                Trace.TraceError("[MainForm] Project List is not ready at the moment of Create New click");
                return;
            }

            IEnumerable <User> fullUserList = dataCache?.UserCache?.GetUsers();
            bool isUserListReady            = fullUserList?.Any() ?? false;

            if (!isUserListReady)
            {
                Debug.Assert(false);
                Trace.TraceError("[MainForm] User List is not ready at the moment of Create New click");
                return;
            }

            showWarningAboutIntegrationWithGitUI();

            string projectName = getDefaultProjectName();
            NewMergeRequestProperties initialFormState = getDefaultNewMergeRequestProperties(
                getHostName(), getCurrentUser(), projectName);

            createNewMergeRequest(getHostName(), getCurrentUser(), initialFormState, fullProjectList, fullUserList);
        }
Exemple #7
0
        async private Task createNewMergeRequestAsync(SubmitNewMergeRequestParameters parameters, string firstNote)
        {
            setMergeRequestEditEnabled(false);
            addOperationRecord("Creating a merge request at GitLab has started");

            MergeRequestKey?mrkOpt = await MergeRequestEditHelper.SubmitNewMergeRequestAsync(
                parameters, firstNote, getCurrentUser(), _shortcuts);

            if (mrkOpt == null)
            {
                // all error handling is done at the callee side
                string message = "Merge Request has not been created";
                addOperationRecord(message);
                setMergeRequestEditEnabled(true);
                return;
            }

            requestUpdates(EDataCacheType.Live, null, new int[] {
                Program.Settings.NewOrClosedMergeRequestRefreshListDelayMs
            });

            addOperationRecord(String.Format("Merge Request !{0} has been created in project {1}",
                                             mrkOpt.Value.IId, parameters.ProjectKey.ProjectName));
            setMergeRequestEditEnabled(true);

            _newMergeRequestDialogStatesByHosts[getHostName()] = new NewMergeRequestProperties(
                parameters.ProjectKey.ProjectName, null, null, parameters.AssigneeUserName, parameters.Squash,
                parameters.DeleteSourceBranch);
            saveState();

            Trace.TraceInformation(
                "[MainForm] Created a new merge request. " +
                "Project: {0}, SourceBranch: {1}, TargetBranch: {2}, Assignee: {3}, firstNote: {4}",
                parameters.ProjectKey.ProjectName, parameters.SourceBranch, parameters.TargetBranch,
                parameters.AssigneeUserName, firstNote);
        }
Exemple #8
0
        private void createMergeRequestFromUrl(ParsedNewMergeRequestUrl parsedNewMergeRequestUrl)
        {
            if (!checkIfMergeRequestCanBeCreated())
            {
                return;
            }

            NewMergeRequestProperties defaultProperties = getDefaultNewMergeRequestProperties(
                getHostName(), getCurrentUser(), null);
            NewMergeRequestProperties initialProperties = new NewMergeRequestProperties(
                parsedNewMergeRequestUrl.ProjectKey.ProjectName, parsedNewMergeRequestUrl.SourceBranch,
                parsedNewMergeRequestUrl.TargetBranchCandidates, defaultProperties.AssigneeUsername,
                defaultProperties.IsSquashNeeded, defaultProperties.IsBranchDeletionNeeded);
            DataCache dataCache       = getDataCache(EDataCacheType.Live);
            var       fullProjectList = dataCache?.ProjectCache?.GetProjects() ?? Array.Empty <Project>();
            var       fullUserList    = dataCache?.UserCache?.GetUsers() ?? Array.Empty <User>();

            if (!fullUserList.Any())
            {
                Trace.TraceInformation("[MainForm] User list is not ready at the moment of creating a MR from URL");
            }

            createNewMergeRequest(getHostName(), getCurrentUser(), initialProperties, fullProjectList, fullUserList);
        }
Exemple #9
0
 private static bool isAllowedToChangeSource(NewMergeRequestProperties initialState)
 {
     return(String.IsNullOrEmpty(initialState.DefaultProject) ||
            String.IsNullOrEmpty(initialState.SourceBranch) ||
            initialState.TargetBranchCandidates == null);
 }