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

removing locals and ref's blocks to repository names, the rulesets will be based of the custom propertys > rulesets #48

Merged
merged 5 commits into from
Sep 4, 2024
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
14 changes: 0 additions & 14 deletions components/locals.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
locals {
# List of repositories to exclude from the production-repos.json file
excluded_repositories = [] # Add any repositories here you would like to exclude

# Read repositories from JSON file
all_repositories = jsondecode(data.local_file.repos_json.content)

# Filter out excluded repos
included_repositories = [
for repo in local.all_repositories : repo
if !contains(local.excluded_repositories, repo)
]
}

locals {
env_display_names = {
sbox = "Sandbox"
Expand Down
7 changes: 2 additions & 5 deletions components/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ resource "azurerm_storage_container" "tfstate" {
}

resource "github_organization_ruleset" "default_ruleset" {
name = "Rule Set Production Repositories"
name = "Production Repositories"
target = "branch"
enforcement = "active"

Expand All @@ -37,7 +37,7 @@ resource "github_organization_ruleset" "default_ruleset" {
exclude = []
}
repository_name {
include = local.included_repositories
include = []
exclude = []
}
}
Expand All @@ -49,11 +49,8 @@ resource "github_organization_ruleset" "default_ruleset" {
required_linear_history = true

pull_request {
dismiss_stale_reviews_on_push = true
require_code_owner_review = false
required_approving_review_count = 1
require_last_push_approval = true
required_review_thread_resolution = true
}
}

Expand Down
6 changes: 6 additions & 0 deletions custom-properties/set_org_custom_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ def define_custom_property(org_name):
2. Sends a PUT request to GitHub's API to create the property.
3. Defines the property as a boolean (true/false) value.
4. The JSON file is where all the production repositories are stored, these will then be used to assign custom properties to.

Error Handling:
1. Checks if the API response status code is not 200.
2. Logs an error message with the specific reason from the API, or a generic HTTP status code error if no specific message is provided.
3. Raises an HTTP error if the request was unsuccessful.

Args:
org_name (str): The name of the GitHub organisation.
Returns:
Expand Down Expand Up @@ -65,11 +67,13 @@ def set_custom_properties(repo_full_name, properties):
1. Sets custom properties for the repositories listed from the JSON file.
2. Sends a PATCH request to GitHub's API to update the repository's properties.
Sets the custom properties for a repository.

Error Handling:
1. Checks if the API response status code is not 204.
2. Logs an error message with the specific reason from the API, or a generic HTTP status code error if no specific message can be provided.
3. Raises an HTTP error if the request was unsuccessful.
Sets the custom properties for a repository.

Args:
repo_full_name (str): The full name of the repository (org/repo).
properties (dict): The custom properties to set.
Expand Down Expand Up @@ -100,6 +104,7 @@ def get_custom_properties(repo_full_name):
1. Retrieves the current custom properties of the repositories.
2. Sends a GET request to GitHub's API for the specific repository.
3. Returns the custom properties as a JSON object.

Args:
repo_full_name (str): The full name of the repository (org/repo).
Returns:
Expand All @@ -119,6 +124,7 @@ def load_production_repos():
1. Loads a list of production repositories from a JSON file.
2. Reads from the production-repos.json.
3. Parses the JSON content and returns it as a list.

Error Handling:
1. Handles FileNotFoundError by logging an error if the JSON file is not found, including the expected file path and current directory contents.
2. Handles JSONDecodeError by logging an error if the JSON file cannot be parsed correctly, including the specific error encountered.
Expand Down
Loading