-
Notifications
You must be signed in to change notification settings - Fork 3
read branch protection rules from config files #670
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
98818a9
read branch protection rules from config files
dbasunag eee17a5
updates based on review comments
dbasunag c4654a9
Merge branch 'main' into config
dbasunag c980198
Merge branch 'main' into config
dbasunag 34097ac
use branch_protection dict
dbasunag 71bf62d
address review comments
dbasunag 2a28be9
Merge branch 'main' into config
myakove File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import os | ||
| import pytest | ||
| from webhook_server_container.libs.config import Config | ||
| from webhook_server_container.utils.github_repository_settings import ( | ||
| get_repo_branch_protection_rules, | ||
| DEFAULT_BRANCH_PROTECTION, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def branch_protection_rules(request, mocker): | ||
| os.environ["WEBHOOK_SERVER_DATA_DIR"] = "webhook_server_container/tests/manifests" | ||
| config = Config() | ||
| repo_name = "test-repo" | ||
| data = config.data | ||
| data.setdefault("branch_protection", request.param.get("global", {})) | ||
| data["repositories"][repo_name].setdefault("branch_protection", request.param.get("repo", {})) | ||
| mocker.patch( | ||
| "webhook_server_container.libs.config.Config.data", new_callable=mocker.PropertyMock, return_value=data | ||
| ) | ||
| return get_repo_branch_protection_rules(config_data=config.data, repo_data=config.data["repositories"][repo_name])[ | ||
| "branch_protection" | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "branch_protection_rules, expected", | ||
| [ | ||
| pytest.param( | ||
| { | ||
| "global": { | ||
| "strict": True, | ||
| }, | ||
| "repo": { | ||
| "strict": False, | ||
| }, | ||
| }, | ||
| { | ||
| "strict": False, | ||
| }, | ||
| id="test_repo_branch_protection_rule", | ||
| ), | ||
| pytest.param( | ||
| { | ||
| "global": { | ||
| "strict": False, | ||
| }, | ||
| }, | ||
| { | ||
| "strict": False, | ||
| }, | ||
| id="test_global_branch_protection_rule", | ||
| ), | ||
| pytest.param( | ||
| { | ||
| "global": { | ||
| "strict": False, | ||
| "require_code_owner_reviews": True, | ||
| "dismiss_stale_reviews": False, | ||
| "required_approving_review_count": 2, | ||
| "required_linear_history": False, | ||
| }, | ||
| "repo": { | ||
| "strict": True, | ||
| "require_code_owner_reviews": True, | ||
| "dismiss_stale_reviews": False, | ||
| "required_approving_review_count": 1, | ||
| "required_linear_history": True, | ||
| }, | ||
| }, | ||
| { | ||
| "strict": True, | ||
| "require_code_owner_reviews": True, | ||
| "dismiss_stale_reviews": False, | ||
| "required_approving_review_count": 1, | ||
| "required_linear_history": True, | ||
| }, | ||
| id="test_repo_multiple_branch_protection_rule", | ||
| ), | ||
| pytest.param( | ||
| {}, | ||
| { | ||
| **DEFAULT_BRANCH_PROTECTION, | ||
| }, | ||
| id="test_default_branch_protection_rule", | ||
| ), | ||
| ], | ||
| indirect=["branch_protection_rules"], | ||
| ) | ||
| def test_branch_protection_setup(branch_protection_rules, expected): | ||
| mismatch = {} | ||
| for key in expected: | ||
| if branch_protection_rules[key] != expected[key]: | ||
| mismatch[key] = f"Expected value for {key}: {expected[key]}, actual: {branch_protection_rules[key]}" | ||
| assert not mismatch, f"Following mismatches are found: {mismatch}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.