async internal static Task <bool> ApplyChangesToMergeRequest(GitLabInstance gitLabInstance, IModificationListener modificationListener, ProjectKey projectKey, MergeRequest originalMergeRequest, ApplyMergeRequestChangesParameters parameters, string oldSpecialNote, string newSpecialNote, User currentUser) { if (String.IsNullOrEmpty(parameters.Title) || String.IsNullOrEmpty(parameters.TargetBranch) || parameters.AssigneeUserName == null || newSpecialNote == null || currentUser == null) { // this is unexpected due to UI restrictions, so don't implement detailed logging here MessageBox.Show("Invalid parameters for a merge request", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Trace.TraceError("[MergeRequestEditHelper] Invalid parameters for a merge request"); return(false); } string oldAssigneeUsername = originalMergeRequest.Assignee?.Username ?? String.Empty; User assignee = oldAssigneeUsername == parameters.AssigneeUserName ? originalMergeRequest.Assignee : await getUserAsync(gitLabInstance, parameters.AssigneeUserName); checkFoundAssignee(projectKey.HostName, parameters.AssigneeUserName, assignee); bool result = false; MergeRequestKey mrk = new MergeRequestKey(projectKey, originalMergeRequest.IId); if (oldSpecialNote != newSpecialNote) { result = await addComment(gitLabInstance, modificationListener, mrk, currentUser, newSpecialNote); } bool changed = oldAssigneeUsername != parameters.AssigneeUserName || originalMergeRequest.Force_Remove_Source_Branch != parameters.DeleteSourceBranch || originalMergeRequest.Squash != parameters.Squash || originalMergeRequest.Target_Branch != parameters.TargetBranch || originalMergeRequest.Title != parameters.Title || originalMergeRequest.Description != parameters.Description; if (!changed) { return(result); } int assigneeId = assignee?.Id ?? 0; // 0 means to unassign UpdateMergeRequestParameters updateMergeRequestParameters = new UpdateMergeRequestParameters( parameters.TargetBranch, parameters.Title, assigneeId, parameters.Description, null, parameters.DeleteSourceBranch, parameters.Squash); try { MergeRequest mergeRequest = await Shortcuts .GetMergeRequestEditor(gitLabInstance, modificationListener, mrk) .ModifyMergeRequest(updateMergeRequestParameters); } catch (MergeRequestEditorException ex) { reportErrorToUser(ex); return(result); } return(true); }
private void onLiveDataCacheConnected(string hostname, User user) { DataCache dataCache = getDataCache(EDataCacheType.Live); subscribeToLiveDataCacheInternalEvents(); createGitHelpers(dataCache, getCommitStorageFactory(false)); if (!_currentUser.ContainsKey(hostname)) { _currentUser.Add(hostname, user); } Program.FeedbackReporter.SetUserEMail(user.EMail); startRedrawTimer(); startEventPendingTimer(() => (dataCache?.ProjectCache?.GetProjects()?.Any() ?? false) && (dataCache?.UserCache?.GetUsers()?.Any() ?? false), ProjectAndUserCacheCheckTimerInterval, () => setMergeRequestEditEnabled(true)); addOperationRecord("Project list download has started"); startEventPendingTimer(() => (dataCache?.ProjectCache?.GetProjects()?.Any() ?? false), ProjectAndUserCacheCheckTimerInterval, () => { addOperationRecord("Project list download has finished. " + "It is possible to create/edit and accept merge requests"); setSearchByProjectEnabled(true); }); addOperationRecord("User list download has started"); startEventPendingTimer(() => (dataCache?.UserCache?.GetUsers()?.Any() ?? false), ProjectAndUserCacheCheckTimerInterval, () => { addOperationRecord("User list download has finished"); setSearchByAuthorEnabled(true, hostname); }); IEnumerable <MergeRequestKey> closedReviewed = gatherClosedReviewedMergeRequests(dataCache, hostname); cleanupReviewedMergeRequests(closedReviewed); loadRecentMergeRequests(); updateMergeRequestList(EDataCacheType.Live); enableMergeRequestListControls(true); enableSimpleSearchControls(true); addOperationRecord("Loading merge requests has completed"); updateCustomActionControls(); IEnumerable <ProjectKey> projects = getDataCache(EDataCacheType.Live).MergeRequestCache.GetProjects(); foreach (ProjectKey projectKey in projects) { requestCommitStorageUpdate(projectKey); } // current mode may have changed during 'await' if (getCurrentTabDataCacheType() == EDataCacheType.Live) { bool shouldUseLastSelection = _lastMergeRequestsByHosts.ContainsKey(hostname); string projectname = shouldUseLastSelection ? _lastMergeRequestsByHosts[hostname].ProjectKey.ProjectName : String.Empty; int iid = shouldUseLastSelection ? _lastMergeRequestsByHosts[hostname].IId : 0; MergeRequestKey mrk = new MergeRequestKey(new ProjectKey(hostname, projectname), iid); switchTabAndSelectMergeRequestOrAnythingElse(EDataCacheType.Live, mrk); } }
async private Task <bool> openUrlAtLiveTabAsync(MergeRequestKey mrk, string url, bool updateIfNeeded) { DataCache dataCache = getDataCache(EDataCacheType.Live); if (dataCache?.MergeRequestCache == null) { throw new UrlConnectionException("Merge request loading was cancelled due to host switch. "); } if (!dataCache.MergeRequestCache.GetMergeRequests(mrk.ProjectKey).Any(x => x.IId == mrk.IId)) { // We need to update the MR list here because cached one is possible outdated if (updateIfNeeded) { addOperationRecord(String.Format( "Merge Request with IId {0} is not found in the cache. List update has started.", mrk.IId)); await checkForUpdatesAsync(getDataCache(EDataCacheType.Live), null); addOperationRecord("Merge request list update has completed"); if (getHostName() != mrk.ProjectKey.HostName || dataCache.MergeRequestCache == null) { throw new UrlConnectionException("Merge request loading was cancelled due to host switch. "); } } if (!checkProjectWorkflowFilters(mrk)) { // this may happen if project list changed while we were in 'await' return(false); } } if (!switchTabAndSelectMergeRequest(EDataCacheType.Live, mrk) && getListView(EDataCacheType.Live).Enabled) { // We could not select MR, but let's check if it is cached or not. if (dataCache.MergeRequestCache.GetMergeRequests(mrk.ProjectKey).Any(x => x.IId == mrk.IId)) { // If it is cached, it is probably hidden by filters and user might want to un-hide it. if (!unhideFilteredMergeRequest(EDataCacheType.Live)) { return(false); // user decided to not un-hide merge request } if (!switchTabAndSelectMergeRequest(EDataCacheType.Live, mrk)) { Debug.Assert(false); Trace.TraceError(String.Format("[MainForm] Cannot open URL {0}, although MR is cached", url)); throw new UrlConnectionException("Something went wrong. "); } } else { if (ConfigurationHelper.IsProjectBasedWorkflowSelected(Program.Settings)) { Debug.Assert(false); Trace.TraceError(String.Format("[MainForm] Cannot open URL {0} by unknown reason", url)); throw new UrlConnectionException("Something went wrong. "); } return(false); } } return(true); }
private void onPreLoadDiscussions(MergeRequestKey mrk) { onDiscussionManagerEvent(); }
private void onPostLoadDiscussions(MergeRequestKey mrk, IEnumerable <Discussion> discussions) { onDiscussionManagerEvent(); }
private static string saveMergeRequestKey(MergeRequestKey key) { return(saveProjectKey(key.ProjectKey) + "|" + saveIId(key.IId)); }
private void onPostLoadTrackedTime(ITotalTimeCache totalTimeCache, MergeRequestKey mrk) { onTrackedTimeManagerEvent(totalTimeCache, mrk); }
internal static SingleDiscussionAccessor GetSingleDiscussionAccessor(GitLabInstance gitLabInstance, IModificationListener modificationListener, MergeRequestKey mrk, string discussionId) { return(GetMergeRequestAccessor(gitLabInstance, modificationListener, mrk.ProjectKey) .GetSingleMergeRequestAccessor(mrk.IId) .GetDiscussionAccessor() .GetSingleDiscussionAccessor(discussionId)); }
internal static IDiscussionCreator GetDiscussionCreator(GitLabInstance gitLabInstance, IModificationListener modificationListener, MergeRequestKey mrk, User user) { return(GetMergeRequestAccessor(gitLabInstance, modificationListener, mrk.ProjectKey) .GetSingleMergeRequestAccessor(mrk.IId) .GetDiscussionAccessor() .GetDiscussionCreator(user)); }
internal static ITimeTracker GetTimeTracker(GitLabInstance gitLabInstance, IModificationListener modificationListener, MergeRequestKey mrk) { return(GetMergeRequestAccessor(gitLabInstance, modificationListener, mrk.ProjectKey) .GetSingleMergeRequestAccessor(mrk.IId).GetTimeTracker()); }
private void setLatestChange(MergeRequestKey mrk, DateTime dateTime) { _latestChanges[mrk] = dateTime; }
private DateTime getLatestChange(MergeRequestKey mrk) { return(_latestChanges.ContainsKey(mrk) ? _latestChanges[mrk] : DateTime.MinValue); }