-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcommit_history.py
More file actions
54 lines (44 loc) · 1.63 KB
/
commit_history.py
File metadata and controls
54 lines (44 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import subprocess
from collections import defaultdict
from datetime import datetime, timedelta
import matplotlib.pyplot as plt
# Get git log data
git_log_cmd = ['git', 'log', '--format=%ai']
process = subprocess.Popen(git_log_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = process.communicate()
# Process the dates
commit_dates = defaultdict(int)
dates = output.decode().strip().split('\n')
for date_str in dates:
if date_str:
# Convert to datetime and get just the date part
commit_date = datetime.strptime(date_str.split()[0], '%Y-%m-%d').date()
commit_dates[commit_date] += 1
# Sort dates and prepare data for plotting
sorted_dates = sorted(commit_dates.keys())
if sorted_dates:
# Create lists for x and y axes
dates_list = []
commits_list = []
# Fill in missing dates with zero commits
current_date = sorted_dates[0]
end_date = datetime.now().date() # Current date
while current_date <= end_date:
dates_list.append(current_date)
commits_list.append(commit_dates[current_date])
current_date += timedelta(days=1)
# Create the plot
plt.figure(figsize=(12, 6))
plt.bar(dates_list, commits_list, color='#2ecc71')
plt.title('Daily Git Commits')
plt.xlabel('Date')
plt.ylabel('Number of Commits')
# Rotate date labels for better readability
plt.xticks(rotation=45)
# Adjust layout to prevent label cutoff
plt.tight_layout()
# Save the plot
plt.savefig('commit_history.png')
print("Chart has been saved as 'commit_history.png'")
else:
print("No commit history found in this repository.")