Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove time of day and tz info properly #83

Merged
merged 4 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()