Commit af7eff8f authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera

Merge branch 'symlink-identifier/unique-id-all-diff-files' into 'master'

Add a UUID to each Diff File when the raw data is processed

See merge request gitlab-org/gitlab!34128
parents 0cf295fa f37f3816
......@@ -16,6 +16,7 @@ import {
INLINE_DIFF_VIEW_TYPE,
PARALLEL_DIFF_VIEW_TYPE,
} from '../constants';
import { uuids } from '../utils/uuids';
export function findDiffFile(files, match, matchKey = 'file_hash') {
return files.find(file => file[matchKey] === match);
......@@ -403,8 +404,26 @@ function deduplicateFilesList(files) {
return Object.values(dedupedFiles);
}
function prepareDiffFile(file) {
Object.assign(file, {
uuid: uuids({
seeds: [
file.blob.id,
file.diff_refs.base_sha,
file.diff_refs.start_sha,
file.diff_refs.head_sha,
file.file_identifier_hash,
Number(file.blob.mode),
],
})[0],
});
return file;
}
export function prepareDiffData(diff, priorFiles = []) {
const cleanedFiles = (diff.diff_files || [])
.map(prepareDiffFile)
.map(ensureBasicDiffFileLines)
.map(prepareDiffFileLines)
.map(finalizeDiffFile);
......
......@@ -13,6 +13,7 @@ export default {
blob_name: 'CHANGELOG',
blob_icon: '<i aria-hidden="true" data-hidden="true" class="fa fa-file-text-o fa-fw"></i>',
file_hash: '1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a',
file_identifier_hash: '928f8286952bda02d674b692addcbe077084663a',
file_path: 'CHANGELOG',
new_file: false,
deleted_file: false,
......
......@@ -243,6 +243,8 @@ describe('DiffsStoreMutations', () => {
const data = {
diff_files: [
{
blob: {},
diff_refs: {},
content_sha: 'abc',
file_hash: fileHash,
extra_field: 1,
......
import { clone } from 'lodash';
import * as utils from '~/diffs/store/utils';
import { uuids } from '~/diffs/utils/uuids';
import {
LINE_POSITION_LEFT,
LINE_POSITION_RIGHT,
......@@ -430,6 +431,7 @@ describe('DiffsStoreUtils', () => {
});
describe('prepareDiffData', () => {
let fileId;
let mock;
let preparedDiff;
let splitInlineDiff;
......@@ -438,6 +440,17 @@ describe('DiffsStoreUtils', () => {
beforeEach(() => {
mock = getDiffFileMock();
[fileId] = uuids({
seeds: [
mock.blob.id,
mock.diff_refs.base_sha,
mock.diff_refs.start_sha,
mock.diff_refs.head_sha,
mock.file_identifier_hash,
Number(mock.blob.mode),
],
});
preparedDiff = { diff_files: [mock] };
splitInlineDiff = {
diff_files: [{ ...mock, parallel_diff_lines: undefined }],
......@@ -455,6 +468,13 @@ describe('DiffsStoreUtils', () => {
completedDiff.diff_files = utils.prepareDiffData(completedDiff, [mock]);
});
it('adds a universally unique identifier to each diff file', () => {
expect(preparedDiff.diff_files[0].uuid).toBe(fileId);
expect(splitInlineDiff.diff_files[0].uuid).toBe(fileId);
expect(splitParallelDiff.diff_files[0].uuid).toBe(fileId);
expect(completedDiff.diff_files[0].uuid).toBe(fileId);
});
it('sets the renderIt and collapsed attribute on files', () => {
const firstParallelDiffLine = preparedDiff.diff_files[0].parallel_diff_lines[2];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment