Skip to content

Commit

Permalink
Change monthly refresh to update only last month's commit counts
Browse files Browse the repository at this point in the history
  • Loading branch information
williln committed Jul 10, 2023
1 parent db33f57 commit 0415a11
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
11 changes: 5 additions & 6 deletions libraries/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ def get_commits(
all_commits.extend(page)

except Exception as e:
self.logger.exception("get_all_commits_failed", repo=repo_slug, msg=str(e))
self.logger.exception(
"get_all_commits_failed", repo=repo_slug, exc_msg=str(e)
)
return []

return all_commits
Expand Down Expand Up @@ -617,7 +619,7 @@ def get_library_list(self, gitmodules=None):

return libraries

def update_libraries(self):
def update_libraries(self, since: datetime = None, until: datetime = None):
"""Update all libraries with the metadata"""
raw_gitmodules = self.client.get_gitmodules()
gitmodules = self.parser.parse_gitmodules(raw_gitmodules.decode("utf-8"))
Expand All @@ -633,10 +635,7 @@ def update_libraries(self):
continue
self.update_categories(obj, categories=lib["category"])
self.update_authors(obj, authors=lib["authors"])
self.update_monthly_commit_counts(obj)
self.update_issues(obj)
self.update_prs(obj)

self.update_monthly_commit_counts(obj, since=since, until=until)
if not obj.first_github_tag_date:
self.update_first_github_tag_date(obj)

Expand Down
4 changes: 3 additions & 1 deletion libraries/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from config.celery import app
from libraries.github import LibraryUpdater
from libraries.utils import get_first_last_day_last_month


logger = structlog.getLogger(__name__)
Expand All @@ -28,7 +29,8 @@ def update_libraries():
from GitHub.
"""
since, until = get_first_last_day_last_month()
updater = LibraryUpdater()
updater.update_libraries()
updater.update_libraries(since=since, until=until)

logger.info("libraries_tasks_update_libraries_finished")
6 changes: 1 addition & 5 deletions libraries/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timedelta
from datetime import datetime
from dateutil.relativedelta import relativedelta
import os

Expand Down Expand Up @@ -37,10 +37,6 @@ def test_get_first_last_day_last_month():
# Assert that the last day is the last day of the month
assert (last_day + relativedelta(days=1)).day == 1

# Assert that the difference between first day and last day is within one month
assert (last_day - first_day) < timedelta(days=31)
assert (last_day - first_day) >= timedelta(days=28)

# Assert that both dates are less than today's date
assert first_day < datetime.now()
assert last_day < datetime.now()
Expand Down

0 comments on commit 0415a11

Please sign in to comment.