1
+ // List git file directories and the number of files they contain
2
+
3
+ MATCH (git_file :File &Git &! Repository )
4
+ WITH percentileDisc (git_file .createdAtEpoch , 0.5 ) AS medianCreatedAtEpoch
5
+ ,percentileDisc (git_file .lastModificationAtEpoch , 0.5 ) AS medianLastModificationAtEpoch
6
+ //,min(git_file.createdAtEpoch) AS oldestCreatedAtEpoch
7
+ //,min(git_file.lastModificationAtEpoch) AS oldestLastModificationAtEpoch
8
+ ,collect (git_file ) AS git_files
9
+ UNWIND git_files AS git_file
10
+ WITH *
11
+ ,datetime .fromepochMillis (coalesce (git_file .createdAtEpoch , medianCreatedAtEpoch )) AS createdAtTimestamp
12
+ ,datetime .fromepochMillis (coalesce (git_file .lastModificationAtEpoch , medianLastModificationAtEpoch )) AS lastModificationAtTimestamp
13
+ WHERE git_file .deletedAt IS NULL
14
+ WITH *
15
+ ,git_file .relativePath AS gitFileName
16
+ ,reverse (split (reverse (git_file .relativePath ),'/' )[0 ]) AS gitFileNameWithoutPath
17
+ WITH *
18
+ ,rtrim (split (gitFileName , gitFileNameWithoutPath )[0 ], '/' ) AS gitDirectoryPath
19
+ WITH *
20
+ ,coalesce (nullif (split (gitDirectoryPath , '/' )[- 2 ],'' ), 'root' ) AS directoryParentName
21
+ ,coalesce (nullif (split (gitDirectoryPath , '/' )[- 1 ],'' ), 'root' ) AS directoryName
22
+ ,size (split (gitDirectoryPath , '/' )) AS directoryPathLength
23
+ OPTIONAL MATCH (git_repository :Git &Repository )- [ : HAS_FILE ] -> (git_file )
24
+ OPTIONAL MATCH (git_commit :Git &Commit )- [ : CONTAINS_CHANGE ] -> (git_change :Git &Change )- [ ] -> (git_file )
25
+ WITH * , COUNT { (git_commit )- [: HAS_PARENT ]- (: Commit ) } AS parentCommitCount
26
+ // WHERE parentCommitCount < 2
27
+ ORDER BY git_commit .date DESC
28
+ WITH git_repository .name AS gitRepositoryName
29
+ ,gitDirectoryPath
30
+ ,directoryParentName
31
+ ,directoryName
32
+ ,directoryPathLength
33
+ ,count (DISTINCT gitFileName ) AS fileCount
34
+ ,count (DISTINCT git_commit .sha ) AS commitCount
35
+ ,count (DISTINCT git_commit .author ) AS authorCount
36
+ ,date (max (git_commit .date )) AS latestCommitDate
37
+ ,max (date (createdAtTimestamp ) ) AS latestCreationDate
38
+ ,max (date (lastModificationAtTimestamp )) AS latestModificationDate
39
+ ,duration .inDays (date (max (git_commit .date )), date ()).days AS daysSinceLatestCommit
40
+ ,duration .inDays (max (createdAtTimestamp ), datetime ()).days AS daysSinceLatestCreation
41
+ ,duration .inDays (max (lastModificationAtTimestamp ), datetime ()).days AS daysSinceLatestModification
42
+ // Debugging
43
+ // ,collect(DISTINCT git_commit.sha)[0..9] AS gitCommitExamples
44
+ // ,collect(DISTINCT git_commit.author)[0..9] AS gitCommitAuthorExamples
45
+ // ,collect(git_file)[0..4] AS gitFileExamples
46
+ // ,collect(gitFileName) AS gitFileNameExamples
47
+ // ,collect(gitFileNameWithoutPath) AS gitFileNameWithoutPathExamples
48
+ WHERE fileCount > 1 // Filter out single files and directories with only one file
49
+ RETURN gitRepositoryName
50
+ ,gitDirectoryPath
51
+ ,directoryParentName
52
+ ,directoryName
53
+ ,directoryPathLength
54
+ ,fileCount
55
+ ,commitCount
56
+ ,authorCount
57
+ ,latestCommitDate
58
+ ,latestCreationDate
59
+ ,latestModificationDate
60
+ ,daysSinceLatestCommit
61
+ ,daysSinceLatestCreation
62
+ ,daysSinceLatestModification
63
+ // Debugging
64
+ // ,gitFileExamples
65
+ // ,gitFileNameExamples
66
+ // ,gitFileNameWithoutPathExamples
0 commit comments