From 1e5723d7a2760392f99ce52d4ce0709e4c2c3e25 Mon Sep 17 00:00:00 2001 From: Tom Ice Date: Fri, 11 Jun 2021 17:35:56 -0400 Subject: [PATCH] Add stats by author per timezone functionality * Added the ability to see git stats both per timezone, as well as by author per timezone. It should respect all global options. * Adjusted the non-interactive menu as it was missed during the reorganization effort * Updated tests, README.md, man page, and screenshots to reflect the new changes * Resolves #128 --- README.md | 12 ++++-- git-quick-stats | 93 +++++++++++++++++++++++++++++++----------- git-quick-stats.1 | 10 +++++ tests/commands_test.sh | 4 ++ 4 files changed, 91 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index be2b8b6..4e472c6 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ > > Any git repository may contain tons of information about commits, contributors, and files. Extracting this information is not always trivial, mostly because there are a gadzillion options to a gadzillion git commands – I don’t think there is a single person alive who knows them all. Probably not even [Linus Torvalds](https://github.com/torvalds) himself :). -![mainMenuScreenshot](https://user-images.githubusercontent.com/8818630/118892347-c7375c80-b8ce-11eb-84f0-6e04bb65f850.png) +![mainMenuScreenshot](https://user-images.githubusercontent.com/8818630/121750502-8223d600-cada-11eb-94bc-470be4e22ba4.png) ## Table of Contents @@ -53,9 +53,9 @@ ## Screenshots -![commitsByWeekdayScreenshot](https://user-images.githubusercontent.com/8818630/118892353-c8688980-b8ce-11eb-96be-a48e1b7dc73b.png) +![commitsByWeekdayScreenshot](https://user-images.githubusercontent.com/8818630/121750517-8819b700-cada-11eb-99a0-a72942822da5.png) -![commitsByHourScreenshot](https://user-images.githubusercontent.com/8818630/118892355-c9012000-b8ce-11eb-991c-ac0e2a335cd6.png) +![commitsByHourScreenshot](https://user-images.githubusercontent.com/8818630/121750525-8c45d480-cada-11eb-8054-78716ce6623c.png) ## Usage @@ -127,6 +127,10 @@ LIST OPTIONS displays a list of commits per hour -A, --commits-by-author-by-hour displays a list of commits per hour by author + -z, --commits-by-timezone + displays a list of commits per timezone + -Z, --commits-by-author-by-timezone + displays a list of commits per timezone by author SUGGEST OPTIONS -r, --suggest-reviewers @@ -201,7 +205,7 @@ You can change to the legacy color scheme by toggling the variable `_MENU_THEME` export _MENU_THEME=legacy ``` -![legacyThemeScreenshot](https://user-images.githubusercontent.com/8818630/118892356-c9012000-b8ce-11eb-8fd8-1b71e0ca6466.png) +![legacyThemeScreenshot](https://user-images.githubusercontent.com/8818630/121750530-8f40c500-cada-11eb-808c-5f5fb81801d2.png) ## Installation diff --git a/git-quick-stats b/git-quick-stats index 50a5a39..81265ba 100755 --- a/git-quick-stats +++ b/git-quick-stats @@ -160,6 +160,10 @@ LIST OPTIONS displays a list of commits per hour -A, --commits-by-author-by-hour displays a list of commits per hour by author + -z, --commits-by-timezone + displays a list of commits per timezone + -Z, --commits-by-author-by-timezone + displays a list of commits per timezone by author SUGGEST OPTIONS -r, --suggest-reviewers @@ -237,9 +241,11 @@ function showMenu() { printf %b "${NUMS} 13)${TEXT} Git commits per month\\n" printf %b "${NUMS} 14)${TEXT} Git commits per weekday\\n" printf %b "${NUMS} 15)${TEXT} Git commits per hour\\n" - printf %b "${NUMS} 16)${TEXT} Git commits by author per hour\\n" + printf %b "${NUMS} 16)${TEXT} Git commits per hour by author\\n" + printf %b "${NUMS} 17)${TEXT} Git commits per timezone\\n" + printf %b "${NUMS} 18)${TEXT} Git commits per timezone by author\\n" printf %b "\\n${TITLES} Suggest:\\n" - printf %b "${NUMS} 17)${TEXT} Code reviewers (based on git history)\\n" + printf %b "${NUMS} 19)${TEXT} Code reviewers (based on git history)\\n" printf %b "\\n${HELP_TXT}Please enter a menu option or ${EXIT_TXT}press Enter to exit.\\n" printf %b "${TEXT}> ${NORMAL}" read -r opt @@ -730,6 +736,29 @@ function commitsByHour() { }' | sort } +################################################################################ +# DESC: Displays number of commits per timezone +# ARGS: $author (optional): Can focus on a single author. Default is all authors +# OUTS: None +################################################################################ +function commitsByTimezone() { + local author="${1:-}" + local _author="" + + if [[ -z "${author}" ]]; then + optionPicked "Git commits by timezone:" + _author="--author=**" + else + optionPicked "Git commits by timezone for author '${author}':" + _author="--author=${author}" + fi + + echo -e "Commits\tTimeZone" + git -c log.showSignature=false shortlog -n $_merges --format='%ad %s' \ + "${_author}" "$_since" "$_until" --date=iso $_log_options $_pathspec \ + | cut -d " " -f 12 | grep -v -e '^[[:space:]]*$' | sort | uniq -c +} + ################################################################################ # FUNCTIONS FOR SUGGESTION STATS @@ -763,7 +792,7 @@ git rev-parse --is-inside-work-tree > /dev/null # Parse non-interative commands if [[ "$#" -eq 1 ]]; then case "$1" in - -r|--suggest-reviewers) suggestReviewers;; + # GENERATE OPTIONS -T|--detailed-git-stats) detailedGitStats;; -R|--git-stats-by-branch) branch="${_GIT_BRANCH:-}" @@ -771,18 +800,6 @@ if [[ "$#" -eq 1 ]]; then read -r -p "Which branch? " branch done detailedGitStats "${branch}";; - -V|--csv-output-by-branch) - branch="${_GIT_BRANCH:-}" - while [[ -z "${branch}" ]]; do - read -r -p "Which branch? " branch - done - csvOutput "${branch}";; - -b|--branch-tree) branchTree;; - -d|--commits-per-day) commitsPerDay;; - -a|--commits-per-author) commitsPerAuthor;; - -S|--my-daily-stats) myDailyStats;; - -C|--contributors) contributors;; - -D|--branches-by-date) branchesByDate;; -c|--changelogs) changelogs;; -L|--changelogs-by-author) author="${_GIT_AUTHOR:-}" @@ -790,15 +807,13 @@ if [[ "$#" -eq 1 ]]; then read -r -p "Which author? " author done changelogs "${author}";; - -w|--commits-by-weekday) commitsByWeekday;; - -o|--commits-by-hour) commitsByHour;; - -A|--commits-by-author-by-hour) - author="${_GIT_AUTHOR:-}" - while [[ -z "${author}" ]]; do - read -r -p "Which author? " author + -S|--my-daily-stats) myDailyStats;; + -V|--csv-output-by-branch) + branch="${_GIT_BRANCH:-}" + while [[ -z "${branch}" ]]; do + read -r -p "Which branch? " branch done - commitsByHour "${author}";; - -m|--commits-by-month) commitsByMonth;; + csvOutput "${branch}";; -j|--json-output) json_path="" while [[ -z "${json_path}" ]]; do @@ -817,6 +832,30 @@ if [[ "$#" -eq 1 ]]; then fi done jsonOutput "${json_path}";; + # LIST OPTIONS + -b|--branch-tree) branchTree;; + -D|--branches-by-date) branchesByDate;; + -C|--contributors) contributors;; + -a|--commits-per-author) commitsPerAuthor;; + -d|--commits-per-day) commitsPerDay;; + -m|--commits-by-month) commitsByMonth;; + -w|--commits-by-weekday) commitsByWeekday;; + -o|--commits-by-hour) commitsByHour;; + -A|--commits-by-author-by-hour) + author="${_GIT_AUTHOR:-}" + while [[ -z "${author}" ]]; do + read -r -p "Which author? " author + done + commitsByHour "${author}";; + -z|--commits-by-timezone) commitsByTimezone;; + -Z|--commits-by-author-by-timezone) + author="${_GIT_AUTHOR:-}" + while [[ -z "${author}" ]]; do + read -r -p "Which author? " author + done + commitsByTimezone "${author}";; + # SUGGEST OPTIONS + -r|--suggest-reviewers) suggestReviewers;; -h|-\?|--help) usage;; *) echo "Invalid argument"; usage; exit 1;; esac @@ -879,7 +918,13 @@ while [[ "${opt}" != "" ]]; do read -r -p "Which author? " author done commitsByHour "${author}"; showMenu;; - 17) suggestReviewers; showMenu;; + 17) commitsByTimezone; showMenu;; + 18) author="" + while [[ -z "${author}" ]]; do + read -r -p "Which author? " author + done + commitsByTimezone "${author}"; showMenu;; + 19) suggestReviewers; showMenu;; q|"\n") exit;; *) clear; optionPicked "Pick an option from the menu"; showMenu;; esac diff --git a/git-quick-stats.1 b/git-quick-stats.1 index 602a660..33f7740 100644 --- a/git-quick-stats.1 +++ b/git-quick-stats.1 @@ -99,6 +99,16 @@ displays a list of commits per hour .IP displays a list of commits per hour by author .HP +.PP +\fB\-z\fR, \fB\-\-commits\-by\-timezone\fR +.IP +displays a list of commits per timezone +.HP +.PP +\fB\-Z\fR, \fB\-\-commits\-by\-author\-by\-timezone\fR +.IP +displays a list of commits per timezone by author +.HP .SH SUGGEST OPTIONS .PP \fB\-r\fR, \fB\-\-suggest\-reviewers\fR diff --git a/tests/commands_test.sh b/tests/commands_test.sh index 96c9488..17f07eb 100755 --- a/tests/commands_test.sh +++ b/tests/commands_test.sh @@ -54,6 +54,10 @@ LIST OPTIONS displays a list of commits per hour -A, --commits-by-author-by-hour displays a list of commits per hour by author + -z, --commits-by-timezone + displays a list of commits per timezone + -Z, --commits-by-author-by-timezone + displays a list of commits per timezone by author SUGGEST OPTIONS -r, --suggest-reviewers