From ce5c794f2cfb1d3d8b685e3c21077f6b84ae763f Mon Sep 17 00:00:00 2001 From: Adina Rahim Date: Tue, 18 Feb 2025 18:07:59 +0000 Subject: [PATCH 01/17] little update to trigger rulesets --- src/classification_Iris_data.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/classification_Iris_data.py b/src/classification_Iris_data.py index 6d566b1..100101b 100644 --- a/src/classification_Iris_data.py +++ b/src/classification_Iris_data.py @@ -10,8 +10,7 @@ # kernelspec: # display_name: Python 3 (ipykernel) # language: python -# name: python3 -# --- + # + import streamlit as st From de3636e9843918884027753f466b9fe017c05fe5 Mon Sep 17 00:00:00 2001 From: Adina Rahim Date: Tue, 18 Feb 2025 18:09:31 +0000 Subject: [PATCH 02/17] Update Check Repository Ruleset.yaml --- .github/workflows/Check Repository Ruleset.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/Check Repository Ruleset.yaml b/.github/workflows/Check Repository Ruleset.yaml index 43c470b..096908c 100644 --- a/.github/workflows/Check Repository Ruleset.yaml +++ b/.github/workflows/Check Repository Ruleset.yaml @@ -36,7 +36,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} REPO_NAME: ${{ github.repository }} run: | - DEFAULT_BRANCH="main" + DEFAULT_BRANCH="development" # Fetch default branch dynamically #DEFAULT_BRANCH=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ # -H "Accept: application/vnd.github+json" \ @@ -141,4 +141,4 @@ jobs: exit 1 else echo " Ruleset matches" - fi \ No newline at end of file + fi From 0c693120c7559fba5b393ddd39cae1bb8f74c32b Mon Sep 17 00:00:00 2001 From: Adina Rahim Date: Tue, 18 Feb 2025 18:22:07 +0000 Subject: [PATCH 03/17] add granular detsils --- .../workflows/Check Repository Ruleset.yaml | 73 +++++++++++-------- 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/.github/workflows/Check Repository Ruleset.yaml b/.github/workflows/Check Repository Ruleset.yaml index 096908c..143ddcf 100644 --- a/.github/workflows/Check Repository Ruleset.yaml +++ b/.github/workflows/Check Repository Ruleset.yaml @@ -36,7 +36,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} REPO_NAME: ${{ github.repository }} run: | - DEFAULT_BRANCH="development" + DEFAULT_BRANCH="main" # Fetch default branch dynamically #DEFAULT_BRANCH=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ # -H "Accept: application/vnd.github+json" \ @@ -70,75 +70,88 @@ jobs: - name: Compare Rulesets run: | echo "Comparing fetched ruleset with expected ruleset..." + + # Load actual and expected rulesets using jq to extract only the necessary fields ACTUAL_RULES=$(jq -c 'map({type, parameters: (if has("parameters") then .parameters else {} end)})' ruleset_response.json) EXPECTED_RULES=$(jq -c 'map({type, parameters: (if has("parameters") then .parameters else {} end)})' expected_ruleset.json) - + echo "Actual Rules: $ACTUAL_RULES" echo "Expected Rules: $EXPECTED_RULES" - + + # Check if the fetched rulesets are empty or invalid if [[ -z "$ACTUAL_RULES" || -z "$EXPECTED_RULES" ]]; then echo "Error: One of the rulesets is empty. Check API response." exit 1 fi - + + # Function to compare rule parameters dynamically compare_rule() { local rule_type=$1 local expected_rule=$2 local actual_rule=$3 - + + # If the rule type is 'pull_request', compare the 'parameters' field if [[ "$rule_type" == "pull_request" ]]; then EXPECTED_PR_PARAMS=$(echo "$expected_rule" | jq -c '(if has("parameters") then .parameters else {} end)') ACTUAL_PR_PARAMS=$(echo "$actual_rule" | jq -c '(if has("parameters") then .parameters else {} end)') - - EXPECTED_MERGE_METHODS=$(echo "$EXPECTED_PR_PARAMS" | jq -c 'if has("allowed_merge_methods") then .allowed_merge_methods | sort else [] end') - ACTUAL_MERGE_METHODS=$(echo "$ACTUAL_PR_PARAMS" | jq -c 'if has("allowed_merge_methods") then .allowed_merge_methods | sort else [] end') - - echo "Expected Merge Methods: $EXPECTED_MERGE_METHODS" - echo "Actual Merge Methods: $ACTUAL_MERGE_METHODS" - - if [[ "$EXPECTED_MERGE_METHODS" != "$ACTUAL_MERGE_METHODS" ]]; then - echo " Pull request rule 'allowed_merge_methods' mismatch" - echo "Expected: $EXPECTED_MERGE_METHODS" - echo "Actual: $ACTUAL_MERGE_METHODS" - return 1 - fi - + + # Compare each parameter dynamically + for param in $(echo "$EXPECTED_PR_PARAMS" | jq -r 'keys[]'); do + EXPECTED_PARAM_VALUE=$(echo "$EXPECTED_PR_PARAMS" | jq -r --arg param "$param" '.[$param]') + ACTUAL_PARAM_VALUE=$(echo "$ACTUAL_PR_PARAMS" | jq -r --arg param "$param" '.[$param]') + + if [[ "$EXPECTED_PARAM_VALUE" != "$ACTUAL_PARAM_VALUE" ]]; then + echo "Mismatch found in pull request parameter '$param':" + echo "Expected: $EXPECTED_PARAM_VALUE" + echo "Actual: $ACTUAL_PARAM_VALUE" + fi + done + + # If the parameters do not match, return false if [[ "$EXPECTED_PR_PARAMS" != "$ACTUAL_PR_PARAMS" ]]; then - echo " Pull request rule parameters mismatch" + echo "Pull request rule parameters mismatch" echo "Expected: $EXPECTED_PR_PARAMS" echo "Actual: $ACTUAL_PR_PARAMS" return 1 fi fi - + + # If rule type or any other rules don't match, return false if [[ "$expected_rule" != "$actual_rule" ]]; then - echo " Rule type mismatch: $rule_type" + echo "Rule type mismatch: $rule_type" echo "Expected: $expected_rule" echo "Actual: $actual_rule" return 1 fi + return 0 - } - + } + + # Set the flag for matching rules MATCHED=true + + # Loop through each expected rule and compare it with the actual rule for expected_rule in $(echo "$EXPECTED_RULES" | jq -c '.[]'); do rule_type=$(echo "$expected_rule" | jq -r '.type') actual_rule=$(echo "$ACTUAL_RULES" | jq -c --arg type "$rule_type" '.[] | select(.type == $type)') - + + # If no matching rule is found in actual rules, indicate missing rule if [[ -z "$actual_rule" ]]; then - echo " Missing expected rule: $rule_type" + echo "Missing expected rule: $rule_type" MATCHED=false continue fi - + + # Compare the expected and actual rule using the compare_rule function if ! compare_rule "$rule_type" "$expected_rule" "$actual_rule"; then MATCHED=false fi done - + + # If there were mismatches, exit with a failure message if [[ "$MATCHED" == false ]]; then - echo " Ruleset mismatch found" + echo "Ruleset mismatch found" exit 1 else - echo " Ruleset matches" + echo "Ruleset matches" fi From 4d5bb8ee994e261ea2d605b7752c11f01bd0c429 Mon Sep 17 00:00:00 2001 From: Adina Rahim Date: Tue, 18 Feb 2025 18:23:49 +0000 Subject: [PATCH 04/17] Update Check Repository Ruleset.yaml --- .github/workflows/Check Repository Ruleset.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Check Repository Ruleset.yaml b/.github/workflows/Check Repository Ruleset.yaml index 143ddcf..8eb01c8 100644 --- a/.github/workflows/Check Repository Ruleset.yaml +++ b/.github/workflows/Check Repository Ruleset.yaml @@ -36,7 +36,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} REPO_NAME: ${{ github.repository }} run: | - DEFAULT_BRANCH="main" + DEFAULT_BRANCH="development" # Fetch default branch dynamically #DEFAULT_BRANCH=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ # -H "Accept: application/vnd.github+json" \ From 8a7ebe789f23d4962739b22618b24eef60ddd3c8 Mon Sep 17 00:00:00 2001 From: Adina Rahim Date: Tue, 18 Feb 2025 18:26:30 +0000 Subject: [PATCH 05/17] correct granular --- .../workflows/Check Repository Ruleset.yaml | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/.github/workflows/Check Repository Ruleset.yaml b/.github/workflows/Check Repository Ruleset.yaml index 8eb01c8..1692116 100644 --- a/.github/workflows/Check Repository Ruleset.yaml +++ b/.github/workflows/Check Repository Ruleset.yaml @@ -74,39 +74,47 @@ jobs: # Load actual and expected rulesets using jq to extract only the necessary fields ACTUAL_RULES=$(jq -c 'map({type, parameters: (if has("parameters") then .parameters else {} end)})' ruleset_response.json) EXPECTED_RULES=$(jq -c 'map({type, parameters: (if has("parameters") then .parameters else {} end)})' expected_ruleset.json) - + echo "Actual Rules: $ACTUAL_RULES" echo "Expected Rules: $EXPECTED_RULES" - + # Check if the fetched rulesets are empty or invalid if [[ -z "$ACTUAL_RULES" || -z "$EXPECTED_RULES" ]]; then echo "Error: One of the rulesets is empty. Check API response." exit 1 fi - + # Function to compare rule parameters dynamically compare_rule() { local rule_type=$1 local expected_rule=$2 local actual_rule=$3 - + # If the rule type is 'pull_request', compare the 'parameters' field if [[ "$rule_type" == "pull_request" ]]; then EXPECTED_PR_PARAMS=$(echo "$expected_rule" | jq -c '(if has("parameters") then .parameters else {} end)') ACTUAL_PR_PARAMS=$(echo "$actual_rule" | jq -c '(if has("parameters") then .parameters else {} end)') - + # Compare each parameter dynamically for param in $(echo "$EXPECTED_PR_PARAMS" | jq -r 'keys[]'); do EXPECTED_PARAM_VALUE=$(echo "$EXPECTED_PR_PARAMS" | jq -r --arg param "$param" '.[$param]') ACTUAL_PARAM_VALUE=$(echo "$ACTUAL_PR_PARAMS" | jq -r --arg param "$param" '.[$param]') - + if [[ "$EXPECTED_PARAM_VALUE" != "$ACTUAL_PARAM_VALUE" ]]; then echo "Mismatch found in pull request parameter '$param':" echo "Expected: $EXPECTED_PARAM_VALUE" echo "Actual: $ACTUAL_PARAM_VALUE" fi done - + + # Check for unexpected parameters in the actual rule + for param in $(echo "$ACTUAL_PR_PARAMS" | jq -r 'keys[]'); do + if [[ "$param" != "required_approving_review_count" && "$param" != "dismiss_stale_reviews_on_push" && "$param" != "require_code_owner_review" && "$param" != "require_last_push_approval" && "$param" != "required_review_thread_resolution" && "$param" != "allowed_merge_methods" ]]; then + echo "Unexpected parameter '$param' found in actual rule:" + echo "Actual: $(echo "$ACTUAL_PR_PARAMS" | jq -r --arg param "$param" '.[$param]')" + fi + done + # If the parameters do not match, return false if [[ "$EXPECTED_PR_PARAMS" != "$ACTUAL_PR_PARAMS" ]]; then echo "Pull request rule parameters mismatch" @@ -115,7 +123,7 @@ jobs: return 1 fi fi - + # If rule type or any other rules don't match, return false if [[ "$expected_rule" != "$actual_rule" ]]; then echo "Rule type mismatch: $rule_type" @@ -123,31 +131,31 @@ jobs: echo "Actual: $actual_rule" return 1 fi - + return 0 } - + # Set the flag for matching rules MATCHED=true - + # Loop through each expected rule and compare it with the actual rule for expected_rule in $(echo "$EXPECTED_RULES" | jq -c '.[]'); do rule_type=$(echo "$expected_rule" | jq -r '.type') actual_rule=$(echo "$ACTUAL_RULES" | jq -c --arg type "$rule_type" '.[] | select(.type == $type)') - + # If no matching rule is found in actual rules, indicate missing rule if [[ -z "$actual_rule" ]]; then echo "Missing expected rule: $rule_type" MATCHED=false continue fi - + # Compare the expected and actual rule using the compare_rule function if ! compare_rule "$rule_type" "$expected_rule" "$actual_rule"; then MATCHED=false fi done - + # If there were mismatches, exit with a failure message if [[ "$MATCHED" == false ]]; then echo "Ruleset mismatch found" From 617b8d04e9aca176e514dbcb6eacb9381ff21f47 Mon Sep 17 00:00:00 2001 From: Adina Rahim Date: Tue, 18 Feb 2025 20:00:05 +0000 Subject: [PATCH 06/17] Update Check Repository Ruleset.yaml --- .github/workflows/Check Repository Ruleset.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Check Repository Ruleset.yaml b/.github/workflows/Check Repository Ruleset.yaml index 1692116..5f34374 100644 --- a/.github/workflows/Check Repository Ruleset.yaml +++ b/.github/workflows/Check Repository Ruleset.yaml @@ -23,7 +23,7 @@ jobs: - name: Load Expected Ruleset run: | EXPECTED_RULESET_FILE=".github/Key Branch Protection Rules.json" - echo "Loading expected ruleset from $EXPECTED_RULESET_FILE..." + echo "Loading expected ruleset from $EXPECTED_RULESET_FILE.." # Extract the "rules" array from the JSON file using jq EXPECTED_RULESET=$(jq '.rules' "$EXPECTED_RULESET_FILE") # Output the extracted rules From c8d2b261b43a88181f8677beb16196d38092549e Mon Sep 17 00:00:00 2001 From: Adina Rahim Date: Tue, 18 Feb 2025 20:01:58 +0000 Subject: [PATCH 07/17] Update Key Branch Protection Rules.json --- .github/Key Branch Protection Rules.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/Key Branch Protection Rules.json b/.github/Key Branch Protection Rules.json index f256fdb..39eae45 100644 --- a/.github/Key Branch Protection Rules.json +++ b/.github/Key Branch Protection Rules.json @@ -32,6 +32,7 @@ "require_code_owner_review": false, "require_last_push_approval": false, "required_review_thread_resolution": true, + "automatic_copilot_code_review_enabled": false, "allowed_merge_methods": [ "merge", "squash", @@ -52,4 +53,4 @@ "bypass_mode": "pull_request" } ] -} \ No newline at end of file +} From d6be458caa0aeac51c7866800050bc0750537250 Mon Sep 17 00:00:00 2001 From: Adina Rahim Date: Tue, 18 Feb 2025 20:04:31 +0000 Subject: [PATCH 08/17] Update Check Repository Ruleset.yaml --- .github/workflows/Check Repository Ruleset.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Check Repository Ruleset.yaml b/.github/workflows/Check Repository Ruleset.yaml index 5f34374..1692116 100644 --- a/.github/workflows/Check Repository Ruleset.yaml +++ b/.github/workflows/Check Repository Ruleset.yaml @@ -23,7 +23,7 @@ jobs: - name: Load Expected Ruleset run: | EXPECTED_RULESET_FILE=".github/Key Branch Protection Rules.json" - echo "Loading expected ruleset from $EXPECTED_RULESET_FILE.." + echo "Loading expected ruleset from $EXPECTED_RULESET_FILE..." # Extract the "rules" array from the JSON file using jq EXPECTED_RULESET=$(jq '.rules' "$EXPECTED_RULESET_FILE") # Output the extracted rules From 98ceb5fa4744822088d365b61f7023c33dec346f Mon Sep 17 00:00:00 2001 From: Adina Rahim Date: Tue, 18 Feb 2025 20:06:38 +0000 Subject: [PATCH 09/17] Update Check Repository Ruleset.yaml --- .github/workflows/Check Repository Ruleset.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Check Repository Ruleset.yaml b/.github/workflows/Check Repository Ruleset.yaml index 1692116..8f293cd 100644 --- a/.github/workflows/Check Repository Ruleset.yaml +++ b/.github/workflows/Check Repository Ruleset.yaml @@ -23,7 +23,7 @@ jobs: - name: Load Expected Ruleset run: | EXPECTED_RULESET_FILE=".github/Key Branch Protection Rules.json" - echo "Loading expected ruleset from $EXPECTED_RULESET_FILE..." + echo "Loading expected ruleset from $EXPECTED_RULESET_FILE." # Extract the "rules" array from the JSON file using jq EXPECTED_RULESET=$(jq '.rules' "$EXPECTED_RULESET_FILE") # Output the extracted rules From f46283b38b34754a56478042cc1033aa5bf8aedf Mon Sep 17 00:00:00 2001 From: Adina Rahim Date: Tue, 18 Feb 2025 20:07:47 +0000 Subject: [PATCH 10/17] Update Check Repository Ruleset.yaml --- .github/workflows/Check Repository Ruleset.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Check Repository Ruleset.yaml b/.github/workflows/Check Repository Ruleset.yaml index 8f293cd..5f34374 100644 --- a/.github/workflows/Check Repository Ruleset.yaml +++ b/.github/workflows/Check Repository Ruleset.yaml @@ -23,7 +23,7 @@ jobs: - name: Load Expected Ruleset run: | EXPECTED_RULESET_FILE=".github/Key Branch Protection Rules.json" - echo "Loading expected ruleset from $EXPECTED_RULESET_FILE." + echo "Loading expected ruleset from $EXPECTED_RULESET_FILE.." # Extract the "rules" array from the JSON file using jq EXPECTED_RULESET=$(jq '.rules' "$EXPECTED_RULESET_FILE") # Output the extracted rules From 8d0b19fce9c316ef5621b376654f6d1085f50e7f Mon Sep 17 00:00:00 2001 From: Adina Rahim Date: Tue, 18 Feb 2025 20:09:25 +0000 Subject: [PATCH 11/17] Update Check Repository Ruleset.yaml --- .github/workflows/Check Repository Ruleset.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Check Repository Ruleset.yaml b/.github/workflows/Check Repository Ruleset.yaml index 5f34374..1692116 100644 --- a/.github/workflows/Check Repository Ruleset.yaml +++ b/.github/workflows/Check Repository Ruleset.yaml @@ -23,7 +23,7 @@ jobs: - name: Load Expected Ruleset run: | EXPECTED_RULESET_FILE=".github/Key Branch Protection Rules.json" - echo "Loading expected ruleset from $EXPECTED_RULESET_FILE.." + echo "Loading expected ruleset from $EXPECTED_RULESET_FILE..." # Extract the "rules" array from the JSON file using jq EXPECTED_RULESET=$(jq '.rules' "$EXPECTED_RULESET_FILE") # Output the extracted rules From 096391d3792c5eb3c98fc9099c56db4472e55388 Mon Sep 17 00:00:00 2001 From: Adina Rahim Date: Tue, 18 Feb 2025 20:11:44 +0000 Subject: [PATCH 12/17] dynamic defult branch name --- .github/workflows/Check Repository Ruleset.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/Check Repository Ruleset.yaml b/.github/workflows/Check Repository Ruleset.yaml index 1692116..4d302aa 100644 --- a/.github/workflows/Check Repository Ruleset.yaml +++ b/.github/workflows/Check Repository Ruleset.yaml @@ -36,13 +36,13 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} REPO_NAME: ${{ github.repository }} run: | - DEFAULT_BRANCH="development" + #DEFAULT_BRANCH="development" # Fetch default branch dynamically - #DEFAULT_BRANCH=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ - # -H "Accept: application/vnd.github+json" \ - # "https://api.github.com/repos/$REPO_NAME" | jq -r '.default_branch') - #echo "Default branch detected: $DEFAULT_BRANCH" - #echo "Fetching ruleset for repository: $REPO_NAME, branch: $DEFAULT_BRANCH..." + DEFAULT_BRANCH=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github+json" \ + "https://api.github.com/repos/$REPO_NAME" | jq -r '.default_branch') + echo "Default branch detected: $DEFAULT_BRANCH" + echo "Fetching ruleset for repository: $REPO_NAME, branch: $DEFAULT_BRANCH..." API_URL="https://api.github.com/repos/$REPO_NAME/rules/branches/$DEFAULT_BRANCH" From d96b46bf56caba1d1e65094bc39ef2e1e0f9f328 Mon Sep 17 00:00:00 2001 From: Adina Rahim Date: Thu, 20 Feb 2025 23:29:20 +0000 Subject: [PATCH 13/17] Update Key Branch Protection Rules.json --- .github/Key Branch Protection Rules.json | 29 +++++++++++++----------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/.github/Key Branch Protection Rules.json b/.github/Key Branch Protection Rules.json index 39eae45..13fb16e 100644 --- a/.github/Key Branch Protection Rules.json +++ b/.github/Key Branch Protection Rules.json @@ -10,10 +10,10 @@ "exclude": [], "include": [ "~DEFAULT_BRANCH", + "refs/heads/dev", "refs/heads/development", "refs/heads/main", - "refs/heads/master", - "refs/heads/dev" + "refs/heads/master" ] } }, @@ -31,25 +31,28 @@ "dismiss_stale_reviews_on_push": true, "require_code_owner_review": false, "require_last_push_approval": false, - "required_review_thread_resolution": true, - "automatic_copilot_code_review_enabled": false, - "allowed_merge_methods": [ - "merge", - "squash", - "rebase" - ] + "required_review_thread_resolution": true + } + }, + { + "type": "branch_name_pattern", + "parameters": { + "operator": "regex", + "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$", + "negate": false, + "name": "Enforces the lower case, dash separated naming convention of branches" } } ], "bypass_actors": [ { - "actor_id": null, - "actor_type": "OrganizationAdmin", + "actor_id": 5, + "actor_type": "RepositoryRole", "bypass_mode": "pull_request" }, { - "actor_id": 5, - "actor_type": "RepositoryRole", + "actor_id": 1, + "actor_type": "OrganizationAdmin", "bypass_mode": "pull_request" } ] From 19de445e0def10ed058f73073c9ff74cf5d41d00 Mon Sep 17 00:00:00 2001 From: Adina Rahim Date: Thu, 20 Feb 2025 23:32:02 +0000 Subject: [PATCH 14/17] Update Key Branch Protection Rules.json --- .github/Key Branch Protection Rules.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/Key Branch Protection Rules.json b/.github/Key Branch Protection Rules.json index 13fb16e..2c4d14e 100644 --- a/.github/Key Branch Protection Rules.json +++ b/.github/Key Branch Protection Rules.json @@ -31,7 +31,8 @@ "dismiss_stale_reviews_on_push": true, "require_code_owner_review": false, "require_last_push_approval": false, - "required_review_thread_resolution": true + "required_review_thread_resolution": true, + "automatic_copilot_code_review_enabled" :false } }, { From 0649cbb1cd4b049f4f8d6f67a4fdcaf96287ee9d Mon Sep 17 00:00:00 2001 From: Adina Rahim Date: Thu, 20 Feb 2025 23:36:44 +0000 Subject: [PATCH 15/17] Update Check Repository Ruleset.yaml --- .github/workflows/Check Repository Ruleset.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Check Repository Ruleset.yaml b/.github/workflows/Check Repository Ruleset.yaml index 4d302aa..d778abf 100644 --- a/.github/workflows/Check Repository Ruleset.yaml +++ b/.github/workflows/Check Repository Ruleset.yaml @@ -69,7 +69,7 @@ jobs: - name: Compare Rulesets run: | - echo "Comparing fetched ruleset with expected ruleset..." + echo "Comparing fetched ruleset with expected ruleset.." # Load actual and expected rulesets using jq to extract only the necessary fields ACTUAL_RULES=$(jq -c 'map({type, parameters: (if has("parameters") then .parameters else {} end)})' ruleset_response.json) From 3bbe8f5315b15356a431073842a834d8f20f8e18 Mon Sep 17 00:00:00 2001 From: Adina Rahim Date: Fri, 21 Feb 2025 14:25:43 +0000 Subject: [PATCH 16/17] Update Check Repository Ruleset.yaml --- .../workflows/Check Repository Ruleset.yaml | 72 ++++++------------- 1 file changed, 23 insertions(+), 49 deletions(-) diff --git a/.github/workflows/Check Repository Ruleset.yaml b/.github/workflows/Check Repository Ruleset.yaml index d778abf..3f7c2d9 100644 --- a/.github/workflows/Check Repository Ruleset.yaml +++ b/.github/workflows/Check Repository Ruleset.yaml @@ -70,8 +70,8 @@ jobs: - name: Compare Rulesets run: | echo "Comparing fetched ruleset with expected ruleset.." - - # Load actual and expected rulesets using jq to extract only the necessary fields + + # Load actual and expected rulesets using jq to extract relevant fields ACTUAL_RULES=$(jq -c 'map({type, parameters: (if has("parameters") then .parameters else {} end)})' ruleset_response.json) EXPECTED_RULES=$(jq -c 'map({type, parameters: (if has("parameters") then .parameters else {} end)})' expected_ruleset.json) @@ -84,79 +84,53 @@ jobs: exit 1 fi - # Function to compare rule parameters dynamically + # Function to compare rules dynamically compare_rule() { - local rule_type=$1 - local expected_rule=$2 - local actual_rule=$3 - - # If the rule type is 'pull_request', compare the 'parameters' field - if [[ "$rule_type" == "pull_request" ]]; then - EXPECTED_PR_PARAMS=$(echo "$expected_rule" | jq -c '(if has("parameters") then .parameters else {} end)') - ACTUAL_PR_PARAMS=$(echo "$actual_rule" | jq -c '(if has("parameters") then .parameters else {} end)') + local expected_rule=$1 + local actual_rule=$2 - # Compare each parameter dynamically - for param in $(echo "$EXPECTED_PR_PARAMS" | jq -r 'keys[]'); do - EXPECTED_PARAM_VALUE=$(echo "$EXPECTED_PR_PARAMS" | jq -r --arg param "$param" '.[$param]') - ACTUAL_PARAM_VALUE=$(echo "$ACTUAL_PR_PARAMS" | jq -r --arg param "$param" '.[$param]') + # Extract and compare parameters if present + EXPECTED_PARAMS=$(echo "$expected_rule" | jq -c '.parameters') + ACTUAL_PARAMS=$(echo "$actual_rule" | jq -c '.parameters') - if [[ "$EXPECTED_PARAM_VALUE" != "$ACTUAL_PARAM_VALUE" ]]; then - echo "Mismatch found in pull request parameter '$param':" - echo "Expected: $EXPECTED_PARAM_VALUE" - echo "Actual: $ACTUAL_PARAM_VALUE" - fi - done + # Check if expected parameters exist in actual; ignore extra parameters + for param in $(echo "$EXPECTED_PARAMS" | jq -r 'keys[]'); do + EXPECTED_VALUE=$(echo "$EXPECTED_PARAMS" | jq -r --arg param "$param" '.[$param]') + ACTUAL_VALUE=$(echo "$ACTUAL_PARAMS" | jq -r --arg param "$param" '.[$param]') - # Check for unexpected parameters in the actual rule - for param in $(echo "$ACTUAL_PR_PARAMS" | jq -r 'keys[]'); do - if [[ "$param" != "required_approving_review_count" && "$param" != "dismiss_stale_reviews_on_push" && "$param" != "require_code_owner_review" && "$param" != "require_last_push_approval" && "$param" != "required_review_thread_resolution" && "$param" != "allowed_merge_methods" ]]; then - echo "Unexpected parameter '$param' found in actual rule:" - echo "Actual: $(echo "$ACTUAL_PR_PARAMS" | jq -r --arg param "$param" '.[$param]')" - fi - done - - # If the parameters do not match, return false - if [[ "$EXPECTED_PR_PARAMS" != "$ACTUAL_PR_PARAMS" ]]; then - echo "Pull request rule parameters mismatch" - echo "Expected: $EXPECTED_PR_PARAMS" - echo "Actual: $ACTUAL_PR_PARAMS" + if [[ "$EXPECTED_VALUE" != "$ACTUAL_VALUE" ]]; then + echo "Mismatch found in parameter '$param':" + echo "Expected: $EXPECTED_VALUE" + echo "Actual: $ACTUAL_VALUE" return 1 fi - fi - - # If rule type or any other rules don't match, return false - if [[ "$expected_rule" != "$actual_rule" ]]; then - echo "Rule type mismatch: $rule_type" - echo "Expected: $expected_rule" - echo "Actual: $actual_rule" - return 1 - fi + done return 0 } - # Set the flag for matching rules + # Set flag for matching rules MATCHED=true - # Loop through each expected rule and compare it with the actual rule + # Loop through each expected rule and compare with actual rules for expected_rule in $(echo "$EXPECTED_RULES" | jq -c '.[]'); do rule_type=$(echo "$expected_rule" | jq -r '.type') actual_rule=$(echo "$ACTUAL_RULES" | jq -c --arg type "$rule_type" '.[] | select(.type == $type)') - # If no matching rule is found in actual rules, indicate missing rule + # If expected rule is missing in actual, report and fail if [[ -z "$actual_rule" ]]; then echo "Missing expected rule: $rule_type" MATCHED=false continue fi - # Compare the expected and actual rule using the compare_rule function - if ! compare_rule "$rule_type" "$expected_rule" "$actual_rule"; then + # Compare expected and actual rule + if ! compare_rule "$expected_rule" "$actual_rule"; then MATCHED=false fi done - # If there were mismatches, exit with a failure message + # Exit with error if mismatches found if [[ "$MATCHED" == false ]]; then echo "Ruleset mismatch found" exit 1 From efb238ab085e9ab5c37fb6123ce47831d43e7c50 Mon Sep 17 00:00:00 2001 From: Adina Rahim Date: Fri, 21 Feb 2025 14:27:57 +0000 Subject: [PATCH 17/17] Update Check Repository Ruleset.yaml --- .../workflows/Check Repository Ruleset.yaml | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/.github/workflows/Check Repository Ruleset.yaml b/.github/workflows/Check Repository Ruleset.yaml index 3f7c2d9..5ca7802 100644 --- a/.github/workflows/Check Repository Ruleset.yaml +++ b/.github/workflows/Check Repository Ruleset.yaml @@ -71,16 +71,16 @@ jobs: run: | echo "Comparing fetched ruleset with expected ruleset.." - # Load actual and expected rulesets using jq to extract relevant fields + # Load actual and expected rulesets using jq ACTUAL_RULES=$(jq -c 'map({type, parameters: (if has("parameters") then .parameters else {} end)})' ruleset_response.json) EXPECTED_RULES=$(jq -c 'map({type, parameters: (if has("parameters") then .parameters else {} end)})' expected_ruleset.json) echo "Actual Rules: $ACTUAL_RULES" echo "Expected Rules: $EXPECTED_RULES" - # Check if the fetched rulesets are empty or invalid - if [[ -z "$ACTUAL_RULES" || -z "$EXPECTED_RULES" ]]; then - echo "Error: One of the rulesets is empty. Check API response." + # Ensure the rules are properly retrieved + if [[ -z "$ACTUAL_RULES" || "$ACTUAL_RULES" == "null" || -z "$EXPECTED_RULES" || "$EXPECTED_RULES" == "null" ]]; then + echo "Error: One of the rulesets is empty or invalid. Check API response." exit 1 fi @@ -89,12 +89,12 @@ jobs: local expected_rule=$1 local actual_rule=$2 - # Extract and compare parameters if present - EXPECTED_PARAMS=$(echo "$expected_rule" | jq -c '.parameters') - ACTUAL_PARAMS=$(echo "$actual_rule" | jq -c '.parameters') + # Extract and compare parameters + EXPECTED_PARAMS=$(echo "$expected_rule" | jq -c '.parameters // {}') + ACTUAL_PARAMS=$(echo "$actual_rule" | jq -c '.parameters // {}') - # Check if expected parameters exist in actual; ignore extra parameters - for param in $(echo "$EXPECTED_PARAMS" | jq -r 'keys[]'); do + # Ensure all expected parameters exist in actual (ignore extra ones) + while read -r param; do EXPECTED_VALUE=$(echo "$EXPECTED_PARAMS" | jq -r --arg param "$param" '.[$param]') ACTUAL_VALUE=$(echo "$ACTUAL_PARAMS" | jq -r --arg param "$param" '.[$param]') @@ -104,36 +104,36 @@ jobs: echo "Actual: $ACTUAL_VALUE" return 1 fi - done + done < <(echo "$EXPECTED_PARAMS" | jq -r 'keys[]') return 0 } - # Set flag for matching rules MATCHED=true - # Loop through each expected rule and compare with actual rules - for expected_rule in $(echo "$EXPECTED_RULES" | jq -c '.[]'); do + # Compare each expected rule against actual rules + while read -r expected_rule; do rule_type=$(echo "$expected_rule" | jq -r '.type') actual_rule=$(echo "$ACTUAL_RULES" | jq -c --arg type "$rule_type" '.[] | select(.type == $type)') - # If expected rule is missing in actual, report and fail if [[ -z "$actual_rule" ]]; then echo "Missing expected rule: $rule_type" MATCHED=false continue fi - # Compare expected and actual rule if ! compare_rule "$expected_rule" "$actual_rule"; then MATCHED=false fi - done + done < <(echo "$EXPECTED_RULES" | jq -c '.[]') - # Exit with error if mismatches found if [[ "$MATCHED" == false ]]; then echo "Ruleset mismatch found" exit 1 else echo "Ruleset matches" fi + + else + echo "Ruleset matches" + fi