4
4
5
5
import collections
6
6
import csv
7
- import datetime
7
+ from datetime import datetime , timedelta
8
8
import json
9
9
import os
10
10
from typing import Optional , Dict , Any , List
@@ -126,8 +126,8 @@ def contribution_stats_by_author(branch: Optional[str] = None) -> None:
126
126
files = len (stats ['files' ])
127
127
commits = stats ['commits' ]
128
128
lines_changed = stats ['lines_changed' ]
129
- first_commit = datetime .datetime . fromtimestamp (stats ['first_commit' ]).strftime ('%a %b %d %H:%M:%S %Y %z' )
130
- last_commit = datetime .datetime . fromtimestamp (stats ['last_commit' ]).strftime ('%a %b %d %H:%M:%S %Y %z' )
129
+ first_commit = datetime .fromtimestamp (stats ['first_commit' ]).strftime ('%a %b %d %H:%M:%S %Y %z' )
130
+ last_commit = datetime .fromtimestamp (stats ['last_commit' ]).strftime ('%a %b %d %H:%M:%S %Y %z' )
131
131
132
132
# Calculate percentages
133
133
insertions_pct = (insertions / total_insertions * 100 ) if total_insertions else 0
@@ -153,30 +153,77 @@ def contribution_stats_by_author(branch: Optional[str] = None) -> None:
153
153
print (f" commits: { total_commits :<6} (100%)\n " )
154
154
155
155
156
-
157
- def git_changelogs_last_10_days (author : Optional [str ] = None ) -> None :
156
+ def changelogs (author : Optional [str ] = None , limit : int = 10 ) -> None :
158
157
"""
159
- Shows commit messages from the last 10 days. If an author is provided,
160
- it shows commit messages from that author.
158
+ Shows commit messages grouped by date, for the last 'limit' dates where commits occurred.
159
+
160
+ Args:
161
+ If an author is provided, it shows commit messages from that author.
162
+ Otherwise, it passes 'None' and shows commits from all authors.
161
163
"""
162
164
163
- if author :
164
- cmd = ['git' , 'log' , '--author' , author , '--since=10.days' , '--oneline' ]
165
- else :
166
- cmd = ['git' , 'log' , '--since=10.days' , '--oneline' ]
165
+ # Initialize variables similar to the Bash version
166
+ # TODO: Refactor this when we add global adjustment capabilities
167
+ next_date = datetime .now ().date ()
168
+ author_option = f'--author={ author } ' if author else ''
169
+ merges_option = '--no-merges' # Adjust as per the Bash global variable _merges
170
+
171
+ # Get unique commit dates
172
+ # Original version:
173
+ # git -c log.showSignature=false log --use-mailmap $_merges --format="%cd" --date=short "${_author}"
174
+ # "$_since" "$_until" $_log_options $_pathspec
175
+ cmd = ['git' , 'log' , '--use-mailmap' , merges_option , '--format=%cd' , '--date=short' ]
176
+ if author_option :
177
+ cmd .append (author_option )
178
+
179
+ print ('Git changelogs (last 10 commits)' )
167
180
181
+ # Get commit dates
168
182
output = run_git_command (cmd )
169
- if output :
170
- if author :
171
- print (f"Git changelogs by { author } (last 10 days):" )
172
- else :
173
- print ("Git changelogs (last 10 days):" )
174
- print (output )
175
- else :
176
- if author :
177
- print (f'No changelogs available for author { author } in the last 10 days.' )
178
- else :
179
- print ('No changelogs available in the last 10 days.' )
183
+ if not output :
184
+ print ("No commits found." )
185
+ return
186
+
187
+ # Process dates by splitting into date strings,
188
+ # removing dupes, sorting in reverse chrono order,
189
+ # and applying our limit defined above
190
+ dates = output .strip ().split ('\n ' )
191
+ dates = sorted (set (dates ), reverse = True )
192
+ dates = dates [:limit ]
193
+
194
+ # Create the date/day format of [YYYY-MM-DD] - Day of week
195
+ for date_str in dates :
196
+ date = datetime .strptime (date_str , '%Y-%m-%d' ).date ()
197
+ day_of_week = date .strftime ('%A' )
198
+ print (f"\n [{ date_str } - { day_of_week } ]" )
199
+
200
+ since_date = (date - timedelta (days = 1 )).strftime ('%Y-%m-%d' )
201
+ until_date = next_date .strftime ('%Y-%m-%d' )
202
+
203
+ # Build git log command for the date range
204
+ # Note the space between the --format and *. This provides
205
+ # the space should there be multiple entries per date string
206
+ # Original version:
207
+ # git -c log.showSignature=false log \
208
+ # --use-mailmap $_merges --format=" * %s (%aN)" \
209
+ # "${_author}" --since==$(date -d "$DATE - 1 day" +"%Y-%m-%d") \
210
+ # --until=$next
211
+ cmd = [
212
+ 'git' , 'log' , '--use-mailmap' , merges_option ,
213
+ '--format= * %s (%aN)' ,
214
+ f'--since={ since_date } ' ,
215
+ f'--until={ until_date } '
216
+ ]
217
+ if author_option :
218
+ cmd .append (author_option )
219
+
220
+ # Output everything to the terminal
221
+ # Note the space added. This provides the initial space
222
+ # before the asterisk for every initial entry
223
+ output = run_git_command (cmd )
224
+ if output :
225
+ print (f" { output } " )
226
+ next_date = date # Update next_date for the next iteration
180
227
181
228
182
229
def my_daily_status () -> None :
0 commit comments