Skip to content

Commit 2f8664e

Browse files
committed
Add git history csv reports
1 parent 73e8869 commit 2f8664e

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

scripts/reports/GitHistoryCsv.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
3+
# Executes "GitLog" Cypher queries to get the "git-history-csv" CSV reports.
4+
# It contains lists of files with only one author, last changed or created files, pairwise changed files,...
5+
6+
# Requires executeQueryFunctions.sh, cleanupAfterReportGeneration.sh
7+
8+
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
9+
set -o errexit -o pipefail
10+
11+
# Overrideable Constants (defaults also defined in sub scripts)
12+
REPORTS_DIRECTORY=${REPORTS_DIRECTORY:-"reports"}
13+
14+
## Get this "scripts/reports" directory if not already set
15+
# Even if $BASH_SOURCE is made for Bourne-like shells it is also supported by others and therefore here the preferred solution.
16+
# CDPATH reduces the scope of the cd command to potentially prevent unintended directory changes.
17+
# This way non-standard tools like readlink aren't needed.
18+
REPORTS_SCRIPT_DIR=${REPORTS_SCRIPT_DIR:-$( CDPATH=. cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P )}
19+
echo "GitHistoryCsv: REPORTS_SCRIPT_DIR=${REPORTS_SCRIPT_DIR}"
20+
21+
# Get the "scripts" directory by taking the path of this script and going one directory up.
22+
SCRIPTS_DIR=${SCRIPTS_DIR:-"${REPORTS_SCRIPT_DIR}/.."} # Repository directory containing the shell scripts
23+
echo "GitHistoryCsv: SCRIPTS_DIR=${SCRIPTS_DIR}"
24+
25+
# Get the "cypher" directory by taking the path of this script and going two directory up and then to "cypher".
26+
CYPHER_DIR=${CYPHER_DIR:-"${REPORTS_SCRIPT_DIR}/../../cypher"}
27+
echo "GitHistoryCsv: CYPHER_DIR=${CYPHER_DIR}"
28+
29+
# Define functions to execute cypher queries from within a given file
30+
source "${SCRIPTS_DIR}/executeQueryFunctions.sh"
31+
32+
# Create report directory
33+
REPORT_NAME="git-history-csv"
34+
FULL_REPORT_DIRECTORY="${REPORTS_DIRECTORY}/${REPORT_NAME}"
35+
mkdir -p "${FULL_REPORT_DIRECTORY}"
36+
37+
# Local Constants
38+
GIT_LOG_CYPHER_DIR="${CYPHER_DIR}/GitLog"
39+
40+
echo "GitHistoryCsv: $(date +'%Y-%m-%dT%H:%M:%S%z') Processing git history..."
41+
42+
# Detailed git file statistics
43+
execute_cypher "${GIT_LOG_CYPHER_DIR}/List_git_files_with_commit_statistics_by_author.cypher" > "${FULL_REPORT_DIRECTORY}/List_git_files_with_commit_statistics_by_author.csv"
44+
execute_cypher "${GIT_LOG_CYPHER_DIR}/List_git_files_that_were_changed_together_with_another_file.cypher" > "${FULL_REPORT_DIRECTORY}/List_git_files_that_were_changed_together_with_another_file.csv"
45+
46+
# Overall distribution of how many files were changed with one git commit, how many were changed with two, etc.
47+
execute_cypher "${GIT_LOG_CYPHER_DIR}/List_git_files_per_commit_distribution.cypher" > "${FULL_REPORT_DIRECTORY}/List_git_files_per_commit_distribution.csv"
48+
49+
# Data basis for finding out if there is a correlation between pairwise changed files and their dependencies
50+
execute_cypher "${GIT_LOG_CYPHER_DIR}/List_pairwise_changed_files_with_dependencies.cypher" > "${FULL_REPORT_DIRECTORY}/List_pairwise_changed_files_with_dependencies.csv"
51+
52+
# Clean-up after report generation. Empty reports will be deleted.
53+
source "${SCRIPTS_DIR}/cleanupAfterReportGeneration.sh" "${FULL_REPORT_DIRECTORY}"
54+
55+
echo "GitHistoryCsv: $(date +'%Y-%m-%dT%H:%M:%S%z') Successfully finished."

0 commit comments

Comments
 (0)