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

file_helpers.js « ide « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 326f8b9716dd1303182d38863c9097488c0210c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
export const createFile = (path, content = '') => ({
  id: path,
  path,
  content,
  raw: content,
});

export const createNewFile = (path, content) =>
  Object.assign(createFile(path, content), {
    tempFile: true,
    raw: '',
  });

export const createDeletedFile = (path, content) =>
  Object.assign(createFile(path, content), {
    deleted: true,
  });

export const createUpdatedFile = (path, oldContent, content) =>
  Object.assign(createFile(path, content), {
    raw: oldContent,
  });

export const createMovedFile = (path, prevPath, content) =>
  Object.assign(createNewFile(path, content), {
    prevPath,
  });

export const createEntries = path =>
  path.split('/').reduce((acc, part, idx, parts) => {
    const parentPath = parts.slice(0, idx).join('/');
    const fullPath = parentPath ? `${parentPath}/${part}` : part;

    return Object.assign(acc, { [fullPath]: { ...createFile(fullPath), parentPath } });
  }, {});