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: handle if ORGANIZATION not provided #32

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 7 additions & 6 deletions cleanowners.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ def main(): # pragma: no cover
usernames = get_usernames_from_codeowners(codeowners_file_contents)

for username in usernames:
org = organization if organization else repo.owner.login
# Check to see if the username is a member of the organization
if not github_connection.organization(organization).is_member(username):
if not github_connection.organization(org).is_member(username):
zkoppert marked this conversation as resolved.
Show resolved Hide resolved
print(
f"\t{username} is not a member of {organization}. Suggest removing them from {repo.full_name}"
f"\t{username} is not a member of {org}. Suggest removing them from {repo.full_name}"
)
users_count += 1
if not dry_run:
Expand Down Expand Up @@ -143,10 +144,10 @@ def get_repos_iterator(organization, repository_list, github_connection):
repos = github_connection.organization(organization).repositories()
else:
# Get the repositories from the repository_list
for repo in repository_list:
repos.append(
github_connection.repository(repo.split("/")[0], repo.split("/")[1])
)
for full_repo_path in repository_list:
org = full_repo_path.split("/")[0]
repo = full_repo_path.split("/")[1]
repos.append(github_connection.repository(org, repo))
zkoppert marked this conversation as resolved.
Show resolved Hide resolved

return repos

Expand Down
1 change: 1 addition & 0 deletions test_auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test cases for the auth module."""

import unittest
from unittest.mock import patch

Expand Down
4 changes: 2 additions & 2 deletions test_cleanowners.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_get_repos_iterator_with_organization(self, mock_github):
def test_get_repos_iterator_with_repository_list(self, mock_github):
"""Test the get_repos_iterator function with a repository list"""
organization = None
repository_list = ["org/repo1", "org/repo2"]
repository_list = ["org/repo1", "org2/repo2"]
github_connection = mock_github.return_value

mock_repository = MagicMock()
Expand All @@ -123,7 +123,7 @@ def test_get_repos_iterator_with_repository_list(self, mock_github):
# Assert that the repository method was called with the correct arguments for each repository in the list
expected_calls = [
unittest.mock.call("org", "repo1"),
unittest.mock.call("org", "repo2"),
unittest.mock.call("org2", "repo2"),
]
github_connection.repository.assert_has_calls(expected_calls)

Expand Down