Skip to content

Commit 62198cd

Browse files
jrbeilkejmeridth
andauthored
feat: add repos_missing_codeowners to issue report (#203)
Co-authored-by: JM (Jason Meridth) <[email protected]>
1 parent ad3233e commit 62198cd

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

cleanowners.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def main(): # pragma: no cover
6969
repos = get_repos_iterator(organization, repository_list, github_connection)
7070

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

9294
codeowners_count += 1
@@ -167,6 +169,7 @@ def main(): # pragma: no cover
167169
no_codeowners_count,
168170
codeowners_count,
169171
repo_and_users_to_remove,
172+
repos_missing_codeowners,
170173
)
171174

172175

markdown_writer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ def write_to_markdown(
77
no_codeowners_count,
88
codeowners_count,
99
repo_and_users_to_remove,
10+
repos_missing_codeowners,
1011
):
1112
"""Write the results to a markdown file"""
1213
with open("report.md", "w", encoding="utf-8") as file:
@@ -25,3 +26,8 @@ def write_to_markdown(
2526
for user in users:
2627
file.write(f"- {user}\n")
2728
file.write("\n")
29+
if repos_missing_codeowners:
30+
file.write("## Repositories Missing CODEOWNERS\n")
31+
for repo in repos_missing_codeowners:
32+
file.write(f"- {repo}\n")
33+
file.write("\n")

test_markdown_writer.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Unit tests for the write_to_markdown function in markdown_writer.py """
1+
"""Unit tests for the write_to_markdown function in markdown_writer.py"""
22

33
import unittest
44
from unittest.mock import call, mock_open, patch
@@ -13,7 +13,7 @@ def test_write_with_all_counts_and_no_users_to_remove(self):
1313
"""Test that the function writes the correct markdown when there are no users to remove"""
1414
mock_file = mock_open()
1515
with patch("builtins.open", mock_file):
16-
write_to_markdown(0, 0, 2, 3, {})
16+
write_to_markdown(0, 0, 2, 3, {}, [])
1717
mock_file().write.assert_called_once_with(
1818
"# Cleanowners Report\n\n"
1919
"## Overall Stats\n"
@@ -28,7 +28,7 @@ def test_write_with_repos_and_users_with_users_to_remove(self):
2828
mock_file = mock_open()
2929
repo_users = {"repo1": ["user1", "user2"], "repo2": ["user3"]}
3030
with patch("builtins.open", mock_file):
31-
write_to_markdown(1, 2, 3, 4, repo_users)
31+
write_to_markdown(1, 2, 3, 4, repo_users, [])
3232
calls = [
3333
call(
3434
"# Cleanowners Report\n\n"
@@ -49,11 +49,33 @@ def test_write_with_repos_and_users_with_users_to_remove(self):
4949
]
5050
mock_file().write.assert_has_calls(calls, any_order=False)
5151

52+
def test_write_with_repos_missing_codeowners(self):
53+
"""Test that the function writes the correct markdown when there are repos missing CODEOWNERS"""
54+
mock_file = mock_open()
55+
repos_missing_codeowners = ["repo1", "repo2"]
56+
with patch("builtins.open", mock_file):
57+
write_to_markdown(0, 0, 2, 0, {}, repos_missing_codeowners)
58+
calls = [
59+
call(
60+
"# Cleanowners Report\n\n"
61+
"## Overall Stats\n"
62+
"0 Users to Remove\n"
63+
"0 Pull Requests created\n"
64+
"2 Repositories with no CODEOWNERS file\n"
65+
"0 Repositories with CODEOWNERS file\n"
66+
),
67+
call("## Repositories Missing CODEOWNERS\n"),
68+
call("- repo1\n"),
69+
call("- repo2\n"),
70+
call("\n"),
71+
]
72+
mock_file().write.assert_has_calls(calls, any_order=False)
73+
5274
def test_write_with_empty_inputs(self):
5375
"""Test that the function writes the correct markdown when all inputs are 0"""
5476
mock_file = mock_open()
5577
with patch("builtins.open", mock_file):
56-
write_to_markdown(0, 0, 0, 0, {})
78+
write_to_markdown(0, 0, 0, 0, {}, [])
5779
mock_file().write.assert_called_once_with(
5880
"# Cleanowners Report\n\n"
5981
"## Overall Stats\n"

0 commit comments

Comments
 (0)