Skip to content

Commit

Permalink
Merge pull request #83 from github/fix-TZ
Browse files Browse the repository at this point in the history
fix: remove time of day and tz info properly
  • Loading branch information
jmeridth authored Apr 2, 2024
2 parents a7ecef4 + bbed3d5 commit 1cac70e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
16 changes: 12 additions & 4 deletions evergreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ def main(): # pragma: no cover
except github3.exceptions.NotFoundError:
pass

if created_after_date and repo.created_at.replace(
tzinfo=None
) < datetime.strptime(created_after_date, "%Y-%m-%d"):
if is_repo_created_date_before(repo.created_at, created_after_date):
continue

print("Checking " + repo.full_name)
Expand Down Expand Up @@ -161,8 +159,18 @@ def main(): # pragma: no cover
print("Done. " + str(count_eligible) + " repositories were eligible.")


def is_repo_created_date_before(repo_created_at: str, created_after_date: str):
"""Check if the repository was created before the created_after_date"""
repo_created_at_date = datetime.fromisoformat(repo_created_at).replace(tzinfo=None)
return created_after_date and repo_created_at_date < datetime.strptime(
created_after_date, "%Y-%m-%d"
)


def is_dependabot_security_updates_enabled(owner, repo, access_token):
"""Check if Dependabot security updates are enabled at the /repos/:owner/:repo/automated-security-fixes endpoint using the requests library"""
"""Check if Dependabot security updates are enabled at the
/repos/:owner/:repo/automated-security-fixes endpoint using the requests library
"""
url = f"https://api.github.com/repos/{owner}/{repo}/automated-security-fixes"
headers = {
"Authorization": f"Bearer {access_token}",
Expand Down
41 changes: 41 additions & 0 deletions test_evergreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
get_global_project_id,
get_repos_iterator,
is_dependabot_security_updates_enabled,
is_repo_created_date_before,
link_item_to_project,
)

Expand Down Expand Up @@ -579,5 +580,45 @@ def test_link_item_to_project_request_exception(self, mock_post):
self.assertIsNone(result)


class TestIsRepoCreateDateBeforeCreatedAfterDate(unittest.TestCase):
"""Test the is_repo_create_date_before_created_after_date function in evergreen.py"""

def test_is_repo_create_date_before_created_after_date(self):
"""Test the repo.created_at date is before created_after_date."""
repo_created_at = "2020-01-01T05:00:00Z"
created_after_date = "2021-01-01"

result = is_repo_created_date_before(repo_created_at, created_after_date)

self.assertTrue(result)

def test_is_repo_create_date_is_after_created_after_date(self):
"""Test the repo.created_at date is after created_after_date."""
repo_created_at = "2022-01-01T05:00:00Z"
created_after_date = "2021-01-01"

result = is_repo_created_date_before(repo_created_at, created_after_date)

self.assertFalse(result)

def test_is_repo_created_date_has_no_time_zone(self):
"""Test the repo.created_at date is after created_after_date."""
repo_created_at = "2020-01-01"
created_after_date = "2021-01-01"

result = is_repo_created_date_before(repo_created_at, created_after_date)

self.assertTrue(result)

def test_is_created_after_date_is_empty_string(self):
"""Test the repo.created_at date is after created_after_date."""
repo_created_at = "2020-01-01"
created_after_date = ""

result = is_repo_created_date_before(repo_created_at, created_after_date)

self.assertFalse(result)


if __name__ == "__main__":
unittest.main()

0 comments on commit 1cac70e

Please sign in to comment.