Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/diffs/components/diff_expansion_cell.vue24
-rw-r--r--app/assets/javascripts/diffs/store/mutations.js1
-rw-r--r--app/assets/javascripts/diffs/store/utils.js64
-rw-r--r--app/assets/javascripts/locale/sprintf.js4
-rw-r--r--app/models/ci/build.rb6
-rw-r--r--app/models/ci/pipeline.rb4
-rw-r--r--app/models/concerns/with_uploads.rb1
-rw-r--r--app/models/merge_request.rb11
8 files changed, 91 insertions, 24 deletions
diff --git a/app/assets/javascripts/diffs/components/diff_expansion_cell.vue b/app/assets/javascripts/diffs/components/diff_expansion_cell.vue
index 23fbfc2b74b..4eae2e09c08 100644
--- a/app/assets/javascripts/diffs/components/diff_expansion_cell.vue
+++ b/app/assets/javascripts/diffs/components/diff_expansion_cell.vue
@@ -3,7 +3,7 @@ import { mapState, mapActions } from 'vuex';
import createFlash from '~/flash';
import { s__ } from '~/locale';
import Icon from '~/vue_shared/components/icon.vue';
-import { UNFOLD_COUNT } from '../constants';
+import { UNFOLD_COUNT, INLINE_DIFF_VIEW_TYPE, PARALLEL_DIFF_VIEW_TYPE } from '../constants';
import * as utils from '../store/utils';
import tooltip from '../../vue_shared/directives/tooltip';
@@ -11,6 +11,16 @@ const EXPAND_ALL = 0;
const EXPAND_UP = 1;
const EXPAND_DOWN = 2;
+const lineNumberByViewType = (viewType, diffLine) => {
+ const numberGetters = {
+ [INLINE_DIFF_VIEW_TYPE]: line => line?.new_line,
+ [PARALLEL_DIFF_VIEW_TYPE]: line => (line?.right || line?.left)?.new_line,
+ };
+ const numberGetter = numberGetters[viewType];
+
+ return numberGetter && numberGetter(diffLine);
+};
+
export default {
directives: {
tooltip,
@@ -67,12 +77,16 @@ export default {
...mapActions('diffs', ['loadMoreLines']),
getPrevLineNumber(oldLineNumber, newLineNumber) {
const diffFile = utils.findDiffFile(this.diffFiles, this.fileHash);
- const indexForInline = utils.findIndexInInlineLines(diffFile.highlighted_diff_lines, {
+ const lines = {
+ [INLINE_DIFF_VIEW_TYPE]: diffFile.highlighted_diff_lines,
+ [PARALLEL_DIFF_VIEW_TYPE]: diffFile.parallel_diff_lines,
+ };
+ const index = utils.getPreviousLineIndex(this.diffViewType, diffFile, {
oldLineNumber,
newLineNumber,
});
- const prevLine = diffFile.highlighted_diff_lines[indexForInline - 2];
- return (prevLine && prevLine.new_line) || 0;
+
+ return lineNumberByViewType(this.diffViewType, lines[this.diffViewType][index - 2]) || 0;
},
callLoadMoreLines(
endpoint,
@@ -114,7 +128,7 @@ export default {
this.handleExpandAllLines(expandOptions);
}
},
- handleExpandUpLines(expandOptions = EXPAND_ALL) {
+ handleExpandUpLines(expandOptions) {
const { endpoint, fileHash, view, oldLineNumber, newLineNumber, offset } = expandOptions;
const bottom = this.isBottom;
diff --git a/app/assets/javascripts/diffs/store/mutations.js b/app/assets/javascripts/diffs/store/mutations.js
index c26411af5d7..086a7872a5d 100644
--- a/app/assets/javascripts/diffs/store/mutations.js
+++ b/app/assets/javascripts/diffs/store/mutations.js
@@ -140,6 +140,7 @@ export default {
addContextLines({
inlineLines: diffFile.highlighted_diff_lines,
parallelLines: diffFile.parallel_diff_lines,
+ diffViewType: state.diffViewType,
contextLines: lines,
bottom,
lineNumbers,
diff --git a/app/assets/javascripts/diffs/store/utils.js b/app/assets/javascripts/diffs/store/utils.js
index 80972d2aeb8..29133c814ea 100644
--- a/app/assets/javascripts/diffs/store/utils.js
+++ b/app/assets/javascripts/diffs/store/utils.js
@@ -13,6 +13,8 @@ import {
LINES_TO_BE_RENDERED_DIRECTLY,
MAX_LINES_TO_BE_RENDERED,
TREE_TYPE,
+ INLINE_DIFF_VIEW_TYPE,
+ PARALLEL_DIFF_VIEW_TYPE,
} from '../constants';
export function findDiffFile(files, match, matchKey = 'file_hash') {
@@ -93,8 +95,7 @@ export function getNoteFormData(params) {
export const findIndexInInlineLines = (lines, lineNumbers) => {
const { oldLineNumber, newLineNumber } = lineNumbers;
- return _.findIndex(
- lines,
+ return lines.findIndex(
line => line.old_line === oldLineNumber && line.new_line === newLineNumber,
);
};
@@ -102,8 +103,7 @@ export const findIndexInInlineLines = (lines, lineNumbers) => {
export const findIndexInParallelLines = (lines, lineNumbers) => {
const { oldLineNumber, newLineNumber } = lineNumbers;
- return _.findIndex(
- lines,
+ return lines.findIndex(
line =>
line.left &&
line.right &&
@@ -112,13 +112,32 @@ export const findIndexInParallelLines = (lines, lineNumbers) => {
);
};
+const indexGettersByViewType = {
+ [INLINE_DIFF_VIEW_TYPE]: findIndexInInlineLines,
+ [PARALLEL_DIFF_VIEW_TYPE]: findIndexInParallelLines,
+};
+
+export const getPreviousLineIndex = (diffViewType, file, lineNumbers) => {
+ const findIndex = indexGettersByViewType[diffViewType];
+ const lines = {
+ [INLINE_DIFF_VIEW_TYPE]: file.highlighted_diff_lines,
+ [PARALLEL_DIFF_VIEW_TYPE]: file.parallel_diff_lines,
+ };
+
+ return findIndex && findIndex(lines[diffViewType], lineNumbers);
+};
+
export function removeMatchLine(diffFile, lineNumbers, bottom) {
const indexForInline = findIndexInInlineLines(diffFile.highlighted_diff_lines, lineNumbers);
const indexForParallel = findIndexInParallelLines(diffFile.parallel_diff_lines, lineNumbers);
const factor = bottom ? 1 : -1;
- diffFile.highlighted_diff_lines.splice(indexForInline + factor, 1);
- diffFile.parallel_diff_lines.splice(indexForParallel + factor, 1);
+ if (indexForInline > -1) {
+ diffFile.highlighted_diff_lines.splice(indexForInline + factor, 1);
+ }
+ if (indexForParallel > -1) {
+ diffFile.parallel_diff_lines.splice(indexForParallel + factor, 1);
+ }
}
export function addLineReferences(lines, lineNumbers, bottom, isExpandDown, nextLineNumbers) {
@@ -160,8 +179,8 @@ export function addLineReferences(lines, lineNumbers, bottom, isExpandDown, next
return linesWithNumbers;
}
-export function addContextLines(options) {
- const { inlineLines, parallelLines, contextLines, lineNumbers, isExpandDown } = options;
+function addParallelContextLines(options) {
+ const { parallelLines, contextLines, lineNumbers, isExpandDown } = options;
const normalizedParallelLines = contextLines.map(line => ({
left: line,
right: line,
@@ -170,17 +189,40 @@ export function addContextLines(options) {
const factor = isExpandDown ? 1 : 0;
if (!isExpandDown && options.bottom) {
- inlineLines.push(...contextLines);
parallelLines.push(...normalizedParallelLines);
} else {
- const inlineIndex = findIndexInInlineLines(inlineLines, lineNumbers);
const parallelIndex = findIndexInParallelLines(parallelLines, lineNumbers);
- inlineLines.splice(inlineIndex + factor, 0, ...contextLines);
parallelLines.splice(parallelIndex + factor, 0, ...normalizedParallelLines);
}
}
+function addInlineContextLines(options) {
+ const { inlineLines, contextLines, lineNumbers, isExpandDown } = options;
+ const factor = isExpandDown ? 1 : 0;
+
+ if (!isExpandDown && options.bottom) {
+ inlineLines.push(...contextLines);
+ } else {
+ const inlineIndex = findIndexInInlineLines(inlineLines, lineNumbers);
+
+ inlineLines.splice(inlineIndex + factor, 0, ...contextLines);
+ }
+}
+
+export function addContextLines(options) {
+ const { diffViewType } = options;
+ const contextLineHandlers = {
+ [INLINE_DIFF_VIEW_TYPE]: addInlineContextLines,
+ [PARALLEL_DIFF_VIEW_TYPE]: addParallelContextLines,
+ };
+ const contextLineHandler = contextLineHandlers[diffViewType];
+
+ if (contextLineHandler) {
+ contextLineHandler(options);
+ }
+}
+
/**
* Trims the first char of the `richText` property when it's either a space or a diff symbol.
* @param {Object} line
diff --git a/app/assets/javascripts/locale/sprintf.js b/app/assets/javascripts/locale/sprintf.js
index a3557fbf3fb..7ab4e725d99 100644
--- a/app/assets/javascripts/locale/sprintf.js
+++ b/app/assets/javascripts/locale/sprintf.js
@@ -1,4 +1,4 @@
-import _ from 'underscore';
+import { escape } from 'lodash';
/**
Very limited implementation of sprintf supporting only named parameters.
@@ -17,7 +17,7 @@ export default (input, parameters, escapeParameters = true) => {
if (parameters) {
Object.keys(parameters).forEach(parameterName => {
const parameterValue = parameters[parameterName];
- const escapedParameterValue = escapeParameters ? _.escape(parameterValue) : parameterValue;
+ const escapedParameterValue = escapeParameters ? escape(parameterValue) : parameterValue;
output = output.replace(new RegExp(`%{${parameterName}}`, 'g'), escapedParameterValue);
});
}
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index e95e2c538c5..d61f0bbfb10 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -173,8 +173,10 @@ module Ci
scope :queued_before, ->(time) { where(arel_table[:queued_at].lt(time)) }
scope :order_id_desc, -> { order('ci_builds.id DESC') }
- PROJECT_ROUTE_AND_NAMESPACE_ROUTE = { project: [:project_feature, :route, { namespace: :route }] }.freeze
- scope :preload_project_and_pipeline_project, -> { preload(PROJECT_ROUTE_AND_NAMESPACE_ROUTE, pipeline: PROJECT_ROUTE_AND_NAMESPACE_ROUTE) }
+ scope :preload_project_and_pipeline_project, -> do
+ preload(Ci::Pipeline::PROJECT_ROUTE_AND_NAMESPACE_ROUTE,
+ pipeline: Ci::Pipeline::PROJECT_ROUTE_AND_NAMESPACE_ROUTE)
+ end
acts_as_taggable
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 3209e077a08..4ae64b6c8f1 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -16,6 +16,10 @@ module Ci
include FromUnion
include UpdatedAtFilterable
+ PROJECT_ROUTE_AND_NAMESPACE_ROUTE = {
+ project: [:project_feature, :route, { namespace: :route }]
+ }.freeze
+
BridgeStatusError = Class.new(StandardError)
sha_attribute :source_sha
diff --git a/app/models/concerns/with_uploads.rb b/app/models/concerns/with_uploads.rb
index 6c6febd186c..d90f32d8b1c 100644
--- a/app/models/concerns/with_uploads.rb
+++ b/app/models/concerns/with_uploads.rb
@@ -18,7 +18,6 @@
module WithUploads
extend ActiveSupport::Concern
include FastDestroyAll::Helpers
- include FeatureGate
# Currently there is no simple way how to select only not-mounted
# uploads, it should be all FileUploaders so we select them by
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 5dda1bd8cc7..0bc4e550678 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -235,12 +235,17 @@ class MergeRequest < ApplicationRecord
end
scope :join_project, -> { joins(:target_project) }
scope :references_project, -> { references(:target_project) }
+
+ PROJECT_ROUTE_AND_NAMESPACE_ROUTE = [
+ target_project: [:route, { namespace: :route }],
+ source_project: [:route, { namespace: :route }]
+ ].freeze
+
scope :with_api_entity_associations, -> {
preload(:assignees, :author, :unresolved_notes, :labels, :milestone,
:timelogs, :latest_merge_request_diff,
- metrics: [:latest_closed_by, :merged_by],
- target_project: [:route, { namespace: :route }],
- source_project: [:route, { namespace: :route }])
+ *PROJECT_ROUTE_AND_NAMESPACE_ROUTE,
+ metrics: [:latest_closed_by, :merged_by])
}
scope :by_target_branch_wildcard, ->(wildcard_branch_name) do
where("target_branch LIKE ?", ApplicationRecord.sanitize_sql_like(wildcard_branch_name).tr('*', '%'))