1+ // List git file directories and their statistics
2+
3+ MATCH (git_repository :Git &Repository )- [ : HAS_FILE ] -> (git_file :Git &File &! Repository )
4+ WHERE git_file .deletedAt IS NULL // filter out deleted files
5+ ORDER BY git_file .relativePath
6+ WITH *
7+ ,datetime .fromepochMillis (git_file .createdAtEpoch ) AS fileCreatedAtTimestamp
8+ ,datetime .fromepochMillis (coalesce (git_file .lastModificationAtEpoch , git_file .createdAtEpoch )) AS fileLastModificationAtTimestamp
9+ WITH * , git_repository .name + '/' + git_file .relativePath AS filePath
10+ WITH * , split (filePath , '/' ) AS pathElements
11+ WITH * , pathElements [- 1 ] AS fileName
12+ MATCH (git_commit :Git &Commit )- [ : CONTAINS_CHANGE ] -> (git_change :Git &Change )--> (old_files_included :Git &File &! Repository )- [ : HAS_NEW_NAME *0..3 ] -> (git_file )
13+ WITH pathElements
14+ ,fileCreatedAtTimestamp
15+ ,fileLastModificationAtTimestamp
16+ ,fileName
17+ ,filePath AS fileRelativePath
18+ ,split (git_commit .author , ' <' )[0 ] AS author
19+ ,max (git_commit .sha ) AS maxCommitSha
20+ ,collect (DISTINCT git_commit .sha ) AS commitHashes
21+ ,date (max (git_commit .date )) AS lastCommitDate
22+ UNWIND pathElements AS pathElement
23+ WITH *
24+ ,coalesce (nullif (split (fileRelativePath , '/' + pathElement )[0 ], fileRelativePath ), '' ) AS parent
25+ WITH *
26+ ,coalesce (nullif (parent ,'' ) + '/' , '' ) + pathElement AS directory
27+ WHERE pathElement <> fileName
28+ WITH directory AS directoryPath
29+ ,split (directory , '/' )[- 1 ] AS directoryName
30+ ,parent AS directoryParentPath
31+ ,split (parent , '/' )[- 1 ] AS directoryParentName
32+ ,size (split (directory , '/' )) AS directoryPathLength
33+ ,author
34+ ,collect (DISTINCT fileRelativePath ) AS files
35+ ,max (date (fileCreatedAtTimestamp ) ) AS lastCreationDate
36+ ,max (date (fileLastModificationAtTimestamp )) AS lastModificationDate
37+ ,apoc .coll .toSet (apoc .coll .flatten (collect (commitHashes ))) AS commitHashes
38+ ,max (maxCommitSha ) AS maxCommitSha
39+ ,max (lastCommitDate ) AS lastCommitDate
40+ ,max (fileRelativePath ) AS maxFileRelativePath
41+ ,duration .inDays (max (lastCommitDate ), date ()).days AS daysSinceLastCommit
42+ ,duration .inDays (max (fileCreatedAtTimestamp ), datetime ()).days AS daysSinceLastCreation
43+ ,duration .inDays (max (fileLastModificationAtTimestamp ), datetime ()).days AS daysSinceLastModification
44+ // Assure that the authors are ordered by their commit count descending per directory
45+ ORDER BY directoryPath ASCENDING , size (commitHashes ) DESCENDING
46+ WITH directoryPath
47+ ,directoryName
48+ ,directoryParentPath
49+ ,directoryParentName
50+ ,directoryPathLength
51+ ,collect (author )[0 ] AS mainAuthor
52+ ,collect (author )[1 ] AS secondAuthor
53+ ,collect (author )[2 ] AS thirdAuthor
54+ ,count (DISTINCT author ) AS authorCount
55+ ,size (apoc .coll .toSet (apoc .coll .flatten (collect (files )))) AS fileCount
56+ ,size (apoc .coll .toSet (apoc .coll .flatten (collect (commitHashes )))) AS commitCount
57+ ,max (lastCreationDate ) AS lastCreationDate
58+ ,max (lastModificationDate ) AS lastModificationDate
59+ ,max (maxCommitSha ) AS maxCommitSha
60+ ,max (lastCommitDate ) AS lastCommitDate
61+ ,min (daysSinceLastCommit ) AS daysSinceLastCommit
62+ ,min (daysSinceLastCreation ) AS daysSinceLastCreation
63+ ,min (daysSinceLastModification ) AS daysSinceLastModification
64+ ,max (maxFileRelativePath ) AS maxFileRelativePath
65+ // The final results are grouped by the statistic values like file count,...
66+ RETURN collect (directoryPath )[- 1 ] AS directoryPath
67+ ,apoc .text .join (collect (directoryName ), '/' ) AS directoryName
68+ ,collect (directoryParentPath )[0 ] AS directoryParentPath
69+ ,collect (directoryParentName )[0 ] AS directoryParentName
70+ ,mainAuthor
71+ ,secondAuthor
72+ ,thirdAuthor
73+ ,authorCount
74+ ,fileCount
75+ ,commitCount
76+ ,lastCreationDate
77+ ,lastModificationDate
78+ ,lastCommitDate
79+ ,daysSinceLastCommit
80+ ,daysSinceLastCreation
81+ ,daysSinceLastModification
82+ ,maxCommitSha
83+ ,maxFileRelativePath
84+ ,max (directoryPathLength ) AS directoryPathLength
85+ ,count (DISTINCT directoryPath ) AS combinedDirectoriesCount
0 commit comments