Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Add verify_all_repo_access config parameter #8

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ include_archived |no |true/false to include archived repos. D
include_disabled |no |true/false to include disabled repos. Default false
repository |no |(DEPRECATED) Allow list strategy to extract selected repos data from organization(has priority over repos_exclude)
max_rate_limit_wait_seconds |no |Max time to wait if you hit the github api limit. DEFAULT to 600s
verify_all_repo_access |no |Verify access to all selected repositories. If it's false then it verifies access only to the first selected repository. Default true

Example:
```json
Expand All @@ -70,7 +71,8 @@ Example:
"start_date": "2021-01-01T00:00:00Z",
"include_archived": false,
"include_disabled": false,
"max_rate_limit_wait_seconds": 800
"max_rate_limit_wait_seconds": 800,
"verify_all_repo_access": true
}
```

Expand Down
10 changes: 9 additions & 1 deletion tap_github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,16 @@ def verify_access_for_repo(config):
session.headers.update({'authorization': 'token ' + access_token, 'per_page': '1', 'page': '1'})

repositories = get_repos_from_config(config)
verify_all = config.get('verify_all_repo_access', True)

for repo in repositories:
if verify_all and len(repositories) > 0:
repos_to_verify = repositories
elif len(repositories) > 0:
repos_to_verify = [repositories[0]]
else:
repos_to_verify = []

for repo in repos_to_verify:
logger.info("Verifying access of repository: %s", repo)

url_for_repo = "https://api.github.com/repos/{}/commits".format(repo)
Expand Down
23 changes: 23 additions & 0 deletions tests/unittests/test_verify_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,26 @@ def test_repo_call_count(self, mocked_repo, mocked_logger_info):

self.assertEqual(mocked_logger_info.call_count, 3)
self.assertEqual(mocked_repo.call_count, 3)

def test_verify_repo_access_call_count(self, mocked_repo, mocked_logger_info):
mocked_repo.return_value = None

# Should verify all repository accesses by default
tap_github.verify_access_for_repo({"access_token": "access_token",
"repository": "org1/repo1 org1/repo2 org2/repo1"})
self.assertEqual(mocked_repo.call_count, 3)

# Should verify only one repository access if verify_all_repo_access is False
mocked_repo.reset_mock()
tap_github.verify_access_for_repo({"access_token": "access_token",
"repository": "org1/repo1 org1/repo2 org2/repo1",
"verify_all_repo_access": False})
self.assertEqual(mocked_repo.call_count, 1)

# Should verify all repository accesses if verify_all_repo_access is True
mocked_repo.reset_mock()
tap_github.verify_access_for_repo({"access_token": "access_token",
"repository": "org1/repo1 org1/repo2 org2/repo1",
"verify_all_repo_access": True})
self.assertEqual(mocked_repo.call_count, 3)