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

feat: add repos_missing_codeowners to issue report #203

Merged
merged 2 commits into from
Mar 3, 2025
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
3 changes: 3 additions & 0 deletions cleanowners.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def main(): # pragma: no cover
repos = get_repos_iterator(organization, repository_list, github_connection)

repo_and_users_to_remove = {}
repos_missing_codeowners = []
for repo in repos:
# Check if the repository is in the exempt_repositories_list
if repo.full_name in exempt_repositories_list:
Expand All @@ -87,6 +88,7 @@ def main(): # pragma: no cover
if not codeowners_file_contents:
print(f"Skipping {repo.full_name} as it does not have a CODEOWNERS file")
no_codeowners_count += 1
repos_missing_codeowners.append(repo)
continue

codeowners_count += 1
Expand Down Expand Up @@ -167,6 +169,7 @@ def main(): # pragma: no cover
no_codeowners_count,
codeowners_count,
repo_and_users_to_remove,
repos_missing_codeowners,
)


Expand Down
6 changes: 6 additions & 0 deletions markdown_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def write_to_markdown(
no_codeowners_count,
codeowners_count,
repo_and_users_to_remove,
repos_missing_codeowners,
):
"""Write the results to a markdown file"""
with open("report.md", "w", encoding="utf-8") as file:
Expand All @@ -25,3 +26,8 @@ def write_to_markdown(
for user in users:
file.write(f"- {user}\n")
file.write("\n")
if repos_missing_codeowners:
file.write("## Repositories Missing CODEOWNERS\n")
for repo in repos_missing_codeowners:
file.write(f"- {repo}\n")
file.write("\n")
30 changes: 26 additions & 4 deletions test_markdown_writer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Unit tests for the write_to_markdown function in markdown_writer.py """
"""Unit tests for the write_to_markdown function in markdown_writer.py"""

import unittest
from unittest.mock import call, mock_open, patch
Expand All @@ -13,7 +13,7 @@ def test_write_with_all_counts_and_no_users_to_remove(self):
"""Test that the function writes the correct markdown when there are no users to remove"""
mock_file = mock_open()
with patch("builtins.open", mock_file):
write_to_markdown(0, 0, 2, 3, {})
write_to_markdown(0, 0, 2, 3, {}, [])
mock_file().write.assert_called_once_with(
"# Cleanowners Report\n\n"
"## Overall Stats\n"
Expand All @@ -28,7 +28,7 @@ def test_write_with_repos_and_users_with_users_to_remove(self):
mock_file = mock_open()
repo_users = {"repo1": ["user1", "user2"], "repo2": ["user3"]}
with patch("builtins.open", mock_file):
write_to_markdown(1, 2, 3, 4, repo_users)
write_to_markdown(1, 2, 3, 4, repo_users, [])
calls = [
call(
"# Cleanowners Report\n\n"
Expand All @@ -49,11 +49,33 @@ def test_write_with_repos_and_users_with_users_to_remove(self):
]
mock_file().write.assert_has_calls(calls, any_order=False)

def test_write_with_repos_missing_codeowners(self):
"""Test that the function writes the correct markdown when there are repos missing CODEOWNERS"""
mock_file = mock_open()
repos_missing_codeowners = ["repo1", "repo2"]
with patch("builtins.open", mock_file):
write_to_markdown(0, 0, 2, 0, {}, repos_missing_codeowners)
calls = [
call(
"# Cleanowners Report\n\n"
"## Overall Stats\n"
"0 Users to Remove\n"
"0 Pull Requests created\n"
"2 Repositories with no CODEOWNERS file\n"
"0 Repositories with CODEOWNERS file\n"
),
call("## Repositories Missing CODEOWNERS\n"),
call("- repo1\n"),
call("- repo2\n"),
call("\n"),
]
mock_file().write.assert_has_calls(calls, any_order=False)

def test_write_with_empty_inputs(self):
"""Test that the function writes the correct markdown when all inputs are 0"""
mock_file = mock_open()
with patch("builtins.open", mock_file):
write_to_markdown(0, 0, 0, 0, {})
write_to_markdown(0, 0, 0, 0, {}, [])
mock_file().write.assert_called_once_with(
"# Cleanowners Report\n\n"
"## Overall Stats\n"
Expand Down
Loading