Skip to content

Commit

Permalink
✨ feat: added the date range as the parameter to the get status function
Browse files Browse the repository at this point in the history
  • Loading branch information
huangyz0918 committed Oct 7, 2024
1 parent 3c40234 commit 25c972e
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions mle/integration/local_git.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from git import Repo, NULL_TREE
from datetime import datetime
from datetime import datetime, timedelta


class GitIntegration:
Expand Down Expand Up @@ -29,22 +29,25 @@ def get_repo_status(self):
except Exception as e:
return f"An error occurred: {str(e)}"

def get_commit_history(self, limit=None):
def get_commit_history(self, date_range=None, limit=None):
"""
Get commit history from a git repository
:param limit: Number of commits to retrieve
:param date_range: Number of days to look back from today (default None)
:param limit: Number of commits to retrieve (default None)
:return: List of commit history
"""
try:
commit_history = []
for commit in self.repo.iter_commits(max_count=limit):
commit_history.append({
'commit_hash': commit.hexsha,
'author': commit.author.name,
'email': commit.author.email,
'message': commit.message.strip(),
'date': datetime.fromtimestamp(commit.committed_date).strftime("%Y-%m-%d %H:%M:%S")
})
commit_date = datetime.fromtimestamp(commit.committed_date)
if date_range is None or (datetime.now() - commit_date).days <= date_range:
commit_history.append({
'commit_hash': commit.hexsha,
'author': commit.author.name,
'email': commit.author.email,
'message': commit.message.strip(),
'date': commit_date.strftime("%Y-%m-%d %H:%M:%S")
})

return commit_history

Expand Down

0 comments on commit 25c972e

Please sign in to comment.