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

support patterns in EXEMPT_REPOS #68

Merged
merged 2 commits into from
Nov 15, 2023
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
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ Note: Your GitHub token will need to have read access to all the repositories in

Below are the allowed configuration options:

| field | required | default | description |
|-----------------------|----------|---------|-------------|
| `GH_TOKEN` | true | | The GitHub Token used to scan repositories. Must have read access to all repositories you are interested in scanning |
| `ORGANIZATION` | false | | The organization to scan for stale repositories. If no organization is provided, this tool will search through repositories owned by the GH_TOKEN owner |
| `INACTIVE_DAYS` | true | | The number of days used to determine if repository is stale, based on `push` events |
| `EXEMPT_TOPICS` | false | | Comma separated list of topics to exempt from being flagged as stale |
| `EXEMPT_REPOS` | false | | Comma separated list of repositories to exempt from being flagged as stale. ie. `EXEMPT_REPOS = "stale-repos,test-repo"` |
| `GH_ENTERPRISE_URL` | false | `""` | URL of GitHub Enterprise instance to use for auth instead of github.com |
| field | required | default | description |
|-----------------------|----------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `GH_TOKEN` | true | | The GitHub Token used to scan repositories. Must have read access to all repositories you are interested in scanning |
| `ORGANIZATION` | false | | The organization to scan for stale repositories. If no organization is provided, this tool will search through repositories owned by the GH_TOKEN owner |
| `INACTIVE_DAYS` | true | | The number of days used to determine if repository is stale, based on `push` events |
| `EXEMPT_TOPICS` | false | | Comma separated list of topics to exempt from being flagged as stale |
| `EXEMPT_REPOS` | false | | Comma separated list of repositories to exempt from being flagged as stale. Supports Unix shell-style wildcards. ie. `EXEMPT_REPOS = "stale-repos,test-repo,conf-*"` |
| `GH_ENTERPRISE_URL` | false | `""` | URL of GitHub Enterprise instance to use for auth instead of github.com |

### Example workflow

Expand Down
4 changes: 2 additions & 2 deletions stale_repos.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
""" Find stale repositories in a GitHub organization. """

import fnmatch
import json
import os
from datetime import datetime, timezone
Expand Down Expand Up @@ -71,7 +71,7 @@ def is_repo_exempt(repo, exempt_repos, exempt_topics):
Returns:
True if the repo is exempt from the stale repo check, False otherwise.
"""
if exempt_repos and any(repo.name == exempt_repo for exempt_repo in exempt_repos):
if exempt_repos and any(fnmatch.fnmatchcase(repo.name, pattern) for pattern in exempt_repos):
print(f"{repo.html_url} is exempt from stale repo check")
return True
try:
Expand Down
19 changes: 15 additions & 4 deletions test_stale_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,13 +532,24 @@ def test_exempt_repos(self):
Test that a repo is exempt if its name is in the exempt_repos list.
"""
repo = MagicMock(name="repo", spec=["name", "html_url"])
repo.name = "exempt_repo"
exempt_repos = ["exempt_repo"]
exempt_topics = []

result = is_repo_exempt(repo, exempt_repos, exempt_topics)
test_cases = [
("exempt_repo", ["exempt_repo"], True),
("data-repo", ["data-*", "conf-*"], True),
("conf-repo", ["exempt_repo", "conf-*"], True),
("conf", ["conf-*"], False),
("repo", ["repo1", "repo-"], False),
zkoppert marked this conversation as resolved.
Show resolved Hide resolved
("repo", [""], False),
]

self.assertTrue(result)
for repo_name, exempt_repos, expected_result in test_cases:
with self.subTest(repo_name=repo_name, exempt_repos=exempt_repos):
repo.name = repo_name
repo.html_url = repo_name

result = is_repo_exempt(repo, exempt_repos, exempt_topics)
self.assertEqual(result, expected_result)

def test_exempt_topics(self):
"""
Expand Down