gitalytics 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e94b6bc74a8f579b8bb625c6e74d52df9db42743
4
- data.tar.gz: c4c3afbc6db0329ce03fa4d59f299da22b083315
2
+ SHA256:
3
+ metadata.gz: 6a2ce13752b65209b61bd74565d85eb843325830c83ef2086a53b1d6d8ecc6e5
4
+ data.tar.gz: b95067b6d2b4e2d7bfb8e94893b7d16a4d209e42bcc560cb1c1fc9670834200b
5
5
  SHA512:
6
- metadata.gz: 1815e7bb9f1422da99109c5e68208cfe6fd50c4084951b13d8d50283633029347c37d529142e44f1a4e620f7d2646cabee6b57c406ffdb24f16183b3ee5a9af8
7
- data.tar.gz: 3c00ad0ff6a0d33fcbdc91f7119466fb3c77183b32cdf9523f1ca7bfc582e296064aedb32debaf21815ba2b89011c675ab3c5f992954a1a09c7dfa6028d1452a
6
+ metadata.gz: f8f39095a76621249537a34a68d4f518816ada5da5dba2ddf97eaa549304fb2433773fcb1feafec249d4a00874cc30d6690baa3c7303e2cec68ecc15f7b2f51f
7
+ data.tar.gz: 79031b60b459d54c81d57eb8735bb8972368d95c16a123d66f8c98bad66b8cb5c84a09da92f187d18ab88e9a8082137b7686e93b76cbecc1b44b1534f39263db
data/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  ## Gitalytics Changelog
2
2
 
3
+ #### v.1.4.0
4
+ * Brand new HTML report: a single self-contained page (no CDN assets) with inline SVG charts, light and dark themes, and a mobile-friendly layout.
5
+ * New report sections: activity timeline, sortable author leaderboard with trends, weekday/hour punch card, most changed files, top directories and highlights.
6
+ * New `--since` / `--until` options to analyze a date range.
7
+ * New `--json` option that prints a machine-readable summary.
8
+ * New `--output FILE` option to choose where the HTML report is written.
9
+ * Commits now keep their full timestamp (`Commit#time`).
10
+ * New `--no-merges` option to leave merge commits out.
11
+ * Author names and emails respect `.mailmap`; `--group-email` ignores case.
12
+ * Binary files are now counted as touched files (they used to be skipped), and renamed files keep their whole history under their current path.
13
+ * File names with spaces, quotes or non-ASCII characters and commit messages with invalid UTF-8 no longer break parsing.
14
+ * Faster on large repositories: the log is streamed and parsed record by record, and authors are looked up in a hash.
15
+ * `gitalytics` now exits with an error message when run outside a git repository instead of printing "No commits found.".
16
+ * `Commit#hash` is now `Commit#sha` (the old name overrode `Object#hash`, so commits could not be used as hash keys or in `uniq`).
17
+ * Dropped the `haml`, `color-generator` and `matrix` dependencies; gitalytics now has no runtime dependencies.
18
+ * Requires Ruby 3.1 or newer.
19
+ * Runs on modern Ruby again (fixes for Bundler, Minitest and stdlib changes).
20
+ * CI moved to GitHub Actions (Ruby 3.1 to 3.4) with RuboCop.
21
+
3
22
  #### v.1.3.1
4
23
  * Add Benchmark option.
5
24
  * Fix lots of Rubocop's warnings.
data/Gemfile CHANGED
@@ -1,10 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
4
6
 
5
- gem 'coveralls', require: false
6
-
7
- group :test do
8
- gem 'rake'
7
+ group :development, :test do
9
8
  gem 'minitest'
9
+ gem 'rake'
10
+ gem 'rubocop', require: false
11
+ gem 'rubocop-minitest', require: false
12
+ gem 'rubocop-rake', require: false
10
13
  end
data/README.md CHANGED
@@ -1,55 +1,96 @@
1
- ## Gitalytics
1
+ # Gitalytics
2
2
 
3
- Get commits statistics for your git repository
4
- Based on gist by Tobin Harris: https://gist.github.com/tobinharris/396634
3
+ [![Gem Version](https://img.shields.io/gem/v/gitalytics.svg)](https://rubygems.org/gems/gitalytics)
4
+ [![CI](https://github.com/pepito2k/gitalytics/actions/workflows/ci.yml/badge.svg)](https://github.com/pepito2k/gitalytics/actions/workflows/ci.yml)
5
+ [![Downloads](https://img.shields.io/gem/dt/gitalytics.svg)](https://rubygems.org/gems/gitalytics)
5
6
 
6
- [![Gem Version](https://badge.fury.io/rb/gitalytics.png)](http://badge.fury.io/rb/gitalytics)
7
- [![Dependency Status](https://gemnasium.com/pepito2k/gitalytics.png)](https://gemnasium.com/pepito2k/gitalytics)
8
- [![Build Status](https://travis-ci.org/pepito2k/gitalytics.png)](https://travis-ci.org/pepito2k/gitalytics)
7
+ Commit statistics for any git repository, in your terminal or as a single self-contained HTML report.
9
8
 
10
- [![Coverage Status](https://coveralls.io/repos/pepito2k/gitalytics/badge.png?branch=master)](https://coveralls.io/r/pepito2k/gitalytics?branch=master)
11
- [![Code Climate](https://codeclimate.com/github/pepito2k/gitalytics.png)](https://codeclimate.com/github/pepito2k/gitalytics)
12
- [![codebeat badge](https://codebeat.co/badges/166f8f5d-5596-44ef-a762-4b89fc5b531f)](https://codebeat.co/projects/github-com-pepito2k-gitalytics)
9
+ Originally based on a gist by Tobin Harris: https://gist.github.com/tobinharris/396634
13
10
 
14
- [![GitHub forks](https://img.shields.io/github/forks/pepito2k/gitalytics.svg)](https://github.com/pepito2k/gitalytics/network)
15
- [![GitHub stars](https://img.shields.io/github/stars/pepito2k/gitalytics.svg)](https://github.com/pepito2k/gitalytics/stargazers)
16
- [![GitHub issues](https://img.shields.io/github/issues/pepito2k/gitalytics.svg)](https://github.com/pepito2k/gitalytics/issues)
17
-
18
- ![Total Downloads](http://ruby-gem-downloads-badge.herokuapp.com/gitalytics?type=total)
19
-
20
- ![Gitalytics Screenshot](http://photos.gonzalo.robaina.me.s3.amazonaws.com/gitalytics_screen.png "Gitalytics Screenshot")
11
+ ![Gitalytics HTML report](docs/report.png)
21
12
 
22
13
  ## Installation
23
14
 
24
- ### Manual installation
15
+ Gitalytics needs Ruby 3.1 or newer and has no other runtime dependencies.
25
16
 
26
17
  gem install gitalytics
27
18
 
28
- ### Using bundler
29
- Add gitalytics to your Gemfile
30
-
31
- gem "gitalytics"
19
+ Or add it to your Gemfile:
32
20
 
33
- Install the gem
34
-
35
- bundle install
21
+ gem 'gitalytics'
36
22
 
37
23
  ## Usage
38
- Open a terminal window pointing to your git repository and just run the gitalytics command:
24
+
25
+ Run it from inside any git repository:
39
26
 
40
27
  $ gitalytics
41
28
 
42
- If you'd like to get a fancy html report like the one in the screenshot above, you will need to run the following command:
29
+ This prints a summary of the repository: the period covered, totals for lines, files and active days, and a table of the top authors with their share of commits:
30
+
31
+ gitalytics 83 commits by 10 authors
32
+ Jan 6, 2014 to Nov 26, 2026 (4,708 days)
33
+
34
+ Lines +4,056 -2,258 Longest streak 3 days
35
+ Files touched 44 Busiest day Nov 26, 2026 (14 commits)
36
+ Active days 18 of 4,708 Commits/day 4.6
37
+
38
+ Author Commits Share Added Deleted Last commit
39
+ Gonzalo Robaina 57 68.7% ██████▉ +2,045 -1,163 2026-11-26
40
+ Claude 9 10.8% █▏ +1,501 -912 2026-11-26
41
+ Alex Funk 4 4.8% ▌ +7 -5 2015-10-17
42
+ ... and 7 more authors (use --top 0 to list everyone)
43
+
44
+ The table fits your terminal width and uses colors in a terminal. Set `NO_COLOR` or pass `--no-color` to turn colors off, and use `--top N` to list more or fewer authors.
45
+
46
+ For the full HTML report, run:
43
47
 
44
48
  $ gitalytics -h
45
49
 
46
- If you want to have the html report but don't want it to be opened right away just write:
50
+ This writes `gitalytics_result.html` in the current directory and opens it in your browser. To write the report without opening it:
47
51
 
48
52
  $ gitalytics -n
49
53
 
50
- Note that gitalytics groups authors by name, you can change that and group by email using:
54
+ The report is a single HTML file with no external CSS or JavaScript, so you can open it offline, attach it or publish it anywhere. It includes:
55
+
56
+ - an overview of commits, authors, lines changed, files touched, active days and the longest streak
57
+ - an activity timeline (per week, or per month for long histories)
58
+ - a sortable author leaderboard with each author's share and trend
59
+ - a weekday by hour punch card
60
+ - the most changed files and top directories
61
+ - highlights such as the first commit, the busiest day and the longest commit message
62
+
63
+ It follows your system's light or dark theme. Author avatars come from Gravatar when available and fall back to initials.
64
+
65
+ To look at a time window, or to feed the numbers into another tool:
66
+
67
+ $ gitalytics -h --since "1 year ago"
68
+ $ gitalytics --json --since 2024-01-01 --until 2024-12-31 > stats.json
51
69
 
52
- $ gitalytics -e
70
+ ### Options
71
+
72
+ | Option | Description |
73
+ | --- | --- |
74
+ | `-h`, `--html` | Write the HTML report and open it in your browser |
75
+ | `-n`, `--no-browser` | Write the HTML report without opening it |
76
+ | `-o`, `--output FILE` | Where to write the HTML report (default `gitalytics_result.html`) |
77
+ | `-j`, `--json` | Print a JSON summary (totals, authors, weekdays, top files) to stdout |
78
+ | `-s`, `--since DATE` | Only count commits after `DATE` (anything git accepts, e.g. `2024-01-01` or `"6 months ago"`) |
79
+ | `-u`, `--until DATE` | Only count commits before `DATE` |
80
+ | `-m`, `--no-merges` | Leave merge commits out of the stats |
81
+ | `-t`, `--top N` | How many authors the terminal summary lists (default 10, `0` for all) |
82
+ | `--[no-]color` | Force or disable colors in the terminal summary |
83
+ | `-e`, `--group-email` | Group commits by author email instead of name (case-insensitive) |
84
+ | `-b`, `--benchmark` | Print how long the analysis took |
85
+ | `-v`, `--version` | Print the version |
86
+
87
+ Authors are read through git's [`.mailmap`](https://git-scm.com/docs/gitmailmap), so add one to the repository to merge the identities of people who committed under several names or emails.
88
+
89
+ ## Development
90
+
91
+ bundle install
92
+ bundle exec rake test
93
+ bundle exec rubocop
53
94
 
54
95
  ## License
55
96
  Copyright (c) 2016 Gonzalo Robaina
data/Rakefile CHANGED
@@ -1,4 +1,6 @@
1
- require "bundler/gem_tasks"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
2
4
  require 'rake/testtask'
3
5
 
4
6
  Rake::TestTask.new do |t|
@@ -0,0 +1,295 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <meta name="generator" content="Gitalytics <%= Gitalytics::VERSION %>">
7
+ <title><%= h repo_name %> · Gitalytics</title>
8
+ <style>
9
+ :root {
10
+ --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f0f2f5; --border: #e3e6eb;
11
+ --text: #1b1f27; --muted: #677084; --faint: #9aa2b1;
12
+ --accent: #4f6bed; --accent-soft: rgba(79,107,237,.14);
13
+ --plus: #1a9c63; --minus: #d64545;
14
+ --radius: 14px; --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
15
+ }
16
+ @media (prefers-color-scheme: dark) {
17
+ :root {
18
+ --bg: #0f1218; --surface: #171b23; --surface-2: #1f2430; --border: #2a303c;
19
+ --text: #e7eaf0; --muted: #9aa3b5; --faint: #6b7385;
20
+ --accent: #7b92ff; --accent-soft: rgba(123,146,255,.16);
21
+ --plus: #3ccf8e; --minus: #ff6b6b; --shadow: none;
22
+ }
23
+ }
24
+ * { box-sizing: border-box; }
25
+ html { -webkit-text-size-adjust: 100%; }
26
+ body {
27
+ margin: 0; background: var(--bg); color: var(--text);
28
+ font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
29
+ font-variant-numeric: tabular-nums;
30
+ }
31
+ a { color: var(--accent); text-decoration: none; }
32
+ a:hover { text-decoration: underline; }
33
+ .wrap { max-width: 1120px; margin: 0 auto; padding: 32px 20px 56px; }
34
+
35
+ header.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 28px; }
36
+ .brand { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
37
+ .brand svg { width: 18px; height: 18px; color: var(--accent); }
38
+ h1 { margin: 6px 0 4px; font-size: 32px; line-height: 1.15; letter-spacing: -.02em; word-break: break-word; }
39
+ .subtitle { color: var(--muted); margin: 0; }
40
+ .meta { color: var(--faint); font-size: 13px; text-align: right; }
41
+
42
+ nav.tabs { position: sticky; top: 0; z-index: 5; display: flex; gap: 4px; overflow-x: auto; margin: 0 -20px 24px; padding: 10px 20px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
43
+ nav.tabs a { white-space: nowrap; padding: 6px 12px; border-radius: 999px; color: var(--muted); font-weight: 500; font-size: 14px; }
44
+ nav.tabs a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
45
+
46
+ .kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 24px; }
47
+ .kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
48
+ .kpi .label { color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
49
+ .kpi .value { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; }
50
+ .kpi .hint { color: var(--faint); font-size: 12.5px; }
51
+ .plus { color: var(--plus); } .minus { color: var(--minus); }
52
+
53
+ section.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px 24px; margin-bottom: 24px; box-shadow: var(--shadow); scroll-margin-top: 64px; }
54
+ section.card > header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 16px; }
55
+ h2 { font-size: 18px; margin: 0; letter-spacing: -.01em; }
56
+ .card .sub { color: var(--muted); font-size: 13.5px; margin: 2px 0 0; }
57
+ .grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 24px; }
58
+ .grid-2 > section.card { margin-bottom: 0; }
59
+ .grid-2 + section, .grid-2 { margin-bottom: 24px; }
60
+
61
+ svg.chart { width: 100%; height: auto; display: block; overflow: visible; }
62
+ svg .grid { stroke: var(--border); stroke-width: 1; }
63
+ svg .axis { fill: var(--faint); font-size: 11px; }
64
+ svg .bar { fill: var(--accent); }
65
+ svg .bar:hover { fill: color-mix(in srgb, var(--accent) 70%, var(--text)); }
66
+ svg .dot { fill: var(--accent); opacity: .85; }
67
+ svg .dot:hover { opacity: 1; }
68
+ svg .dot.empty { fill: var(--border); opacity: 1; }
69
+ .spark { width: 96px; height: 28px; display: block; }
70
+
71
+ .sharebar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--surface-2); margin-bottom: 18px; }
72
+ .sharebar span { display: block; height: 100%; }
73
+
74
+ .table-wrap { overflow-x: auto; margin: 0 -24px; padding: 0 24px; }
75
+ table { width: 100%; border-collapse: collapse; font-size: 14px; }
76
+ th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; padding: 0 10px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; cursor: pointer; user-select: none; }
77
+ th.num, td.num { text-align: right; }
78
+ th[aria-sort="ascending"]::after { content: " ↑"; } th[aria-sort="descending"]::after { content: " ↓"; }
79
+ td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
80
+ tr:last-child td { border-bottom: 0; }
81
+ .who { display: flex; align-items: center; gap: 10px; min-width: 200px; max-width: 300px; }
82
+ .who > span:last-child { min-width: 0; } .who .name, .who .email { overflow: hidden; text-overflow: ellipsis; }
83
+ .avatar { position: relative; flex: none; width: 34px; height: 34px; border-radius: 50%; color: #fff; display: grid; place-items: center; font-size: 12.5px; font-weight: 700; overflow: hidden; }
84
+ .avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
85
+ .who .name { font-weight: 600; }
86
+ .who .email { color: var(--faint); font-size: 12.5px; }
87
+ .pct { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
88
+ .pct .track { width: 64px; height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
89
+ .pct .fill { display: block; height: 100%; border-radius: 999px; }
90
+ .rank { color: var(--faint); width: 1%; }
91
+ #authors-table:not(.expanded) tr.more { display: none; }
92
+ .show-all { margin-top: 14px; font: inherit; font-size: 14px; font-weight: 500; color: var(--accent); background: var(--accent-soft); border: 0; border-radius: 999px; padding: 7px 14px; cursor: pointer; }
93
+ .show-all:hover { filter: brightness(1.05); }
94
+
95
+ .rows { list-style: none; margin: 0; padding: 0; }
96
+ .rows li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
97
+ .rows li:last-child { border-bottom: 0; }
98
+ .rows .path { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
99
+ .rows .meter { grid-column: 1 / -1; height: 4px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
100
+ .rows .meter span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
101
+ .rows .stat { color: var(--muted); font-size: 13px; }
102
+
103
+ .weekdays { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; margin-top: 14px; }
104
+ .weekdays div { background: var(--surface-2); border-radius: 10px; padding: 8px; text-align: center; font-size: 12px; color: var(--muted); }
105
+ .weekdays b { display: block; color: var(--text); font-size: 16px; }
106
+
107
+ .highlights { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; align-items: start; }
108
+ .hl { background: var(--surface-2); border-radius: 12px; padding: 14px 16px; }
109
+ .hl .label { color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
110
+ .hl blockquote { margin: 6px 0; font-size: 15px; word-break: break-word; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
111
+ .hl .by { color: var(--faint); font-size: 12.5px; }
112
+ .hl .big { font-size: 22px; font-weight: 650; margin: 4px 0 2px; }
113
+
114
+ footer.foot { color: var(--faint); font-size: 13px; text-align: center; margin-top: 32px; }
115
+ .empty-state { text-align: center; padding: 64px 0; color: var(--muted); }
116
+ @media (max-width: 600px) { h1 { font-size: 26px; } .meta { text-align: left; } section.card { padding: 18px 16px; } .table-wrap { margin: 0 -16px; padding: 0 16px; } .weekdays { gap: 4px; } .weekdays div { padding: 6px 2px; } .weekdays b { font-size: 14px; } }
117
+ </style>
118
+ </head>
119
+ <body>
120
+ <div class="wrap">
121
+ <header class="top">
122
+ <div>
123
+ <div class="brand"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><circle cx="6" cy="6" r="2.5"/><circle cx="18" cy="18" r="2.5"/><circle cx="6" cy="18" r="2.5"/><path d="M6 8.5v7M18 15.5V12a4 4 0 0 0-4-4H8.5"/></svg>Gitalytics</div>
124
+ <h1><%= h repo_name %></h1>
125
+ <% if empty? -%>
126
+ <p class="subtitle">No commits yet.</p>
127
+ <% else -%>
128
+ <p class="subtitle"><%= plural(commits.size, 'commit') %> by <%= plural(users.size, 'author') %> from <%= fmt_date(first_commit.date) %> to <%= fmt_date(last_commit.date) %></p>
129
+ <% end -%>
130
+ </div>
131
+ <div class="meta">Generated <%= generated_at.strftime('%b %-d, %Y at %H:%M') %></div>
132
+ </header>
133
+ <% if empty? -%>
134
+ <div class="empty-state">This repository has no commits to analyze.</div>
135
+ <% else -%>
136
+ <nav class="tabs" aria-label="Sections">
137
+ <a href="#activity">Activity</a><a href="#authors">Authors</a><a href="#rhythm">Rhythm</a><a href="#files">Files</a><a href="#highlights">Highlights</a>
138
+ </nav>
139
+
140
+ <div class="kpis">
141
+ <div class="kpi"><div class="label">Commits</div><div class="value"><%= num commits.size %></div><div class="hint"><%= format('%.1f', commits.size / active_days.to_f) %> per active day</div></div>
142
+ <div class="kpi"><div class="label">Authors</div><div class="value"><%= num users.size %></div><div class="hint">top: <%= h users.first.name %></div></div>
143
+ <div class="kpi"><div class="label">Lines changed</div><div class="value"><span class="plus">+<%= num total_insertions %></span></div><div class="hint minus">−<%= num total_deletions %></div></div>
144
+ <div class="kpi"><div class="label">Files touched</div><div class="value"><%= num files_touched %></div><div class="hint">across all history</div></div>
145
+ <div class="kpi"><div class="label">Active days</div><div class="value"><%= num active_days %></div><div class="hint">of <%= plural(span_days, 'day') %></div></div>
146
+ <div class="kpi"><div class="label">Longest streak</div><div class="value"><%= num longest_streak %></div><div class="hint"><%= longest_streak == 1 ? 'day' : 'days in a row' %></div></div>
147
+ </div>
148
+
149
+ <section class="card" id="activity">
150
+ <header>
151
+ <div><h2>Activity</h2><p class="sub">Commits per <%= bucket_unit %>. Hover a bar for details.</p></div>
152
+ </header>
153
+ <%= timeline_svg %>
154
+ </section>
155
+
156
+ <section class="card" id="authors">
157
+ <header>
158
+ <div><h2>Authors</h2><p class="sub">Who's been shaping this codebase. Click a column to sort.</p></div>
159
+ </header>
160
+ <div class="sharebar" aria-hidden="true">
161
+ <% users.each do |u| -%>
162
+ <span style="width:<%= format('%.3f', share(u)) %>%;background:<%= color_for(u) %>" title="<%= h u.name %>: <%= format('%.1f', share(u)) %>%"></span>
163
+ <% end -%>
164
+ </div>
165
+ <div class="table-wrap">
166
+ <table id="authors-table">
167
+ <thead><tr>
168
+ <th class="rank" data-type="num">#</th><th data-type="text">Author</th><th class="num" data-type="num">Commits</th><th class="num" data-type="num">Share</th>
169
+ <th class="num" data-type="num">Added</th><th class="num" data-type="num">Removed</th><th class="num" data-type="num">Active days</th>
170
+ <th data-type="num">First</th><th data-type="num">Last</th><th data-type="none">Trend</th>
171
+ </tr></thead>
172
+ <tbody>
173
+ <% users.each_with_index do |u, i| -%>
174
+ <tr<%= ' class="more"' if i >= AUTHORS_SHOWN %>>
175
+ <td class="rank" data-v="<%= i + 1 %>"><%= i + 1 %></td>
176
+ <td data-v="<%= h u.name.to_s.downcase %>" title="<%= h u.name %> &lt;<%= h u.email %>&gt;"><div class="who">
177
+ <span class="avatar" style="background:<%= color_for(u) %>"><%= h u.initials %><img src="https://www.gravatar.com/avatar/<%= u.gravatar %>?s=68&amp;d=404" alt="" loading="lazy" onerror="this.remove()"></span>
178
+ <span><div class="name"><%= h u.name %></div><div class="email"><%= h u.email %></div></span>
179
+ </div></td>
180
+ <td class="num" data-v="<%= u.commits.size %>"><%= num u.commits.size %></td>
181
+ <td class="num" data-v="<%= share(u) %>"><div class="pct"><span><%= format('%.1f', share(u)) %>%</span><span class="track"><span class="fill" style="width:<%= format('%.2f', share(u)) %>%;background:<%= color_for(u) %>"></span></span></div></td>
182
+ <td class="num plus" data-v="<%= u.total_insertions %>">+<%= num u.total_insertions %></td>
183
+ <td class="num minus" data-v="<%= u.total_deletions %>">−<%= num u.total_deletions %></td>
184
+ <td class="num" data-v="<%= u.working_days %>"><%= num u.working_days %></td>
185
+ <td data-v="<%= u.first_commit.date.jd %>"><%= u.first_commit.date.strftime('%b %Y') %></td>
186
+ <td data-v="<%= u.last_commit.date.jd %>"><%= u.last_commit.date.strftime('%b %Y') %></td>
187
+ <td><%= sparkline_svg(u) %></td>
188
+ </tr>
189
+ <% end -%>
190
+ </tbody>
191
+ </table>
192
+ </div>
193
+ <% if users.size > AUTHORS_SHOWN -%>
194
+ <button type="button" class="show-all" id="authors-toggle" data-more="Show all <%= num users.size %> authors" data-less="Show top <%= AUTHORS_SHOWN %> only">Show all <%= num users.size %> authors</button>
195
+ <% end -%>
196
+ </section>
197
+
198
+ <section class="card" id="rhythm">
199
+ <header>
200
+ <div><h2>Rhythm</h2><p class="sub">When commits happen, by weekday and hour (in each author's local time).</p></div>
201
+ </header>
202
+ <%= punch_card_svg %>
203
+ <div class="weekdays">
204
+ <% %w[Mon Tue Wed Thu Fri Sat Sun].each_with_index do |d, i| -%>
205
+ <div><b><%= num weekday_totals[i] %></b><%= d %></div>
206
+ <% end -%>
207
+ </div>
208
+ </section>
209
+
210
+ <div class="grid-2" id="files">
211
+ <section class="card">
212
+ <header><div><h2>Most changed files</h2><p class="sub">By lines added + removed.</p></div></header>
213
+ <% files = top_files; max_churn = files.map { |_, s| s[:insertions] + s[:deletions] }.max.to_i -%>
214
+ <% if files.empty? -%>
215
+ <p class="sub">No file changes recorded.</p>
216
+ <% else -%>
217
+ <ul class="rows">
218
+ <% files.each do |name, s| churn = s[:insertions] + s[:deletions] -%>
219
+ <li><span class="path" title="<%= h name %>"><%= h name %></span><span class="stat"><span class="plus">+<%= num s[:insertions] %></span> <span class="minus">−<%= num s[:deletions] %></span> · <%= plural(s[:commits], 'commit') %></span><span class="meter"><span style="width:<%= max_churn.zero? ? 0 : format('%.1f', churn * 100.0 / max_churn) %>%"></span></span></li>
220
+ <% end -%>
221
+ </ul>
222
+ <% end -%>
223
+ </section>
224
+ <section class="card">
225
+ <header><div><h2>Top directories</h2><p class="sub">Where the churn is, by top-level folder.</p></div></header>
226
+ <% dirs = top_directories; max_dir = dirs.map(&:last).max.to_i -%>
227
+ <% if dirs.empty? -%>
228
+ <p class="sub">No file changes recorded.</p>
229
+ <% else -%>
230
+ <ul class="rows">
231
+ <% dirs.each do |dir, n| -%>
232
+ <li><span class="path"><%= h dir %></span><span class="stat"><%= num n %> lines</span><span class="meter"><span style="width:<%= max_dir.zero? ? 0 : format('%.1f', n * 100.0 / max_dir) %>%"></span></span></li>
233
+ <% end -%>
234
+ </ul>
235
+ <% end -%>
236
+ </section>
237
+ </div>
238
+
239
+ <section class="card" id="highlights">
240
+ <header><div><h2>Highlights</h2><p class="sub">A few fun facts from the log.</p></div></header>
241
+ <div class="highlights">
242
+ <div class="hl"><div class="label">First commit</div><blockquote><%= h first_commit.subject %></blockquote><div class="by"><%= h first_commit.author.name %> · <%= fmt_date(first_commit.date) %></div></div>
243
+ <div class="hl"><div class="label">Latest commit</div><blockquote><%= h last_commit.subject %></blockquote><div class="by"><%= h last_commit.author.name %> · <%= fmt_date(last_commit.date) %></div></div>
244
+ <% if (s = shortest_message) -%>
245
+ <div class="hl"><div class="label">Shortest message</div><blockquote><%= h s.subject %></blockquote><div class="by"><%= h s.author.name %> · <%= fmt_date(s.date) %></div></div>
246
+ <% end -%>
247
+ <% l = longest_message -%>
248
+ <div class="hl"><div class="label">Longest message</div><blockquote><%= h l.subject %></blockquote><div class="by"><%= h l.author.name %> · <%= fmt_date(l.date) %> · <%= l.subject.length %> chars</div></div>
249
+ <% day, day_commits = busiest_day -%>
250
+ <div class="hl"><div class="label">Busiest day</div><div class="big"><%= fmt_date(day) %></div><div class="by"><%= plural(day_commits.size, 'commit') %> by <%= h day_commits.map { |c| c.author.name }.uniq.join(', ') %></div></div>
251
+ <% top_wd = weekday_totals.each_with_index.max_by(&:first) -%>
252
+ <div class="hl"><div class="label">Favorite weekday</div><div class="big"><%= %w[Monday Tuesday Wednesday Thursday Friday Saturday Sunday][top_wd.last] %></div><div class="by"><%= format('%.0f', top_wd.first * 100.0 / commits.size) %>% of all commits</div></div>
253
+ </div>
254
+ </section>
255
+ <% end -%>
256
+
257
+ <footer class="foot">Made with <a href="https://github.com/pepito2k/gitalytics">Gitalytics</a> v<%= Gitalytics::VERSION %></footer>
258
+ </div>
259
+ <script>
260
+ (function () {
261
+ var table = document.getElementById('authors-table');
262
+ if (!table) return;
263
+ var heads = table.querySelectorAll('th');
264
+ heads.forEach(function (th, col) {
265
+ if (th.dataset.type === 'none') return;
266
+ th.addEventListener('click', function () {
267
+ var asc = th.getAttribute('aria-sort') !== 'ascending';
268
+ heads.forEach(function (h) { h.removeAttribute('aria-sort'); });
269
+ th.setAttribute('aria-sort', asc ? 'ascending' : 'descending');
270
+ var body = table.tBodies[0];
271
+ var rows = Array.prototype.slice.call(body.rows);
272
+ rows.sort(function (a, b) {
273
+ var x = a.cells[col].dataset.v, y = b.cells[col].dataset.v;
274
+ var r = th.dataset.type === 'num' ? parseFloat(x) - parseFloat(y) : x.localeCompare(y);
275
+ return asc ? r : -r;
276
+ });
277
+ rows.forEach(function (r) { body.appendChild(r); });
278
+ markMore();
279
+ });
280
+ });
281
+ // Only the first rows (in the current sort order) are shown until expanded.
282
+ function markMore() {
283
+ Array.prototype.forEach.call(table.tBodies[0].rows, function (r, i) {
284
+ r.classList.toggle('more', i >= <%= AUTHORS_SHOWN %>);
285
+ });
286
+ }
287
+ var toggle = document.getElementById('authors-toggle');
288
+ if (toggle) toggle.addEventListener('click', function () {
289
+ var open = table.classList.toggle('expanded');
290
+ toggle.textContent = open ? toggle.dataset.less : toggle.dataset.more;
291
+ });
292
+ })();
293
+ </script>
294
+ </body>
295
+ </html>
data/bin/gitalytics CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
2
+ # frozen_string_literal: true
3
3
 
4
4
  Encoding.default_external = Encoding::UTF_8
5
- $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
5
+ $LOAD_PATH.unshift(File.expand_path("#{File.dirname(__FILE__)}/../lib"))
6
6
 
7
7
  require 'benchmark'
8
8
  require 'optparse'
@@ -19,7 +19,7 @@ OptionParser.new do |opts|
19
19
  opts.banner = 'Usage: gitalytics [options]'
20
20
 
21
21
  opts.on('-v', '--version', 'Display gem version') do
22
- p "Gitalytics #{Gitalytics::VERSION}"
22
+ puts "Gitalytics #{Gitalytics::VERSION}"
23
23
  exit
24
24
  end
25
25
 
@@ -33,6 +33,36 @@ OptionParser.new do |opts|
33
33
  options[:browser] = false
34
34
  end
35
35
 
36
+ opts.on('-j', '--json', 'Print a JSON summary to stdout') do
37
+ options[:format] = 'json'
38
+ end
39
+
40
+ opts.on('-o', '--output FILE', "Where to write the HTML report (default: #{Gitalytics::OUTPUT_FILE})") do |file|
41
+ options[:output] = file
42
+ end
43
+
44
+ opts.on('-s', '--since DATE', 'Only commits after DATE (e.g. 2024-01-01 or "6 months ago")') do |date|
45
+ options[:since] = date
46
+ end
47
+
48
+ opts.on('-u', '--until DATE', 'Only commits before DATE') do |date|
49
+ options[:until] = date
50
+ end
51
+
52
+ opts.on('-m', '--no-merges', 'Leave merge commits out of the stats') do
53
+ options[:no_merges] = true
54
+ end
55
+
56
+ opts.on('-t', '--top N', Integer,
57
+ "How many authors the summary lists (default: #{Gitalytics::CliReport::DEFAULT_TOP}, 0 for all)") do |n|
58
+ options[:top] = n
59
+ end
60
+
61
+ opts.on('--[no-]color',
62
+ 'Force or disable colors in the summary (default: on in a terminal, off with NO_COLOR)') do |c|
63
+ options[:color] = c
64
+ end
65
+
36
66
  opts.on('-e', '--group-email', "Group commits by author's email address") do
37
67
  options[:group_by] = 'email'
38
68
  end
@@ -42,8 +72,13 @@ OptionParser.new do |opts|
42
72
  end
43
73
  end.parse!
44
74
 
45
- if options[:benchmark]
46
- puts Benchmark.measure { Gitalytics.analyze(options) }
47
- else
48
- Gitalytics.analyze(options)
75
+ begin
76
+ if options[:benchmark]
77
+ puts(Benchmark.measure { Gitalytics.analyze(options) })
78
+ else
79
+ Gitalytics.analyze(options)
80
+ end
81
+ rescue Gitalytics::GitError => e
82
+ warn "gitalytics: #{e.message}"
83
+ exit 1
49
84
  end
data/gitalytics.gemspec CHANGED
@@ -1,5 +1,6 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'gitalytics/version'
5
6
 
@@ -11,20 +12,16 @@ Gem::Specification.new do |spec|
11
12
  spec.email = 'gonzalo@robaina.me'
12
13
 
13
14
  spec.summary = 'Git Analytics'
14
- spec.description = 'Get usefull analytics from your git log'
15
- spec.homepage = 'http://gonza.uy/gitalytics'
15
+ spec.description = 'Commit statistics for any git repository, in your terminal or as a self-contained HTML report.'
16
+ spec.homepage = 'https://github.com/pepito2k/gitalytics'
16
17
  spec.license = 'MIT'
17
18
 
18
- spec.files = `git ls-files -z`.split("\x0")
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.start_with?('test/', 'docs/', '.') }
19
20
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
21
  spec.require_paths = ['lib']
22
22
 
23
- spec.required_ruby_version = '>= 2.0.0'
24
-
25
- spec.add_development_dependency 'bundler', '~> 1.7'
26
- spec.add_development_dependency 'rake', '~> 10.0'
27
- spec.add_development_dependency 'byebug'
28
- spec.add_dependency 'color-generator'
29
- spec.add_dependency 'haml'
23
+ spec.required_ruby_version = '>= 3.1'
24
+ spec.metadata['rubygems_mfa_required'] = 'true'
25
+ spec.metadata['changelog_uri'] = 'https://github.com/pepito2k/gitalytics/blob/master/CHANGELOG.md'
26
+ spec.metadata['source_code_uri'] = 'https://github.com/pepito2k/gitalytics'
30
27
  end