2019-01-14 16:38:49 +00:00
|
|
|
import getStateKey from 'ee_else_ce/vue_merge_request_widget/stores/get_state_key';
|
2022-05-13 09:07:54 +00:00
|
|
|
import { badgeState } from '~/issuable/components/status_box.vue';
|
2021-07-14 09:08:33 +00:00
|
|
|
import { formatDate, getTimeago } from '~/lib/utils/datetime_utility';
|
2021-09-27 15:10:13 +00:00
|
|
|
import { machine } from '~/lib/utils/finite_state_machine';
|
|
|
|
import {
|
|
|
|
MTWPS_MERGE_STRATEGY,
|
|
|
|
MT_MERGE_STRATEGY,
|
|
|
|
MWPS_MERGE_STRATEGY,
|
|
|
|
STATE_MACHINE,
|
|
|
|
stateToTransitionMap,
|
|
|
|
} from '../constants';
|
2021-02-01 15:08:56 +00:00
|
|
|
import { stateKey } from './state_maps';
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2021-07-14 09:08:33 +00:00
|
|
|
const { format } = getTimeago();
|
|
|
|
|
2021-09-27 15:10:13 +00:00
|
|
|
const { states } = STATE_MACHINE;
|
|
|
|
const { IDLE } = states;
|
|
|
|
|
2017-05-09 04:15:34 +00:00
|
|
|
export default class MergeRequestStore {
|
|
|
|
constructor(data) {
|
2017-05-18 02:56:43 +00:00
|
|
|
this.sha = data.diff_head_sha;
|
2017-05-26 14:37:09 +00:00
|
|
|
this.gitlabLogo = data.gitlabLogo;
|
2017-05-26 14:26:06 +00:00
|
|
|
|
2020-07-17 06:09:11 +00:00
|
|
|
this.apiApprovalsPath = data.api_approvals_path;
|
|
|
|
this.apiApprovePath = data.api_approve_path;
|
|
|
|
this.apiUnapprovePath = data.api_unapprove_path;
|
|
|
|
this.hasApprovalsAvailable = data.has_approvals_available;
|
|
|
|
|
2021-09-27 15:10:13 +00:00
|
|
|
this.stateMachine = machine(STATE_MACHINE.definition);
|
|
|
|
this.machineValue = this.stateMachine.value;
|
2022-09-01 15:12:07 +00:00
|
|
|
this.mergeDetailsCollapsed = window.innerWidth < 768;
|
2021-09-27 15:10:13 +00:00
|
|
|
|
2019-08-09 21:01:55 +00:00
|
|
|
this.setPaths(data);
|
|
|
|
|
2017-05-09 04:15:34 +00:00
|
|
|
this.setData(data);
|
2022-03-17 15:07:44 +00:00
|
|
|
this.initCodeQualityReport(data);
|
2021-08-14 00:10:05 +00:00
|
|
|
this.setGitpodData(data);
|
2017-05-09 04:15:34 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 15:07:44 +00:00
|
|
|
initCodeQualityReport(data) {
|
|
|
|
this.blobPath = data.blob_path;
|
|
|
|
this.codeQuality = data.codequality_reports_path;
|
|
|
|
}
|
|
|
|
|
2018-12-11 18:27:35 +00:00
|
|
|
setData(data, isRebased) {
|
2020-07-17 06:09:11 +00:00
|
|
|
this.initApprovals();
|
|
|
|
|
2021-05-04 12:10:04 +00:00
|
|
|
this.updateStatusState(data.state);
|
|
|
|
|
2018-12-11 18:27:35 +00:00
|
|
|
if (isRebased) {
|
|
|
|
this.sha = data.diff_head_sha;
|
|
|
|
}
|
|
|
|
|
2017-05-09 04:15:34 +00:00
|
|
|
const pipelineStatus = data.pipeline ? data.pipeline.details.status : null;
|
|
|
|
|
2018-05-29 09:51:43 +00:00
|
|
|
this.squash = data.squash;
|
2020-07-07 00:08:58 +00:00
|
|
|
this.squashIsEnabledByDefault = data.squash_enabled_by_default;
|
|
|
|
this.squashIsReadonly = data.squash_readonly;
|
2018-05-29 09:51:43 +00:00
|
|
|
this.enableSquashBeforeMerge = this.enableSquashBeforeMerge || true;
|
2020-07-07 00:08:58 +00:00
|
|
|
this.squashIsSelected = data.squash_readonly ? data.squash_on_merge : data.squash;
|
2018-05-29 09:51:43 +00:00
|
|
|
|
2018-07-10 09:35:16 +00:00
|
|
|
this.iid = data.iid;
|
2017-05-09 04:15:34 +00:00
|
|
|
this.title = data.title;
|
|
|
|
this.targetBranch = data.target_branch;
|
2019-04-15 13:25:48 +00:00
|
|
|
this.targetBranchSha = data.target_branch_sha;
|
2017-05-09 04:15:34 +00:00
|
|
|
this.sourceBranch = data.source_branch;
|
2018-12-21 10:47:03 +00:00
|
|
|
this.sourceBranchProtected = data.source_branch_protected;
|
2019-08-14 21:09:46 +00:00
|
|
|
this.conflictsDocsPath = data.conflicts_docs_path;
|
2019-02-06 12:33:11 +00:00
|
|
|
this.commitMessage = data.default_merge_commit_message;
|
2020-09-10 12:08:54 +00:00
|
|
|
this.shortMergeCommitSha = data.short_merged_commit_sha;
|
|
|
|
this.mergeCommitSha = data.merged_commit_sha;
|
2019-02-06 12:33:11 +00:00
|
|
|
this.commitMessageWithDescription = data.default_merge_commit_message_with_description;
|
2017-05-09 04:15:34 +00:00
|
|
|
this.divergedCommitsCount = data.diverged_commits_count;
|
|
|
|
this.pipeline = data.pipeline || {};
|
2019-12-11 09:08:12 +00:00
|
|
|
this.pipelineCoverageDelta = data.pipeline_coverage_delta;
|
2020-09-04 21:08:41 +00:00
|
|
|
this.buildsWithCoverage = data.builds_with_coverage;
|
2018-10-29 11:34:41 +00:00
|
|
|
this.mergePipeline = data.merge_pipeline || {};
|
2017-05-09 04:15:34 +00:00
|
|
|
this.deployments = this.deployments || data.deployments || [];
|
2018-10-29 11:34:41 +00:00
|
|
|
this.postMergeDeployments = this.postMergeDeployments || [];
|
2019-02-07 15:14:56 +00:00
|
|
|
this.commits = data.commits_without_merge_commits || [];
|
|
|
|
this.squashCommitMessage = data.default_squash_commit_message;
|
2019-08-09 21:01:55 +00:00
|
|
|
this.rebaseInProgress = data.rebase_in_progress;
|
2019-12-06 12:06:21 +00:00
|
|
|
this.mergeRequestDiffsPath = data.diffs_path;
|
2020-07-17 06:09:11 +00:00
|
|
|
this.approvalsWidgetType = data.approvals_widget_type;
|
2021-04-07 09:09:06 +00:00
|
|
|
this.mergeRequestWidgetPath = data.merge_request_widget_path;
|
2017-05-09 04:15:34 +00:00
|
|
|
|
|
|
|
if (data.issues_links) {
|
|
|
|
const links = data.issues_links;
|
|
|
|
const { closing } = links;
|
|
|
|
const mentioned = links.mentioned_but_not_closing;
|
|
|
|
const assignToMe = links.assign_to_closing;
|
2022-03-14 15:09:32 +00:00
|
|
|
const unassignedCount = links.assign_to_closing_count;
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2022-03-14 15:09:32 +00:00
|
|
|
if (closing || mentioned || unassignedCount) {
|
2021-08-16 18:10:51 +00:00
|
|
|
this.relatedLinks = {
|
|
|
|
closing,
|
|
|
|
mentioned,
|
|
|
|
assignToMe,
|
|
|
|
closingCount: links.closing_count,
|
|
|
|
mentionedCount: links.mentioned_count,
|
2022-03-14 15:09:32 +00:00
|
|
|
unassignedCount: links.assign_to_closing_count,
|
2021-08-16 18:10:51 +00:00
|
|
|
};
|
2017-05-09 04:15:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.updatedAt = data.updated_at;
|
2017-12-07 17:41:30 +00:00
|
|
|
this.metrics = MergeRequestStore.buildMetrics(data.metrics);
|
2019-05-22 11:45:27 +00:00
|
|
|
this.setToAutoMergeBy = MergeRequestStore.formatUserObject(data.merge_user || {});
|
2017-05-09 04:15:34 +00:00
|
|
|
this.mergeUserId = data.merge_user_id;
|
|
|
|
this.currentUserId = gon.current_user_id;
|
|
|
|
this.sourceBranchRemoved = !data.source_branch_exists;
|
2017-05-25 16:47:06 +00:00
|
|
|
this.shouldRemoveSourceBranch = data.remove_source_branch || false;
|
2019-05-22 11:45:27 +00:00
|
|
|
this.autoMergeStrategy = data.auto_merge_strategy;
|
2019-06-11 14:19:22 +00:00
|
|
|
this.availableAutoMergeStrategies = data.available_auto_merge_strategies;
|
|
|
|
this.preferredAutoMergeStrategy = MergeRequestStore.getPreferredAutoMergeStrategy(
|
|
|
|
this.availableAutoMergeStrategies,
|
|
|
|
);
|
2017-09-18 22:06:47 +00:00
|
|
|
this.ffOnlyEnabled = data.ff_only_enabled;
|
2017-05-09 04:15:34 +00:00
|
|
|
this.isRemovingSourceBranch = this.isRemovingSourceBranch || false;
|
2020-08-18 18:10:10 +00:00
|
|
|
this.mergeRequestState = data.state;
|
|
|
|
this.isOpen = this.mergeRequestState === 'opened';
|
2019-12-06 12:06:21 +00:00
|
|
|
this.latestSHA = data.diff_head_sha;
|
2017-10-02 16:11:18 +00:00
|
|
|
this.isMergeAllowed = data.mergeable || false;
|
2017-07-31 22:01:36 +00:00
|
|
|
this.mergeOngoing = data.merge_ongoing;
|
2018-05-23 01:54:57 +00:00
|
|
|
this.allowCollaboration = data.allow_collaboration;
|
2019-04-15 13:25:48 +00:00
|
|
|
this.sourceProjectId = data.source_project_id;
|
|
|
|
this.targetProjectId = data.target_project_id;
|
2017-05-09 04:15:34 +00:00
|
|
|
|
|
|
|
// CI related
|
|
|
|
this.hasCI = data.has_ci;
|
|
|
|
this.ciStatus = data.ci_status;
|
2018-07-10 09:35:16 +00:00
|
|
|
this.isPipelinePassing =
|
2019-04-12 12:39:10 +00:00
|
|
|
this.ciStatus === 'success' || this.ciStatus === 'success-with-warnings';
|
2017-09-01 00:46:18 +00:00
|
|
|
this.isPipelineSkipped = this.ciStatus === 'skipped';
|
2017-05-09 04:15:34 +00:00
|
|
|
this.pipelineDetailedStatus = pipelineStatus;
|
|
|
|
this.isPipelineActive = data.pipeline ? data.pipeline.active : false;
|
2020-09-15 21:09:35 +00:00
|
|
|
this.isPipelineBlocked =
|
|
|
|
data.only_allow_merge_if_pipeline_succeeds && pipelineStatus?.group === 'manual';
|
2017-05-09 04:15:34 +00:00
|
|
|
this.ciStatusFaviconPath = pipelineStatus ? pipelineStatus.favicon : null;
|
2020-04-13 12:10:03 +00:00
|
|
|
this.terraformReportsPath = data.terraform_reports_path;
|
2018-07-31 15:50:34 +00:00
|
|
|
this.testResultsPath = data.test_reports_path;
|
2020-05-11 21:09:40 +00:00
|
|
|
this.accessibilityReportPath = data.accessibility_report_path;
|
2019-10-14 09:07:54 +00:00
|
|
|
this.exposedArtifactsPath = data.exposed_artifacts_path;
|
2019-08-09 21:01:55 +00:00
|
|
|
this.cancelAutoMergePath = data.cancel_auto_merge_path;
|
|
|
|
this.canCancelAutomaticMerge = Boolean(data.cancel_auto_merge_path);
|
|
|
|
|
|
|
|
this.newBlobPath = data.new_blob_path;
|
|
|
|
this.sourceBranchPath = data.source_branch_path;
|
|
|
|
this.sourceBranchLink = data.source_branch_with_namespace_link;
|
|
|
|
this.rebasePath = data.rebase_path;
|
|
|
|
this.targetBranchPath = data.target_branch_commits_path;
|
|
|
|
this.targetBranchTreePath = data.target_branch_tree_path;
|
|
|
|
this.conflictResolutionPath = data.conflict_resolution_path;
|
|
|
|
this.removeWIPPath = data.remove_wip_path;
|
|
|
|
this.createIssueToResolveDiscussionsPath = data.create_issue_to_resolve_discussions_path;
|
|
|
|
this.mergePath = data.merge_path;
|
2020-09-10 12:08:54 +00:00
|
|
|
this.mergeCommitPath = data.merged_commit_path;
|
2019-08-09 21:01:55 +00:00
|
|
|
this.canPushToSourceBranch = data.can_push_to_source_branch;
|
|
|
|
|
2020-09-12 00:08:44 +00:00
|
|
|
if (!window.gon?.features?.mergeRequestWidgetGraphql) {
|
|
|
|
this.autoMergeEnabled = Boolean(data.auto_merge_enabled);
|
|
|
|
this.canBeMerged = data.can_be_merged || false;
|
|
|
|
this.canMerge = Boolean(data.merge_path);
|
|
|
|
this.commitsCount = data.commits_count;
|
|
|
|
this.branchMissing = data.branch_missing;
|
|
|
|
this.hasConflicts = data.has_conflicts;
|
|
|
|
this.hasMergeableDiscussionsState = data.mergeable_discussions_state === false;
|
|
|
|
this.isPipelineFailed = this.ciStatus === 'failed' || this.ciStatus === 'canceled';
|
|
|
|
this.mergeError = data.merge_error;
|
|
|
|
this.mergeStatus = data.merge_status;
|
|
|
|
this.onlyAllowMergeIfPipelineSucceeds = data.only_allow_merge_if_pipeline_succeeds || false;
|
2022-08-24 18:12:18 +00:00
|
|
|
this.allowMergeOnSkippedPipeline = data.allow_merge_on_skipped_pipeline || false;
|
2020-09-12 00:08:44 +00:00
|
|
|
this.projectArchived = data.project_archived;
|
|
|
|
this.isSHAMismatch = this.sha !== data.diff_head_sha;
|
|
|
|
this.shouldBeRebased = Boolean(data.should_be_rebased);
|
2021-11-10 18:12:35 +00:00
|
|
|
this.draft = data.draft;
|
2020-08-18 18:10:10 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 21:01:55 +00:00
|
|
|
const currentUser = data.current_user;
|
|
|
|
|
2020-04-24 09:09:44 +00:00
|
|
|
this.cherryPickInForkPath = currentUser.cherry_pick_in_fork_path;
|
|
|
|
this.revertInForkPath = currentUser.revert_in_fork_path;
|
|
|
|
|
|
|
|
this.canRemoveSourceBranch = currentUser.can_remove_source_branch || false;
|
|
|
|
this.canCreateIssue = currentUser.can_create_issue || false;
|
|
|
|
this.canCherryPickInCurrentMR = currentUser.can_cherry_pick_on_current_merge_request || false;
|
|
|
|
this.canRevertInCurrentMR = currentUser.can_revert_on_current_merge_request || false;
|
2018-07-31 15:50:34 +00:00
|
|
|
|
2020-08-18 18:10:10 +00:00
|
|
|
this.setState();
|
|
|
|
}
|
|
|
|
|
2020-09-12 00:08:44 +00:00
|
|
|
setGraphqlData(project) {
|
|
|
|
const { mergeRequest } = project;
|
2021-03-25 06:09:02 +00:00
|
|
|
const pipeline = mergeRequest.headPipeline;
|
2020-09-12 00:08:44 +00:00
|
|
|
|
2021-05-04 12:10:04 +00:00
|
|
|
this.updateStatusState(mergeRequest.state);
|
|
|
|
|
2020-09-12 00:08:44 +00:00
|
|
|
this.projectArchived = project.archived;
|
|
|
|
this.onlyAllowMergeIfPipelineSucceeds = project.onlyAllowMergeIfPipelineSucceeds;
|
2022-08-24 18:12:18 +00:00
|
|
|
this.allowMergeOnSkippedPipeline = project.allowMergeOnSkippedPipeline;
|
2020-09-12 00:08:44 +00:00
|
|
|
|
|
|
|
this.autoMergeEnabled = mergeRequest.autoMergeEnabled;
|
|
|
|
this.canBeMerged = mergeRequest.mergeStatus === 'can_be_merged';
|
|
|
|
this.canMerge = mergeRequest.userPermissions.canMerge;
|
|
|
|
this.ciStatus = pipeline?.status.toLowerCase();
|
2021-02-17 06:09:21 +00:00
|
|
|
|
|
|
|
if (pipeline?.warnings && this.ciStatus === 'success') {
|
|
|
|
this.ciStatus = `${this.ciStatus}-with-warnings`;
|
|
|
|
}
|
|
|
|
|
2021-02-24 18:11:28 +00:00
|
|
|
this.commitsCount = mergeRequest.commitCount;
|
2020-09-12 00:08:44 +00:00
|
|
|
this.branchMissing = !mergeRequest.sourceBranchExists || !mergeRequest.targetBranchExists;
|
|
|
|
this.hasConflicts = mergeRequest.conflicts;
|
|
|
|
this.hasMergeableDiscussionsState = mergeRequest.mergeableDiscussionsState === false;
|
|
|
|
this.mergeError = mergeRequest.mergeError;
|
|
|
|
this.mergeStatus = mergeRequest.mergeStatus;
|
|
|
|
this.isPipelineFailed = this.ciStatus === 'failed' || this.ciStatus === 'canceled';
|
|
|
|
this.isSHAMismatch = this.sha !== mergeRequest.diffHeadSha;
|
|
|
|
this.shouldBeRebased = mergeRequest.shouldBeRebased;
|
2021-11-10 18:12:35 +00:00
|
|
|
this.draft = mergeRequest.draft;
|
2021-02-04 12:09:25 +00:00
|
|
|
this.mergeRequestState = mergeRequest.state;
|
2022-09-21 12:13:58 +00:00
|
|
|
this.detailedMergeStatus = mergeRequest.detailedMergeStatus;
|
2020-08-18 18:10:10 +00:00
|
|
|
|
|
|
|
this.setState();
|
2017-05-09 04:15:34 +00:00
|
|
|
}
|
|
|
|
|
2021-05-04 12:10:04 +00:00
|
|
|
updateStatusState(state) {
|
2022-05-13 09:07:54 +00:00
|
|
|
if (this.mergeRequestState !== state && badgeState.updateStatus) {
|
|
|
|
badgeState.updateStatus();
|
2021-05-04 12:10:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-14 00:10:05 +00:00
|
|
|
setGitpodData(data) {
|
|
|
|
this.showGitpodButton = data.show_gitpod_button;
|
|
|
|
this.gitpodUrl = data.gitpod_url;
|
|
|
|
this.gitpodEnabled = data.gitpod_enabled;
|
2022-01-12 03:11:06 +00:00
|
|
|
this.userPreferencesGitpodPath = data.user_preferences_gitpod_path;
|
|
|
|
this.userProfileEnableGitpodPath = data.user_profile_enable_gitpod_path;
|
2021-08-14 00:10:05 +00:00
|
|
|
}
|
|
|
|
|
2020-08-18 18:10:10 +00:00
|
|
|
setState() {
|
2017-07-31 22:01:36 +00:00
|
|
|
if (this.mergeOngoing) {
|
|
|
|
this.state = 'merging';
|
2021-09-27 15:10:13 +00:00
|
|
|
} else if (this.isOpen) {
|
2020-08-18 18:10:10 +00:00
|
|
|
this.state = getStateKey.call(this);
|
2017-05-09 04:15:34 +00:00
|
|
|
} else {
|
2020-08-18 18:10:10 +00:00
|
|
|
switch (this.mergeRequestState) {
|
2017-05-09 04:15:34 +00:00
|
|
|
case 'merged':
|
|
|
|
this.state = 'merged';
|
|
|
|
break;
|
|
|
|
case 'closed':
|
|
|
|
this.state = 'closed';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this.state = null;
|
|
|
|
}
|
|
|
|
}
|
2021-09-27 15:10:13 +00:00
|
|
|
|
|
|
|
this.translateStateToMachine();
|
2017-05-09 04:15:34 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 21:01:55 +00:00
|
|
|
setPaths(data) {
|
|
|
|
// Paths are set on the first load of the page and not auto-refreshed
|
|
|
|
this.squashBeforeMergeHelpPath = data.squash_before_merge_help_path;
|
2020-07-13 15:09:08 +00:00
|
|
|
this.mrTroubleshootingDocsPath = data.mr_troubleshooting_docs_path;
|
|
|
|
this.ciTroubleshootingDocsPath = data.ci_troubleshooting_docs_path;
|
2020-05-07 15:09:29 +00:00
|
|
|
this.pipelineMustSucceedDocsPath = data.pipeline_must_succeed_docs_path;
|
2019-08-09 21:01:55 +00:00
|
|
|
this.mergeRequestBasicPath = data.merge_request_basic_path;
|
|
|
|
this.mergeRequestWidgetPath = data.merge_request_widget_path;
|
|
|
|
this.mergeRequestCachedWidgetPath = data.merge_request_cached_widget_path;
|
|
|
|
this.emailPatchesPath = data.email_patches_path;
|
|
|
|
this.plainDiffPath = data.plain_diff_path;
|
|
|
|
this.mergeCheckPath = data.merge_check_path;
|
|
|
|
this.mergeActionsContentPath = data.commit_change_content_path;
|
|
|
|
this.targetProjectFullPath = data.target_project_full_path;
|
|
|
|
this.sourceProjectFullPath = data.source_project_full_path;
|
|
|
|
this.mergeRequestPipelinesHelpPath = data.merge_request_pipelines_docs_path;
|
|
|
|
this.conflictsDocsPath = data.conflicts_docs_path;
|
2020-11-20 18:09:37 +00:00
|
|
|
this.reviewingDocsPath = data.reviewing_and_managing_merge_requests_docs_path;
|
2019-08-09 21:01:55 +00:00
|
|
|
this.ciEnvironmentsStatusPath = data.ci_environments_status_path;
|
2019-10-14 21:06:30 +00:00
|
|
|
this.securityApprovalsHelpPagePath = data.security_approvals_help_page_path;
|
2021-03-15 18:09:05 +00:00
|
|
|
this.licenseComplianceDocsPath = data.license_compliance_docs_path;
|
2019-12-06 12:06:21 +00:00
|
|
|
this.eligibleApproversDocsPath = data.eligible_approvers_docs_path;
|
2019-12-06 21:07:54 +00:00
|
|
|
this.mergeImmediatelyDocsPath = data.merge_immediately_docs_path;
|
2020-07-17 06:09:11 +00:00
|
|
|
this.approvalsHelpPath = data.approvals_help_path;
|
2020-02-17 15:09:01 +00:00
|
|
|
this.mergeRequestAddCiConfigPath = data.merge_request_add_ci_config_path;
|
2020-02-24 21:09:08 +00:00
|
|
|
this.pipelinesEmptySvgPath = data.pipelines_empty_svg_path;
|
2020-02-17 15:09:01 +00:00
|
|
|
this.humanAccess = data.human_access;
|
2020-03-04 06:08:23 +00:00
|
|
|
this.newPipelinePath = data.new_project_pipeline_path;
|
2020-11-20 18:09:37 +00:00
|
|
|
this.sourceProjectDefaultUrl = data.source_project_default_url;
|
2020-08-04 09:09:45 +00:00
|
|
|
this.userCalloutsPath = data.user_callouts_path;
|
|
|
|
this.suggestPipelineFeatureId = data.suggest_pipeline_feature_id;
|
|
|
|
this.isDismissedSuggestPipeline = data.is_dismissed_suggest_pipeline;
|
2020-10-12 21:08:56 +00:00
|
|
|
this.securityReportsDocsPath = data.security_reports_docs_path;
|
2022-10-11 12:09:17 +00:00
|
|
|
this.securityConfigurationPath = data.security_configuration_path;
|
2020-07-17 03:09:14 +00:00
|
|
|
|
2021-01-29 18:09:17 +00:00
|
|
|
// code quality
|
2020-07-17 03:09:14 +00:00
|
|
|
const blobPath = data.blob_path || {};
|
|
|
|
this.headBlobPath = blobPath.head_path || '';
|
|
|
|
this.baseBlobPath = blobPath.base_path || '';
|
2021-01-29 18:09:17 +00:00
|
|
|
this.codequalityReportsPath = data.codequality_reports_path;
|
2020-11-23 18:09:14 +00:00
|
|
|
|
|
|
|
// Security reports
|
|
|
|
this.sastComparisonPath = data.sast_comparison_path;
|
2021-10-13 15:12:51 +00:00
|
|
|
this.secretDetectionComparisonPath = data.secret_detection_comparison_path;
|
2019-08-09 21:01:55 +00:00
|
|
|
}
|
|
|
|
|
2017-12-19 17:50:38 +00:00
|
|
|
get isNothingToMergeState() {
|
|
|
|
return this.state === stateKey.nothingToMerge;
|
|
|
|
}
|
|
|
|
|
2018-03-12 12:08:47 +00:00
|
|
|
get isMergedState() {
|
|
|
|
return this.state === stateKey.merged;
|
|
|
|
}
|
|
|
|
|
2017-12-07 17:41:30 +00:00
|
|
|
static buildMetrics(metrics) {
|
2018-01-02 21:27:00 +00:00
|
|
|
if (!metrics) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2017-09-29 09:31:10 +00:00
|
|
|
return {
|
2017-12-07 17:41:30 +00:00
|
|
|
mergedBy: MergeRequestStore.formatUserObject(metrics.merged_by),
|
|
|
|
closedBy: MergeRequestStore.formatUserObject(metrics.closed_by),
|
|
|
|
mergedAt: formatDate(metrics.merged_at),
|
|
|
|
closedAt: formatDate(metrics.closed_at),
|
|
|
|
readableMergedAt: MergeRequestStore.getReadableDate(metrics.merged_at),
|
|
|
|
readableClosedAt: MergeRequestStore.getReadableDate(metrics.closed_at),
|
2017-09-29 09:31:10 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-12-07 17:41:30 +00:00
|
|
|
static formatUserObject(user) {
|
|
|
|
if (!user) {
|
2017-05-09 04:15:34 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2017-12-07 17:41:30 +00:00
|
|
|
name: user.name || '',
|
|
|
|
username: user.username || '',
|
|
|
|
webUrl: user.web_url || '',
|
|
|
|
avatarUrl: user.avatar_url || '',
|
2017-05-09 04:15:34 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-12-07 17:41:30 +00:00
|
|
|
static getReadableDate(date) {
|
|
|
|
if (!date) {
|
2017-09-29 11:49:14 +00:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2019-11-27 15:06:45 +00:00
|
|
|
return format(date);
|
2017-05-09 04:15:34 +00:00
|
|
|
}
|
2019-06-11 14:19:22 +00:00
|
|
|
|
|
|
|
static getPreferredAutoMergeStrategy(availableAutoMergeStrategies) {
|
2020-03-11 09:09:48 +00:00
|
|
|
if (availableAutoMergeStrategies === undefined) return undefined;
|
|
|
|
|
|
|
|
if (availableAutoMergeStrategies.includes(MTWPS_MERGE_STRATEGY)) {
|
2019-08-22 17:53:14 +00:00
|
|
|
return MTWPS_MERGE_STRATEGY;
|
2020-03-11 09:09:48 +00:00
|
|
|
} else if (availableAutoMergeStrategies.includes(MT_MERGE_STRATEGY)) {
|
2019-06-11 14:19:22 +00:00
|
|
|
return MT_MERGE_STRATEGY;
|
2020-03-11 09:09:48 +00:00
|
|
|
} else if (availableAutoMergeStrategies.includes(MWPS_MERGE_STRATEGY)) {
|
2019-06-11 14:19:22 +00:00
|
|
|
return MWPS_MERGE_STRATEGY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
}
|
2020-07-17 06:09:11 +00:00
|
|
|
|
|
|
|
initApprovals() {
|
|
|
|
this.isApproved = this.isApproved || false;
|
|
|
|
this.approvals = this.approvals || null;
|
|
|
|
}
|
|
|
|
|
|
|
|
setApprovals(data) {
|
|
|
|
this.approvals = data;
|
|
|
|
this.isApproved = data.approved || false;
|
2022-01-11 06:10:58 +00:00
|
|
|
|
|
|
|
this.setState();
|
2020-07-17 06:09:11 +00:00
|
|
|
}
|
2021-09-15 18:11:29 +00:00
|
|
|
|
2022-01-11 06:10:58 +00:00
|
|
|
// eslint-disable-next-line class-methods-use-this
|
2021-09-15 18:11:29 +00:00
|
|
|
get hasMergeChecksFailed() {
|
2022-01-11 06:10:58 +00:00
|
|
|
return false;
|
2021-09-15 18:11:29 +00:00
|
|
|
}
|
2021-09-27 15:10:13 +00:00
|
|
|
|
|
|
|
// Because the state machine doesn't yet handle every state and transition,
|
|
|
|
// some use-cases will need to force a state that can't be reached by
|
|
|
|
// a known transition. This is undesirable long-term (as it subverts
|
|
|
|
// the intent of a state machine), but is necessary until the machine
|
|
|
|
// can handle all possible combinations. (unsafeForce)
|
|
|
|
transitionStateMachine({ transition, state, unsafeForce = false } = {}) {
|
|
|
|
if (unsafeForce && state) {
|
|
|
|
this.stateMachine.value = state;
|
|
|
|
} else {
|
|
|
|
this.stateMachine.send(transition);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.machineValue = this.stateMachine.value;
|
|
|
|
}
|
|
|
|
translateStateToMachine() {
|
|
|
|
const transition = stateToTransitionMap[this.state];
|
|
|
|
let transitionOptions = {
|
|
|
|
state: IDLE,
|
|
|
|
unsafeForce: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (transition) {
|
|
|
|
transitionOptions = { transition };
|
|
|
|
}
|
|
|
|
|
|
|
|
this.transitionStateMachine(transitionOptions);
|
|
|
|
}
|
2022-09-01 15:12:07 +00:00
|
|
|
|
|
|
|
toggleMergeDetails(val = !this.mergeDetailsCollapsed) {
|
|
|
|
this.mergeDetailsCollapsed = val;
|
|
|
|
}
|
2017-05-09 04:15:34 +00:00
|
|
|
}
|