Skip to content

Commit

Permalink
Merge pull request #56 from github/private-temp-forks
Browse files Browse the repository at this point in the history
fix: handle private temp forks which dont have topics
  • Loading branch information
zkoppert authored Aug 15, 2023
2 parents 03dd905 + 01fd5c7 commit c1d46fe
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
15 changes: 12 additions & 3 deletions stale_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,18 @@ def is_repo_exempt(repo, exempt_repos, exempt_topics):
if exempt_repos and any(repo.name == exempt_repo for exempt_repo in exempt_repos):
print(f"{repo.html_url} is exempt from stale repo check")
return True
if exempt_topics and any(topic in exempt_topics for topic in repo.topics().names):
print(f"{repo.html_url} is exempt from stale repo check")
return True
try:
if exempt_topics and any(
topic in exempt_topics for topic in repo.topics().names
):
print(f"{repo.html_url} is exempt from stale repo check")
return True
except github3.exceptions.NotFoundError as error_code:
if error_code.code == 404:
print(
f"{repo.html_url} does not have topics enabled and may be a private temporary fork"
)

return False


Expand Down
19 changes: 19 additions & 0 deletions test_stale_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,25 @@ def test_not_exempt(self):

self.assertFalse(result)

def test_not_found_error(self):
"""
Test that a repo is not exempt if a NotFoundError is raised
which happens for private temporary forks.
"""
repo = MagicMock(name="repo", spec=["name", "html_url", "topics"])
repo.name = "not_exempt_repo"
repo.topics.side_effect = github3.exceptions.NotFoundError(
resp=MagicMock(status_code=404)
)
exempt_repos = []
exempt_topics = ["exempt_topic"]

result = is_repo_exempt(
repo=repo, exempt_repos=exempt_repos, exempt_topics=exempt_topics
)

self.assertFalse(result)


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

0 comments on commit c1d46fe

Please sign in to comment.