Skip to content

Commit

Permalink
feat: switch get_last_updated from date -> datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
ghickman committed Apr 15, 2022
1 parent fadf421 commit c948d10
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions osgithub/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,18 +364,18 @@ def get_commits_for_file(self, path, ref, number_of_commits=1):

def get_last_updated(self, path, ref):
"""
Finds the date of the last commit for a file
Finds the datetime of the last commit for a file

Args:
path (str): path to the file in the repo
ref (str): branch/tag/sha

Returns:
str: HTML from readme (at ROOT)
datetime: a datetime instance of the last commit's committed date
"""
commits = self.get_commits_for_file(path, ref, number_of_commits=1)
last_commit_date = commits[0]["commit"]["committer"]["date"]
return datetime.strptime(last_commit_date, "%Y-%m-%dT%H:%M:%SZ").date()
return datetime.strptime(last_commit_date, "%Y-%m-%dT%H:%M:%SZ")

def get_readme(self, tag="main"):
"""
Expand Down
6 changes: 3 additions & 3 deletions tests/test_github.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from base64 import b64encode
from datetime import date
from datetime import datetime
from os import environ

import pytest
Expand Down Expand Up @@ -285,7 +285,7 @@ def test_github_repo_get_last_updated(httpretty):
)

last_updated = repo.get_last_updated(path="test-folder/test-file.html", ref="main")
assert last_updated == date(2021, 3, 1)
assert last_updated == datetime(2021, 3, 1, 10, 0, 0)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -546,7 +546,7 @@ def test_github_repo_get_contents_too_large_file(httpretty):

content_file = repo.get_contents("test-folder/test-file.html", ref="main")
assert content_file.decoded_content == str_content
assert content_file.last_updated == date(2021, 3, 1)
assert content_file.last_updated == datetime(2021, 3, 1, 10, 0, 0)


def test_github_repo_get_readme(httpretty):
Expand Down

0 comments on commit c948d10

Please sign in to comment.