diff --git a/stale_repos.py b/stale_repos.py index 9386828..8a8b8ca 100755 --- a/stale_repos.py +++ b/stale_repos.py @@ -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 diff --git a/test_stale_repos.py b/test_stale_repos.py index 33a10bd..d019e59 100644 --- a/test_stale_repos.py +++ b/test_stale_repos.py @@ -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()