|
| 1 | +// List git file directories and their statistics |
| 2 | + |
| 3 | + MATCH (git_file:File&Git&!Repository) |
| 4 | + WHERE git_file.deletedAt IS NULL // filter out deleted files |
| 5 | + ORDER BY git_file.relativePath |
| 6 | + WITH percentileDisc(git_file.createdAtEpoch, 0.5) AS medianCreatedAtEpoch |
| 7 | + ,percentileDisc(git_file.lastModificationAtEpoch, 0.5) AS medianLastModificationAtEpoch |
| 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 fileCreatedAtTimestamp |
| 12 | + ,datetime.fromepochMillis(coalesce(git_file.lastModificationAtEpoch, medianLastModificationAtEpoch)) AS fileLastModificationAtTimestamp |
| 13 | + WITH *, split(git_file.relativePath, '/') AS pathElements |
| 14 | + WITH *, pathElements[-1] AS fileName |
| 15 | + MATCH (git_repository:Git&Repository)-[:HAS_FILE]->(git_file) |
| 16 | + MATCH (git_commit:Git&Commit)-[:CONTAINS_CHANGE]->(git_change:Git&Change)-[]->(git_file) |
| 17 | + WITH pathElements |
| 18 | + ,fileCreatedAtTimestamp |
| 19 | + ,fileLastModificationAtTimestamp |
| 20 | + ,fileName |
| 21 | + ,git_file.relativePath AS fileRelativePath |
| 22 | + ,max(git_repository.name) AS repository |
| 23 | + ,COUNT(DISTINCT git_commit.sha) AS commitCount |
| 24 | + ,COUNT(DISTINCT git_commit.author) AS authorCount |
| 25 | + ,date(max(git_commit.date)) AS lastCommitDate |
| 26 | +UNWIND pathElements AS pathElement |
| 27 | + WITH * |
| 28 | + ,coalesce(nullif(split(fileRelativePath, '/' + pathElement)[0], fileRelativePath), '') AS parent |
| 29 | + WITH * |
| 30 | + ,coalesce(nullif(parent,'') + '/', '') + pathElement AS directory |
| 31 | + WHERE pathElement <> fileName |
| 32 | +RETURN repository AS gitRepositoryName |
| 33 | + ,directory AS gitDirectoryPath |
| 34 | + ,parent AS directoryParentPath |
| 35 | + ,split(parent, '/')[-1] AS directoryParentPathName |
| 36 | + ,parent AS directoryParentName // TODO was directoryParentPathName |
| 37 | + ,split(directory, '/')[-1] AS directoryPathName |
| 38 | + ,directory AS directoryName // TODO was directoryPathName |
| 39 | + ,size(split(directory, '/')) AS directoryPathLength |
| 40 | + ,count(DISTINCT fileRelativePath) AS fileCount |
| 41 | + ,max(date(fileCreatedAtTimestamp) ) AS latestCreationDate |
| 42 | + ,max(date(fileLastModificationAtTimestamp)) AS latestModificationDate |
| 43 | + ,sum(commitCount) AS commitCount |
| 44 | + ,sum(authorCount) AS authorCount |
| 45 | + ,max(lastCommitDate) AS latestCommitDate |
| 46 | + ,duration.inDays(max(lastCommitDate), date()).days AS daysSinceLatestCommit |
| 47 | + ,duration.inDays(max(fileCreatedAtTimestamp), datetime()).days AS daysSinceLatestCreation |
| 48 | + ,duration.inDays(max(fileLastModificationAtTimestamp), datetime()).days AS daysSinceLatestModification |
| 49 | + // Debugging |
| 50 | + //,collect(DISTINCT fileRelativePath)[0..4] AS relativePathExamples |
| 51 | + //,collect(DISTINCT fileName)[0..4] AS fileNameExamples |
0 commit comments