From 3656bc65b67c60f133c097ecbf35571c7cfb0ec3 Mon Sep 17 00:00:00 2001 From: Akanshu Aich Date: Mon, 6 Oct 2025 06:49:24 +0000 Subject: [PATCH 1/7] fix: BOMS-235 Create script to set up remotes for devstack --- Makefile | 5 + repo.sh | 307 +++++++++++++++++++++++++++++++++++++++++++++++---- test_repo.sh | 203 ++++++++++++++++++++++++++++++++++ 3 files changed, 495 insertions(+), 20 deletions(-) create mode 100755 test_repo.sh diff --git a/Makefile b/Makefile index 66a9c3d..a8e2ccf 100644 --- a/Makefile +++ b/Makefile @@ -143,13 +143,18 @@ dev.status: ## Prints the status of all git repositories. dev.checkout: ## Check out "openedx-release/$OPENEDX_RELEASE" in each repo if set, use default branch otherwise. ./repo.sh checkout +dev.setup-remotes: ## Set up edx and openedx remotes for all forked repositories. + ./repo.sh setup-remotes + dev.clone: dev.clone.ssh ## Clone service repos to the parent directory. dev.clone.https: ## Clone service repos using HTTPS method to the parent directory. ./repo.sh clone + make dev.setup-remotes dev.clone.ssh: ## Clone service repos using SSH method to the parent directory. ./repo.sh clone_ssh + make dev.setup-remotes ######################################################################################## # Developer interface: Docker image management. diff --git a/repo.sh b/repo.sh index e551aaf..9910fd3 100755 --- a/repo.sh +++ b/repo.sh @@ -26,14 +26,14 @@ repos=( "https://github.com/openedx/cs_comments_service.git" "https://github.com/edx/ecommerce.git" "https://github.com/openedx/edx-notes-api.git" - "https://github.com/openedx/edx-platform.git" + "https://github.com/edx/edx-platform.git" "https://github.com/openedx/xqueue.git" "https://github.com/edx/edx-analytics-dashboard.git" - "https://github.com/openedx/frontend-app-gradebook.git" - "https://github.com/openedx/frontend-app-learner-dashboard.git" - "https://github.com/openedx/frontend-app-learner-record.git" + "https://github.com/edx/frontend-app-gradebook.git" + "https://github.com/edx/frontend-app-learner-dashboard.git" + "https://github.com/edx/frontend-app-learner-record.git" "https://github.com/edx/frontend-app-payment.git" - "https://github.com/openedx/frontend-app-publisher.git" + "https://github.com/edx/frontend-app-publisher.git" "https://github.com/edx/edx-analytics-dashboard.git" "https://github.com/edx/edx-analytics-data-api.git" "https://github.com/openedx/enterprise-catalog.git" @@ -46,17 +46,30 @@ repos=( non_release_repos=( "https://github.com/openedx/frontend-app-authn.git" "https://github.com/openedx/frontend-app-course-authoring.git" - "https://github.com/openedx/frontend-app-learning.git" + "https://github.com/edx/frontend-app-learning.git" "https://github.com/edx/registrar.git" "https://github.com/edx/frontend-app-program-console.git" "https://github.com/openedx/frontend-app-account.git" - "https://github.com/openedx/frontend-app-profile.git" - "https://github.com/openedx/frontend-app-ora-grading.git" + "https://github.com/edx/frontend-app-profile.git" + "https://github.com/edx/frontend-app-ora-grading.git" "https://github.com/openedx/enterprise-subsidy.git" - "https://github.com/openedx/frontend-app-admin-portal.git" - "https://github.com/openedx/frontend-app-learner-portal-enterprise.git" + "https://github.com/edx/frontend-app-admin-portal.git" + "https://github.com/edx/frontend-app-learner-portal-enterprise.git" "https://github.com/edx/frontend-app-enterprise-checkout.git" "https://github.com/edx/edx-exams.git" + "https://github.com/edx/frontend-app-skills.git" + "https://github.com/edx/frontend-app-ora.git" + "https://github.com/edx/frontend-app-exams-dashboard.git" + "https://github.com/edx/frontend-app-learner-portal-programs.git" + "https://github.com/edx/frontend-app-communications.git" + "https://github.com/edx/frontend-app-discussions.git" + "https://github.com/edx/frontend-app-enterprise-api-doc.git" + "https://github.com/edx/frontend-app-enterprise-public-catalog.git" + "https://github.com/edx/frontend-app-support-tools.git" + "https://github.com/edx/frontend-app-authoring.git" + "https://github.com/edx/frontend-app-instruct.git" + "https://github.com/edx/frontend-app-catalog.git" + "https://github.com/edx/openedx-translations.git" ) ssh_repos=( @@ -66,14 +79,14 @@ ssh_repos=( "git@github.com:edx/ecommerce.git" "git@github.com:openedx/edx-notes-api.git" "git@github.com:openedx/enterprise-catalog.git" - "git@github.com:openedx/edx-platform.git" + "git@github.com:edx/edx-platform.git" "git@github.com:openedx/xqueue.git" "git@github.com:edx/edx-analytics-dashboard.git" - "git@github.com:openedx/frontend-app-gradebook.git" - "git@github.com:openedx/frontend-app-learner-dashboard.git" - "git@github.com:openedx/frontend-app-learner-record.git" + "git@github.com:edx/frontend-app-gradebook.git" + "git@github.com:edx/frontend-app-learner-dashboard.git" + "git@github.com:edx/frontend-app-learner-record.git" "git@github.com:edx/frontend-app-payment.git" - "git@github.com:openedx/frontend-app-publisher.git" + "git@github.com:edx/frontend-app-publisher.git" "git@github.com:edx/edx-analytics-dashboard.git" "git@github.com:edx/edx-analytics-data-api.git" "git@github.com:edx/portal-designer.git" @@ -85,17 +98,30 @@ ssh_repos=( non_release_ssh_repos=( "git@github.com:openedx/frontend-app-authn.git" "git@github.com:openedx/frontend-app-course-authoring.git" - "git@github.com:openedx/frontend-app-learning.git" + "git@github.com:edx/frontend-app-learning.git" "git@github.com:edx/registrar.git" "git@github.com:edx/frontend-app-program-console.git" "git@github.com:openedx/frontend-app-account.git" - "git@github.com:openedx/frontend-app-profile.git" - "git@github.com:openedx/frontend-app-ora-grading.git" + "git@github.com:edx/frontend-app-profile.git" + "git@github.com:edx/frontend-app-ora-grading.git" "git@github.com:openedx/enterprise-subsidy.git" - "git@github.com:openedx/frontend-app-admin-portal.git" - "git@github.com:openedx/frontend-app-learner-portal-enterprise.git" + "git@github.com:edx/frontend-app-admin-portal.git" + "git@github.com:edx/frontend-app-learner-portal-enterprise.git" "git@github.com:edx/frontend-app-enterprise-checkout.git" "git@github.com:edx/edx-exams.git" + "git@github.com:edx/frontend-app-skills.git" + "git@github.com:edx/frontend-app-ora.git" + "git@github.com:edx/frontend-app-exams-dashboard.git" + "git@github.com:edx/frontend-app-learner-portal-programs.git" + "git@github.com:edx/frontend-app-communications.git" + "git@github.com:edx/frontend-app-discussions.git" + "git@github.com:edx/frontend-app-enterprise-api-doc.git" + "git@github.com:edx/frontend-app-enterprise-public-catalog.git" + "git@github.com:edx/frontend-app-support-tools.git" + "git@github.com:edx/frontend-app-authoring.git" + "git@github.com:edx/frontend-app-instruct.git" + "git@github.com:edx/frontend-app-catalog.git" + "git@github.com:edx/openedx-translations.git" ) if [ -n "${OPENEDX_RELEASE}" ]; then @@ -287,6 +313,245 @@ status () cd - &> /dev/null } +# Define repositories that exist in both edx and openedx organizations +# These are the ones that need remote setup for forked repositories +declare -A FORKED_REPOS +FORKED_REPOS=( + ["course-discovery"]="openedx" + ["credentials"]="openedx" + ["cs_comments_service"]="openedx" + ["ecommerce"]="edx" + ["edx-notes-api"]="openedx" + ["edx-platform"]="edx" + ["xqueue"]="openedx" + ["edx-analytics-dashboard"]="edx" + ["frontend-app-gradebook"]="edx" + ["frontend-app-learner-dashboard"]="edx" + ["frontend-app-learner-record"]="edx" + ["frontend-app-skills"]="edx" + ["frontend-app-learning"]="edx" + ["frontend-app-ora"]="edx" + ["frontend-app-ora-grading"]="edx" + ["frontend-app-exams-dashboard"]="edx" + ["frontend-app-learner-portal-programs"]="edx" + ["frontend-app-program-console"]="edx" + ["frontend-app-communications"]="edx" + ["frontend-app-discussions"]="edx" + ["frontend-app-profile"]="edx" + ["frontend-app-enterprise-api-doc"]="edx" + ["frontend-app-enterprise-public-catalog"]="edx" + ["frontend-app-publisher"]="edx" + ["frontend-app-support-tools"]="edx" + ["frontend-app-admin-portal"]="edx" + ["frontend-app-learner-portal-enterprise"]="edx" + ["frontend-app-enterprise-checkout"]="edx" + ["frontend-app-authoring"]="edx" + ["frontend-app-instruct"]="edx" + ["frontend-app-catalog"]="edx" + ["openedx-translations"]="edx" + ["frontend-app-payment"]="edx" + ["edx-analytics-data-api"]="edx" + ["enterprise-catalog"]="openedx" + ["portal-designer"]="edx" + ["license-manager"]="openedx" + ["codejail-service"]="openedx" + ["enterprise-access"]="openedx" + ["frontend-app-authn"]="openedx" + ["frontend-app-course-authoring"]="openedx" + ["registrar"]="edx" + ["frontend-app-account"]="openedx" + ["enterprise-subsidy"]="openedx" + ["edx-exams"]="edx" +) + +setup_forked_repo_remotes () +{ + local repo_name=$1 + local expected_primary_org=${FORKED_REPOS[$repo_name]} + + if [ -z "$expected_primary_org" ]; then + echo "Repository $repo_name is not configured as a forked repo. Skipping remote setup." + return 0 + fi + + echo "Setting up remotes for forked repository: $repo_name" + + # Check if we're in a git repository + if [ ! -d ".git" ]; then + echo "ERROR: $repo_name is not a git repository" + return 1 + fi + + # Check if both remotes already exist (idempotency check) + local edx_remote_exists + local openedx_remote_exists + local origin_exists + edx_remote_exists=$(git remote | grep "^edx$" || true) + openedx_remote_exists=$(git remote | grep "^openedx$" || true) + origin_exists=$(git remote | grep "^origin$" || true) + + if [ -n "$edx_remote_exists" ] && [ -n "$openedx_remote_exists" ] && [ -z "$origin_exists" ]; then + echo "Both edx and openedx remotes already exist in $repo_name. No changes needed." + return 0 + fi + + # Determine the origin URL and organization + local origin_url="" + local origin_org="" + + # Try to get origin URL first + origin_url=$(git remote get-url origin 2>/dev/null || true) + + if [ -n "$origin_url" ]; then + # Origin exists, determine its organization + if [[ $origin_url =~ github\.com[:/]edx/ ]]; then + origin_org="edx" + elif [[ $origin_url =~ github\.com[:/]openedx/ ]]; then + origin_org="openedx" + else + echo "ERROR: Unexpected origin URL in $repo_name: $origin_url" + echo "Expected URL to be from either edx or openedx organization" + return 1 + fi + + # Rename origin to the correct organization name if not already done + if [ -z "$(git remote | grep "^${origin_org}$")" ]; then + echo "Renaming origin to '$origin_org' in $repo_name" + git remote rename origin "$origin_org" + if [ $? -ne 0 ]; then + echo "ERROR: Failed to rename origin to $origin_org in $repo_name" + return 1 + fi + else + echo "Remote '$origin_org' already exists, removing origin" + git remote remove origin 2>/dev/null || true + fi + else + # No origin, check if either edx or openedx remote exists to determine URL format + if [ -n "$edx_remote_exists" ]; then + origin_url=$(git remote get-url edx) + origin_org="edx" + elif [ -n "$openedx_remote_exists" ]; then + origin_url=$(git remote get-url openedx) + origin_org="openedx" + else + echo "ERROR: No origin remote and no edx/openedx remotes found in $repo_name" + return 1 + fi + fi + + # Determine the other organization and add its remote if missing + local other_org + if [ "$origin_org" = "edx" ]; then + other_org="openedx" + else + other_org="edx" + fi + + # Check if the other remote exists + local other_remote_exists + other_remote_exists=$(git remote | grep "^${other_org}$" || true) + + if [ -z "$other_remote_exists" ]; then + # Construct the URL for the other organization + local other_url + if [[ $origin_url =~ ^git@ ]]; then + # SSH URL format + other_url="git@github.com:${other_org}/${repo_name}.git" + else + # HTTPS URL format + other_url="https://github.com/${other_org}/${repo_name}.git" + fi + + echo "Adding $other_org remote: $other_url" + git remote add "$other_org" "$other_url" + if [ $? -ne 0 ]; then + echo "ERROR: Failed to add $other_org remote in $repo_name" + return 1 + fi + else + echo "Remote '$other_org' already exists in $repo_name" + fi + + echo "Successfully configured remotes for $repo_name" + return 0 +} + +setup_all_forked_repo_remotes () +{ + local successful_repos=() + local failed_repos=() + local skipped_repos=() + + echo "Setting up remotes for all forked repositories..." + echo "========================================" + + for repo in "${repos[@]}" "${non_release_repos[@]}" + do + # Extract repo name from URL + if [[ ! $repo =~ $name_pattern ]]; then + echo "Cannot setup remotes for repo; URL did not match expected pattern: $repo" + continue + fi + local name="${BASH_REMATCH[1]}" + + # Check if directory exists + if [ ! -d "$name" ]; then + echo "Repository $name is not cloned. Skipping." + skipped_repos+=("$name") + continue + fi + + # Check if this repo is configured as a forked repo + if [ -z "${FORKED_REPOS[$name]}" ]; then + echo "Repository $name is not configured as a forked repo. Skipping." + skipped_repos+=("$name") + continue + fi + + # Change to repo directory and setup remotes + cd "$name" + if setup_forked_repo_remotes "$name"; then + successful_repos+=("$name") + else + failed_repos+=("$name") + fi + cd "$DEVSTACK_WORKSPACE" + echo "" + done + + # Print summary report + echo "========================================" + echo "Remote Setup Summary:" + echo "========================================" + + if [ ${#successful_repos[@]} -gt 0 ]; then + echo "✓ Successfully configured remotes for ${#successful_repos[@]} repositories:" + printf " - %s\n" "${successful_repos[@]}" + echo "" + fi + + if [ ${#failed_repos[@]} -gt 0 ]; then + echo "✗ Failed to configure remotes for ${#failed_repos[@]} repositories:" + printf " - %s\n" "${failed_repos[@]}" + echo "" + fi + + if [ ${#skipped_repos[@]} -gt 0 ]; then + echo "◦ Skipped ${#skipped_repos[@]} repositories (not cloned or not forked):" + printf " - %s\n" "${skipped_repos[@]}" + echo "" + fi + + echo "Total repositories processed: $((${#successful_repos[@]} + ${#failed_repos[@]} + ${#skipped_repos[@]}))" + + if [ ${#failed_repos[@]} -gt 0 ]; then + return 1 + else + return 0 + fi +} + if [ "$1" == "checkout" ]; then checkout elif [ "$1" == "clone" ]; then @@ -297,4 +562,6 @@ elif [ "$1" == "reset" ]; then reset elif [ "$1" == "status" ]; then status +elif [ "$1" == "setup-remotes" ]; then + setup_all_forked_repo_remotes fi diff --git a/test_repo.sh b/test_repo.sh new file mode 100755 index 0000000..af259aa --- /dev/null +++ b/test_repo.sh @@ -0,0 +1,203 @@ +#!/bin/bash + +TEST_WORKSPACE="/tmp/devstack_test_$$" +mkdir -p "$TEST_WORKSPACE" + +GREEN='\033[0;32m' +RED='\033[0;31m' +BLUE='\033[0;34m' +NC='\033[0m' + +# Test tracking variables +TOTAL_TESTS=0 +PASSED_TESTS=0 +FAILED_TESTS=0 +TEST_RESULTS=() + +print_pass() { + echo -e "${GREEN}PASS${NC}: $1" + PASSED_TESTS=$((PASSED_TESTS + 1)) + TEST_RESULTS+=("PASS: $1") +} + +print_fail() { + echo -e "${RED}FAIL${NC}: $1" + FAILED_TESTS=$((FAILED_TESTS + 1)) + TEST_RESULTS+=("FAIL: $1") +} + +show_remotes() { + local repo_name=$1 + local label=$2 + echo " $label - $repo_name:" + if [ -d "$repo_name" ]; then + cd "$repo_name" + git remote -v | sed 's/^/ /' + cd .. + fi +} + +create_test_repo() { + local repo_name=$1 + local origin_url=$2 + mkdir -p "$repo_name" + cd "$repo_name" + git init -q + git remote add origin "$origin_url" + git config user.email "test@example.com" + git config user.name "Test User" + echo "# $repo_name" > README.md + git add README.md + git commit -q -m "Initial commit" + cd .. +} + +echo "TEST 1: EDX Origin Repository" +TOTAL_TESTS=$((TOTAL_TESTS + 1)) +cd "$TEST_WORKSPACE" +create_test_repo "ecommerce" "https://github.com/edx/ecommerce.git" +show_remotes "ecommerce" "BEFORE" +cd /workspaces/devstack +echo " Output:" +DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes +cd "$TEST_WORKSPACE" +show_remotes "ecommerce" "AFTER" +cd ecommerce +if git remote | grep -q "edx" && git remote | grep -q "openedx" && ! git remote | grep -q "origin"; then + print_pass "EDX origin handling" +else + print_fail "EDX origin handling" +fi +cd .. + +echo +echo "TEST 2: EDX Origin Repository (edx-platform)" +TOTAL_TESTS=$((TOTAL_TESTS + 1)) +create_test_repo "edx-platform" "https://github.com/edx/edx-platform.git" +show_remotes "edx-platform" "BEFORE" +cd /workspaces/devstack +echo " Output:" +DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes +cd "$TEST_WORKSPACE" +show_remotes "edx-platform" "AFTER" +cd edx-platform +if git remote | grep -q "openedx" && git remote | grep -q "edx" && ! git remote | grep -q "origin"; then + print_pass "EDX origin handling (edx-platform)" +else + print_fail "EDX origin handling (edx-platform)" +fi +cd .. + +echo +echo "TEST 3: OpenEDX Origin Repository (course-discovery)" +TOTAL_TESTS=$((TOTAL_TESTS + 1)) +create_test_repo "course-discovery" "https://github.com/openedx/course-discovery.git" +show_remotes "course-discovery" "BEFORE" +cd /workspaces/devstack +echo " Output:" +DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes +cd "$TEST_WORKSPACE" +show_remotes "course-discovery" "AFTER" +cd course-discovery +if git remote | grep -q "openedx" && git remote | grep -q "edx" && ! git remote | grep -q "origin"; then + print_pass "OpenEDX origin handling (course-discovery)" +else + print_fail "OpenEDX origin handling (course-discovery)" +fi +cd .. + +echo +echo "TEST 4: Personal Fork Error" +TOTAL_TESTS=$((TOTAL_TESTS + 1)) +create_test_repo "credentials" "https://github.com/personaluser/credentials.git" +show_remotes "credentials" "BEFORE" +cd /workspaces/devstack +echo " Output:" +DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes +cd "$TEST_WORKSPACE" +show_remotes "credentials" "AFTER" +cd credentials +if git remote get-url origin | grep -q "personaluser"; then + print_pass "Personal fork error detection" +else + print_fail "Personal fork error detection" +fi +cd .. + +echo +echo "TEST 5: Non-Forked Repository" +TOTAL_TESTS=$((TOTAL_TESTS + 1)) +create_test_repo "unknown-repo" "https://github.com/edx/unknown-repo.git" +show_remotes "unknown-repo" "BEFORE" +cd /workspaces/devstack +echo " Output:" +DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes +cd "$TEST_WORKSPACE" +show_remotes "unknown-repo" "AFTER" +cd unknown-repo +if git remote | grep -q "^origin$" && [ $(git remote | wc -l) -eq 1 ]; then + print_pass "Non-forked repository handling" +else + print_fail "Non-forked repository handling" +fi +cd .. + +echo +echo "TEST 6: Idempotent Operations" +TOTAL_TESTS=$((TOTAL_TESTS + 1)) +create_test_repo "ecommerce" "https://github.com/edx/ecommerce.git" +show_remotes "ecommerce" "BEFORE (fresh repo)" +cd /workspaces/devstack +echo " First run output:" +DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes +cd "$TEST_WORKSPACE" +show_remotes "ecommerce" "AFTER FIRST RUN" +cd /workspaces/devstack +echo " Second run output (should be idempotent):" +DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes +cd "$TEST_WORKSPACE" +show_remotes "ecommerce" "AFTER SECOND RUN (should be identical)" +cd ecommerce +if [ $(git remote | wc -l) -eq 2 ] && git remote | grep -q "edx" && git remote | grep -q "openedx"; then + print_pass "Idempotent operations" +else + print_fail "Idempotent operations" +fi +cd .. + +echo +echo "TEST 7: Make Integration" +TOTAL_TESTS=$((TOTAL_TESTS + 1)) +cd /workspaces/devstack +if make -n dev.setup-remotes >/dev/null 2>&1 && make help | grep -q "dev.setup-remotes"; then + print_pass "Make command integration" +else + print_fail "Make command integration" +fi + +rm -rf "$TEST_WORKSPACE" + +echo +echo "======================================================================" +echo -e "${BLUE}TEST SUMMARY${NC}" +echo "======================================================================" +echo "Total Test Cases: $TOTAL_TESTS" +echo -e "Passed: ${GREEN}$PASSED_TESTS${NC}" +echo -e "Failed: ${RED}$FAILED_TESTS${NC}" +echo +echo "Test Results:" +for result in "${TEST_RESULTS[@]}"; do + if [[ $result == PASS:* ]]; then + echo -e " ${GREEN}${result}${NC}" + else + echo -e " ${RED}${result}${NC}" + fi +done +echo +if [ $FAILED_TESTS -eq 0 ]; then + echo -e "${GREEN}All tests passed successfully!${NC}" + exit 0 +else + echo -e "${RED}$FAILED_TESTS test(s) failed.${NC}" + exit 1 +fi From e6d904c8c51b8fa786578e6f6beb8f1863effd6e Mon Sep 17 00:00:00 2001 From: Akanshu Aich Date: Mon, 6 Oct 2025 07:23:28 +0000 Subject: [PATCH 2/7] fix: corrected the github urls for repos --- repo.sh | 5 ----- test_repo.sh | 21 +++++++++++---------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/repo.sh b/repo.sh index 9910fd3..3940e2c 100755 --- a/repo.sh +++ b/repo.sh @@ -34,7 +34,6 @@ repos=( "https://github.com/edx/frontend-app-learner-record.git" "https://github.com/edx/frontend-app-payment.git" "https://github.com/edx/frontend-app-publisher.git" - "https://github.com/edx/edx-analytics-dashboard.git" "https://github.com/edx/edx-analytics-data-api.git" "https://github.com/openedx/enterprise-catalog.git" "https://github.com/edx/portal-designer.git" @@ -63,7 +62,6 @@ non_release_repos=( "https://github.com/edx/frontend-app-learner-portal-programs.git" "https://github.com/edx/frontend-app-communications.git" "https://github.com/edx/frontend-app-discussions.git" - "https://github.com/edx/frontend-app-enterprise-api-doc.git" "https://github.com/edx/frontend-app-enterprise-public-catalog.git" "https://github.com/edx/frontend-app-support-tools.git" "https://github.com/edx/frontend-app-authoring.git" @@ -87,7 +85,6 @@ ssh_repos=( "git@github.com:edx/frontend-app-learner-record.git" "git@github.com:edx/frontend-app-payment.git" "git@github.com:edx/frontend-app-publisher.git" - "git@github.com:edx/edx-analytics-dashboard.git" "git@github.com:edx/edx-analytics-data-api.git" "git@github.com:edx/portal-designer.git" "git@github.com:openedx/license-manager.git" @@ -115,7 +112,6 @@ non_release_ssh_repos=( "git@github.com:edx/frontend-app-learner-portal-programs.git" "git@github.com:edx/frontend-app-communications.git" "git@github.com:edx/frontend-app-discussions.git" - "git@github.com:edx/frontend-app-enterprise-api-doc.git" "git@github.com:edx/frontend-app-enterprise-public-catalog.git" "git@github.com:edx/frontend-app-support-tools.git" "git@github.com:edx/frontend-app-authoring.git" @@ -338,7 +334,6 @@ FORKED_REPOS=( ["frontend-app-communications"]="edx" ["frontend-app-discussions"]="edx" ["frontend-app-profile"]="edx" - ["frontend-app-enterprise-api-doc"]="edx" ["frontend-app-enterprise-public-catalog"]="edx" ["frontend-app-publisher"]="edx" ["frontend-app-support-tools"]="edx" diff --git a/test_repo.sh b/test_repo.sh index af259aa..7744ece 100755 --- a/test_repo.sh +++ b/test_repo.sh @@ -55,14 +55,14 @@ create_test_repo() { echo "TEST 1: EDX Origin Repository" TOTAL_TESTS=$((TOTAL_TESTS + 1)) cd "$TEST_WORKSPACE" -create_test_repo "ecommerce" "https://github.com/edx/ecommerce.git" -show_remotes "ecommerce" "BEFORE" +create_test_repo "frontend-app-gradebook" "https://github.com/edx/frontend-app-gradebook.git" +show_remotes "frontend-app-gradebook" "BEFORE" cd /workspaces/devstack echo " Output:" DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes cd "$TEST_WORKSPACE" -show_remotes "ecommerce" "AFTER" -cd ecommerce +show_remotes "frontend-app-gradebook" "AFTER" +cd frontend-app-gradebook if git remote | grep -q "edx" && git remote | grep -q "openedx" && ! git remote | grep -q "origin"; then print_pass "EDX origin handling" else @@ -99,7 +99,8 @@ DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes cd "$TEST_WORKSPACE" show_remotes "course-discovery" "AFTER" cd course-discovery -if git remote | grep -q "openedx" && git remote | grep -q "edx" && ! git remote | grep -q "origin"; then +# course-discovery should be renamed from origin to openedx, and get an edx remote +if git remote get-url openedx | grep -q "openedx/course-discovery" && git remote get-url edx | grep -q "edx/course-discovery" && [ $(git remote | wc -l) -eq 2 ]; then print_pass "OpenEDX origin handling (course-discovery)" else print_fail "OpenEDX origin handling (course-discovery)" @@ -145,19 +146,19 @@ cd .. echo echo "TEST 6: Idempotent Operations" TOTAL_TESTS=$((TOTAL_TESTS + 1)) -create_test_repo "ecommerce" "https://github.com/edx/ecommerce.git" -show_remotes "ecommerce" "BEFORE (fresh repo)" +create_test_repo "frontend-app-gradebook" "https://github.com/edx/frontend-app-gradebook.git" +show_remotes "frontend-app-gradebook" "BEFORE (fresh repo)" cd /workspaces/devstack echo " First run output:" DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes cd "$TEST_WORKSPACE" -show_remotes "ecommerce" "AFTER FIRST RUN" +show_remotes "frontend-app-gradebook" "AFTER FIRST RUN" cd /workspaces/devstack echo " Second run output (should be idempotent):" DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes cd "$TEST_WORKSPACE" -show_remotes "ecommerce" "AFTER SECOND RUN (should be identical)" -cd ecommerce +show_remotes "frontend-app-gradebook" "AFTER SECOND RUN (should be identical)" +cd frontend-app-gradebook if [ $(git remote | wc -l) -eq 2 ] && git remote | grep -q "edx" && git remote | grep -q "openedx"; then print_pass "Idempotent operations" else From c9adf61c5e27abcd95f6a57d6f6736d56f02a1fd Mon Sep 17 00:00:00 2001 From: Akanshu-2u Date: Fri, 10 Oct 2025 11:18:37 +0000 Subject: [PATCH 3/7] fix: added variables to top and removed dupliation of code --- repo.sh | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/repo.sh b/repo.sh index 3940e2c..8d96950 100755 --- a/repo.sh +++ b/repo.sh @@ -361,15 +361,17 @@ FORKED_REPOS=( setup_forked_repo_remotes () { + # Declare all local variables at the top local repo_name=$1 local expected_primary_org=${FORKED_REPOS[$repo_name]} - - if [ -z "$expected_primary_org" ]; then - echo "Repository $repo_name is not configured as a forked repo. Skipping remote setup." - return 0 - fi - - echo "Setting up remotes for forked repository: $repo_name" + local edx_remote_exists + local openedx_remote_exists + local origin_exists + local origin_url="" + local origin_org="" + local other_org + local other_remote_exists + local other_url # Check if we're in a git repository if [ ! -d ".git" ]; then @@ -378,9 +380,6 @@ setup_forked_repo_remotes () fi # Check if both remotes already exist (idempotency check) - local edx_remote_exists - local openedx_remote_exists - local origin_exists edx_remote_exists=$(git remote | grep "^edx$" || true) openedx_remote_exists=$(git remote | grep "^openedx$" || true) origin_exists=$(git remote | grep "^origin$" || true) @@ -390,9 +389,7 @@ setup_forked_repo_remotes () return 0 fi - # Determine the origin URL and organization - local origin_url="" - local origin_org="" + echo "Setting up remotes for forked repository: $repo_name" # Try to get origin URL first origin_url=$(git remote get-url origin 2>/dev/null || true) @@ -436,7 +433,6 @@ setup_forked_repo_remotes () fi # Determine the other organization and add its remote if missing - local other_org if [ "$origin_org" = "edx" ]; then other_org="openedx" else @@ -444,12 +440,10 @@ setup_forked_repo_remotes () fi # Check if the other remote exists - local other_remote_exists other_remote_exists=$(git remote | grep "^${other_org}$" || true) if [ -z "$other_remote_exists" ]; then # Construct the URL for the other organization - local other_url if [[ $origin_url =~ ^git@ ]]; then # SSH URL format other_url="git@github.com:${other_org}/${repo_name}.git" @@ -474,9 +468,12 @@ setup_forked_repo_remotes () setup_all_forked_repo_remotes () { + # Declare all local variables at the top local successful_repos=() local failed_repos=() local skipped_repos=() + local repo + local name echo "Setting up remotes for all forked repositories..." echo "========================================" @@ -488,7 +485,7 @@ setup_all_forked_repo_remotes () echo "Cannot setup remotes for repo; URL did not match expected pattern: $repo" continue fi - local name="${BASH_REMATCH[1]}" + name="${BASH_REMATCH[1]}" # Check if directory exists if [ ! -d "$name" ]; then From 4f28bffade3c4017d95f62e3f1f6b8865571c1fd Mon Sep 17 00:00:00 2001 From: Akanshu-2u Date: Fri, 10 Oct 2025 11:27:49 +0000 Subject: [PATCH 4/7] fix: removed unwanted comments --- repo.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/repo.sh b/repo.sh index 8d96950..58bc1dd 100755 --- a/repo.sh +++ b/repo.sh @@ -361,7 +361,6 @@ FORKED_REPOS=( setup_forked_repo_remotes () { - # Declare all local variables at the top local repo_name=$1 local expected_primary_org=${FORKED_REPOS[$repo_name]} local edx_remote_exists @@ -468,7 +467,6 @@ setup_forked_repo_remotes () setup_all_forked_repo_remotes () { - # Declare all local variables at the top local successful_repos=() local failed_repos=() local skipped_repos=() From 24e33373788cdb54504f7ed24bf274526240b51a Mon Sep 17 00:00:00 2001 From: Akanshu-2u Date: Wed, 15 Oct 2025 11:24:49 +0000 Subject: [PATCH 5/7] fix: fixed repo.sh using shellcheck and added test in CI check --- .github/workflows/cli-tests.yml | 5 + repo.sh | 209 ++++++++++++++++---------------- tests/test_repo.sh | 204 +++++++++++++++++++++++++++++++ 3 files changed, 316 insertions(+), 102 deletions(-) create mode 100755 tests/test_repo.sh diff --git a/.github/workflows/cli-tests.yml b/.github/workflows/cli-tests.yml index 07b6811..171b955 100644 --- a/.github/workflows/cli-tests.yml +++ b/.github/workflows/cli-tests.yml @@ -70,3 +70,8 @@ jobs: - name: CLI tests run: pytest -s ./tests/*.py + + - name: Repo setup-remotes tests + run: | + chmod +x ./tests/test_repo.sh + ./tests/test_repo.sh diff --git a/repo.sh b/repo.sh index 58bc1dd..3fccc10 100755 --- a/repo.sh +++ b/repo.sh @@ -311,156 +311,151 @@ status () # Define repositories that exist in both edx and openedx organizations # These are the ones that need remote setup for forked repositories -declare -A FORKED_REPOS FORKED_REPOS=( - ["course-discovery"]="openedx" - ["credentials"]="openedx" - ["cs_comments_service"]="openedx" - ["ecommerce"]="edx" - ["edx-notes-api"]="openedx" - ["edx-platform"]="edx" - ["xqueue"]="openedx" - ["edx-analytics-dashboard"]="edx" - ["frontend-app-gradebook"]="edx" - ["frontend-app-learner-dashboard"]="edx" - ["frontend-app-learner-record"]="edx" - ["frontend-app-skills"]="edx" - ["frontend-app-learning"]="edx" - ["frontend-app-ora"]="edx" - ["frontend-app-ora-grading"]="edx" - ["frontend-app-exams-dashboard"]="edx" - ["frontend-app-learner-portal-programs"]="edx" - ["frontend-app-program-console"]="edx" - ["frontend-app-communications"]="edx" - ["frontend-app-discussions"]="edx" - ["frontend-app-profile"]="edx" - ["frontend-app-enterprise-public-catalog"]="edx" - ["frontend-app-publisher"]="edx" - ["frontend-app-support-tools"]="edx" - ["frontend-app-admin-portal"]="edx" - ["frontend-app-learner-portal-enterprise"]="edx" - ["frontend-app-enterprise-checkout"]="edx" - ["frontend-app-authoring"]="edx" - ["frontend-app-instruct"]="edx" - ["frontend-app-catalog"]="edx" - ["openedx-translations"]="edx" - ["frontend-app-payment"]="edx" - ["edx-analytics-data-api"]="edx" - ["enterprise-catalog"]="openedx" - ["portal-designer"]="edx" - ["license-manager"]="openedx" - ["codejail-service"]="openedx" - ["enterprise-access"]="openedx" - ["frontend-app-authn"]="openedx" - ["frontend-app-course-authoring"]="openedx" - ["registrar"]="edx" - ["frontend-app-account"]="openedx" - ["enterprise-subsidy"]="openedx" - ["edx-exams"]="edx" + "course-discovery" + "credentials" + "cs_comments_service" + "ecommerce" + "edx-notes-api" + "edx-platform" + "xqueue" + "edx-analytics-dashboard" + "frontend-app-gradebook" + "frontend-app-learner-dashboard" + "frontend-app-learner-record" + "frontend-app-skills" + "frontend-app-learning" + "frontend-app-ora" + "frontend-app-ora-grading" + "frontend-app-exams-dashboard" + "frontend-app-learner-portal-programs" + "frontend-app-program-console" + "frontend-app-communications" + "frontend-app-discussions" + "frontend-app-profile" + "frontend-app-enterprise-public-catalog" + "frontend-app-publisher" + "frontend-app-support-tools" + "frontend-app-admin-portal" + "frontend-app-learner-portal-enterprise" + "frontend-app-enterprise-checkout" + "frontend-app-authoring" + "frontend-app-instruct" + "frontend-app-catalog" + "openedx-translations" + "frontend-app-payment" + "edx-analytics-data-api" + "enterprise-catalog" + "portal-designer" + "license-manager" + "codejail-service" + "enterprise-access" + "frontend-app-authn" + "frontend-app-course-authoring" + "registrar" + "frontend-app-account" + "enterprise-subsidy" + "edx-exams" ) setup_forked_repo_remotes () { local repo_name=$1 - local expected_primary_org=${FORKED_REPOS[$repo_name]} local edx_remote_exists local openedx_remote_exists local origin_exists - local origin_url="" - local origin_org="" + local existing_url="" + local existing_org="" local other_org local other_remote_exists local other_url - + # Check if we're in a git repository if [ ! -d ".git" ]; then echo "ERROR: $repo_name is not a git repository" return 1 fi - + # Check if both remotes already exist (idempotency check) edx_remote_exists=$(git remote | grep "^edx$" || true) openedx_remote_exists=$(git remote | grep "^openedx$" || true) origin_exists=$(git remote | grep "^origin$" || true) - + if [ -n "$edx_remote_exists" ] && [ -n "$openedx_remote_exists" ] && [ -z "$origin_exists" ]; then echo "Both edx and openedx remotes already exist in $repo_name. No changes needed." return 0 fi - + echo "Setting up remotes for forked repository: $repo_name" - - # Try to get origin URL first - origin_url=$(git remote get-url origin 2>/dev/null || true) - - if [ -n "$origin_url" ]; then - # Origin exists, determine its organization - if [[ $origin_url =~ github\.com[:/]edx/ ]]; then - origin_org="edx" - elif [[ $origin_url =~ github\.com[:/]openedx/ ]]; then - origin_org="openedx" + + # First, try to find an existing remote and its URL + if [ -n "$origin_exists" ]; then + # We have an 'origin' remote - determine its organization + existing_url=$(git remote get-url origin 2>/dev/null || true) + + if [[ $existing_url =~ github\.com[:/]edx/ ]]; then + existing_org="edx" + elif [[ $existing_url =~ github\.com[:/]openedx/ ]]; then + existing_org="openedx" else - echo "ERROR: Unexpected origin URL in $repo_name: $origin_url" + echo "ERROR: Unexpected origin URL in $repo_name: $existing_url" echo "Expected URL to be from either edx or openedx organization" return 1 fi - + # Rename origin to the correct organization name if not already done - if [ -z "$(git remote | grep "^${origin_org}$")" ]; then - echo "Renaming origin to '$origin_org' in $repo_name" - git remote rename origin "$origin_org" - if [ $? -ne 0 ]; then - echo "ERROR: Failed to rename origin to $origin_org in $repo_name" + if ! git remote | grep -q "^${existing_org}$"; then + echo "Renaming origin to '$existing_org' in $repo_name" + if ! git remote rename origin "$existing_org"; then + echo "ERROR: Failed to rename origin to $existing_org in $repo_name" return 1 fi else - echo "Remote '$origin_org' already exists, removing origin" + echo "Remote '$existing_org' already exists, removing origin" git remote remove origin 2>/dev/null || true fi + elif [ -n "$edx_remote_exists" ]; then + # No origin, but we have an 'edx' remote - use it as reference + existing_url=$(git remote get-url edx) + existing_org="edx" + elif [ -n "$openedx_remote_exists" ]; then + # No origin or edx, but we have an 'openedx' remote - use it as reference + existing_url=$(git remote get-url openedx) + existing_org="openedx" else - # No origin, check if either edx or openedx remote exists to determine URL format - if [ -n "$edx_remote_exists" ]; then - origin_url=$(git remote get-url edx) - origin_org="edx" - elif [ -n "$openedx_remote_exists" ]; then - origin_url=$(git remote get-url openedx) - origin_org="openedx" - else - echo "ERROR: No origin remote and no edx/openedx remotes found in $repo_name" - return 1 - fi + echo "ERROR: No remotes found in $repo_name" + return 1 fi - + # Determine the other organization and add its remote if missing - if [ "$origin_org" = "edx" ]; then + if [ "$existing_org" = "edx" ]; then other_org="openedx" else other_org="edx" fi - + # Check if the other remote exists other_remote_exists=$(git remote | grep "^${other_org}$" || true) - + if [ -z "$other_remote_exists" ]; then # Construct the URL for the other organization - if [[ $origin_url =~ ^git@ ]]; then + if [[ $existing_url =~ ^git@ ]]; then # SSH URL format other_url="git@github.com:${other_org}/${repo_name}.git" else # HTTPS URL format other_url="https://github.com/${other_org}/${repo_name}.git" fi - + echo "Adding $other_org remote: $other_url" - git remote add "$other_org" "$other_url" - if [ $? -ne 0 ]; then + if ! git remote add "$other_org" "$other_url"; then echo "ERROR: Failed to add $other_org remote in $repo_name" return 1 fi else echo "Remote '$other_org' already exists in $repo_name" fi - + echo "Successfully configured remotes for $repo_name" return 0 } @@ -472,10 +467,12 @@ setup_all_forked_repo_remotes () local skipped_repos=() local repo local name - + local is_forked + local forked_repo + echo "Setting up remotes for all forked repositories..." echo "========================================" - + for repo in "${repos[@]}" "${non_release_repos[@]}" do # Extract repo name from URL @@ -484,21 +481,29 @@ setup_all_forked_repo_remotes () continue fi name="${BASH_REMATCH[1]}" - + # Check if directory exists if [ ! -d "$name" ]; then echo "Repository $name is not cloned. Skipping." skipped_repos+=("$name") continue fi - + # Check if this repo is configured as a forked repo - if [ -z "${FORKED_REPOS[$name]}" ]; then + is_forked=false + for forked_repo in "${FORKED_REPOS[@]}"; do + if [[ "$forked_repo" == "$name" ]]; then + is_forked=true + break + fi + done + + if [[ "$is_forked" == false ]]; then echo "Repository $name is not configured as a forked repo. Skipping." skipped_repos+=("$name") continue fi - + # Change to repo directory and setup remotes cd "$name" if setup_forked_repo_remotes "$name"; then @@ -509,32 +514,32 @@ setup_all_forked_repo_remotes () cd "$DEVSTACK_WORKSPACE" echo "" done - + # Print summary report echo "========================================" echo "Remote Setup Summary:" echo "========================================" - + if [ ${#successful_repos[@]} -gt 0 ]; then echo "✓ Successfully configured remotes for ${#successful_repos[@]} repositories:" printf " - %s\n" "${successful_repos[@]}" echo "" fi - + if [ ${#failed_repos[@]} -gt 0 ]; then echo "✗ Failed to configure remotes for ${#failed_repos[@]} repositories:" printf " - %s\n" "${failed_repos[@]}" echo "" fi - + if [ ${#skipped_repos[@]} -gt 0 ]; then echo "◦ Skipped ${#skipped_repos[@]} repositories (not cloned or not forked):" printf " - %s\n" "${skipped_repos[@]}" echo "" fi - + echo "Total repositories processed: $((${#successful_repos[@]} + ${#failed_repos[@]} + ${#skipped_repos[@]}))" - + if [ ${#failed_repos[@]} -gt 0 ]; then return 1 else diff --git a/tests/test_repo.sh b/tests/test_repo.sh new file mode 100755 index 0000000..9ab9adf --- /dev/null +++ b/tests/test_repo.sh @@ -0,0 +1,204 @@ +#!/bin/bash + +TEST_WORKSPACE="/tmp/devstack_test_$$" +mkdir -p "$TEST_WORKSPACE" + +GREEN='\033[0;32m' +RED='\033[0;31m' +BLUE='\033[0;34m' +NC='\033[0m' + +# Test tracking variables +TOTAL_TESTS=0 +PASSED_TESTS=0 +FAILED_TESTS=0 +TEST_RESULTS=() + +print_pass() { + echo -e "${GREEN}PASS${NC}: $1" + PASSED_TESTS=$((PASSED_TESTS + 1)) + TEST_RESULTS+=("PASS: $1") +} + +print_fail() { + echo -e "${RED}FAIL${NC}: $1" + FAILED_TESTS=$((FAILED_TESTS + 1)) + TEST_RESULTS+=("FAIL: $1") +} + +show_remotes() { + local repo_name=$1 + local label=$2 + echo " $label - $repo_name:" + if [ -d "$repo_name" ]; then + cd "$repo_name" + git remote -v | sed 's/^/ /' + cd .. + fi +} + +create_test_repo() { + local repo_name=$1 + local origin_url=$2 + mkdir -p "$repo_name" + cd "$repo_name" + git init -q + git remote add origin "$origin_url" + git config user.email "test@example.com" + git config user.name "Test User" + echo "# $repo_name" > README.md + git add README.md + git commit -q -m "Initial commit" + cd .. +} + +echo "TEST 1: EDX Origin Repository" +TOTAL_TESTS=$((TOTAL_TESTS + 1)) +cd "$TEST_WORKSPACE" +create_test_repo "frontend-app-gradebook" "https://github.com/edx/frontend-app-gradebook.git" +show_remotes "frontend-app-gradebook" "BEFORE" +cd /workspaces/devstack +echo " Output:" +DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes +cd "$TEST_WORKSPACE" +show_remotes "frontend-app-gradebook" "AFTER" +cd frontend-app-gradebook +if git remote | grep -q "edx" && git remote | grep -q "openedx" && ! git remote | grep -q "origin"; then + print_pass "EDX origin handling" +else + print_fail "EDX origin handling" +fi +cd .. + +echo +echo "TEST 2: EDX Origin Repository (edx-platform)" +TOTAL_TESTS=$((TOTAL_TESTS + 1)) +create_test_repo "edx-platform" "https://github.com/edx/edx-platform.git" +show_remotes "edx-platform" "BEFORE" +cd /workspaces/devstack +echo " Output:" +DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes +cd "$TEST_WORKSPACE" +show_remotes "edx-platform" "AFTER" +cd edx-platform +if git remote | grep -q "openedx" && git remote | grep -q "edx" && ! git remote | grep -q "origin"; then + print_pass "EDX origin handling (edx-platform)" +else + print_fail "EDX origin handling (edx-platform)" +fi +cd .. + +echo +echo "TEST 3: OpenEDX Origin Repository (course-discovery)" +TOTAL_TESTS=$((TOTAL_TESTS + 1)) +create_test_repo "course-discovery" "https://github.com/openedx/course-discovery.git" +show_remotes "course-discovery" "BEFORE" +cd /workspaces/devstack +echo " Output:" +DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes +cd "$TEST_WORKSPACE" +show_remotes "course-discovery" "AFTER" +cd course-discovery +# course-discovery should be renamed from origin to openedx, and get an edx remote +if git remote get-url openedx | grep -q "openedx/course-discovery" && git remote get-url edx | grep -q "edx/course-discovery" && [ $(git remote | wc -l) -eq 2 ]; then + print_pass "OpenEDX origin handling (course-discovery)" +else + print_fail "OpenEDX origin handling (course-discovery)" +fi +cd .. + +echo +echo "TEST 4: Personal Fork Error" +TOTAL_TESTS=$((TOTAL_TESTS + 1)) +create_test_repo "credentials" "https://github.com/personaluser/credentials.git" +show_remotes "credentials" "BEFORE" +cd /workspaces/devstack +echo " Output:" +DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes +cd "$TEST_WORKSPACE" +show_remotes "credentials" "AFTER" +cd credentials +if git remote get-url origin | grep -q "personaluser"; then + print_pass "Personal fork error detection" +else + print_fail "Personal fork error detection" +fi +cd .. + +echo +echo "TEST 5: Non-Forked Repository" +TOTAL_TESTS=$((TOTAL_TESTS + 1)) +create_test_repo "unknown-repo" "https://github.com/edx/unknown-repo.git" +show_remotes "unknown-repo" "BEFORE" +cd /workspaces/devstack +echo " Output:" +DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes +cd "$TEST_WORKSPACE" +show_remotes "unknown-repo" "AFTER" +cd unknown-repo +if git remote | grep -q "^origin$" && [ $(git remote | wc -l) -eq 1 ]; then + print_pass "Non-forked repository handling" +else + print_fail "Non-forked repository handling" +fi +cd .. + +echo +echo "TEST 6: Idempotent Operations" +TOTAL_TESTS=$((TOTAL_TESTS + 1)) +create_test_repo "frontend-app-gradebook" "https://github.com/edx/frontend-app-gradebook.git" +show_remotes "frontend-app-gradebook" "BEFORE (fresh repo)" +cd /workspaces/devstack +echo " First run output:" +DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes +cd "$TEST_WORKSPACE" +show_remotes "frontend-app-gradebook" "AFTER FIRST RUN" +cd /workspaces/devstack +echo " Second run output (should be idempotent):" +DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes +cd "$TEST_WORKSPACE" +show_remotes "frontend-app-gradebook" "AFTER SECOND RUN (should be identical)" +cd frontend-app-gradebook +if [ $(git remote | wc -l) -eq 2 ] && git remote | grep -q "edx" && git remote | grep -q "openedx"; then + print_pass "Idempotent operations" +else + print_fail "Idempotent operations" +fi +cd .. + +echo +echo "TEST 7: Make Integration" +TOTAL_TESTS=$((TOTAL_TESTS + 1)) +cd /workspaces/devstack +if make -n dev.setup-remotes >/dev/null 2>&1 && make help | grep -q "dev.setup-remotes"; then + print_pass "Make command integration" +else + print_fail "Make command integration" +fi + +rm -rf "$TEST_WORKSPACE" + +echo +echo "======================================================================" +echo -e "${BLUE}TEST SUMMARY${NC}" +echo "======================================================================" +echo "Total Test Cases: $TOTAL_TESTS" +echo -e "Passed: ${GREEN}$PASSED_TESTS${NC}" +echo -e "Failed: ${RED}$FAILED_TESTS${NC}" +echo +echo "Test Results:" +for result in "${TEST_RESULTS[@]}"; do + if [[ $result == PASS:* ]]; then + echo -e " ${GREEN}${result}${NC}" + else + echo -e " ${RED}${result}${NC}" + fi +done +echo +if [ $FAILED_TESTS -eq 0 ]; then + echo -e "${GREEN}All tests passed successfully!${NC}" + exit 0 +else + echo -e "${RED}$FAILED_TESTS test(s) failed.${NC}" + exit 1 +fi From 8567fa8e14a05206af3a2aaf0c528f7219ca1056 Mon Sep 17 00:00:00 2001 From: Akanshu-2u Date: Wed, 15 Oct 2025 11:27:10 +0000 Subject: [PATCH 6/7] fix: removed test_repo as its already in tests --- test_repo.sh | 204 --------------------------------------------------- 1 file changed, 204 deletions(-) delete mode 100755 test_repo.sh diff --git a/test_repo.sh b/test_repo.sh deleted file mode 100755 index 7744ece..0000000 --- a/test_repo.sh +++ /dev/null @@ -1,204 +0,0 @@ -#!/bin/bash - -TEST_WORKSPACE="/tmp/devstack_test_$$" -mkdir -p "$TEST_WORKSPACE" - -GREEN='\033[0;32m' -RED='\033[0;31m' -BLUE='\033[0;34m' -NC='\033[0m' - -# Test tracking variables -TOTAL_TESTS=0 -PASSED_TESTS=0 -FAILED_TESTS=0 -TEST_RESULTS=() - -print_pass() { - echo -e "${GREEN}PASS${NC}: $1" - PASSED_TESTS=$((PASSED_TESTS + 1)) - TEST_RESULTS+=("PASS: $1") -} - -print_fail() { - echo -e "${RED}FAIL${NC}: $1" - FAILED_TESTS=$((FAILED_TESTS + 1)) - TEST_RESULTS+=("FAIL: $1") -} - -show_remotes() { - local repo_name=$1 - local label=$2 - echo " $label - $repo_name:" - if [ -d "$repo_name" ]; then - cd "$repo_name" - git remote -v | sed 's/^/ /' - cd .. - fi -} - -create_test_repo() { - local repo_name=$1 - local origin_url=$2 - mkdir -p "$repo_name" - cd "$repo_name" - git init -q - git remote add origin "$origin_url" - git config user.email "test@example.com" - git config user.name "Test User" - echo "# $repo_name" > README.md - git add README.md - git commit -q -m "Initial commit" - cd .. -} - -echo "TEST 1: EDX Origin Repository" -TOTAL_TESTS=$((TOTAL_TESTS + 1)) -cd "$TEST_WORKSPACE" -create_test_repo "frontend-app-gradebook" "https://github.com/edx/frontend-app-gradebook.git" -show_remotes "frontend-app-gradebook" "BEFORE" -cd /workspaces/devstack -echo " Output:" -DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes -cd "$TEST_WORKSPACE" -show_remotes "frontend-app-gradebook" "AFTER" -cd frontend-app-gradebook -if git remote | grep -q "edx" && git remote | grep -q "openedx" && ! git remote | grep -q "origin"; then - print_pass "EDX origin handling" -else - print_fail "EDX origin handling" -fi -cd .. - -echo -echo "TEST 2: EDX Origin Repository (edx-platform)" -TOTAL_TESTS=$((TOTAL_TESTS + 1)) -create_test_repo "edx-platform" "https://github.com/edx/edx-platform.git" -show_remotes "edx-platform" "BEFORE" -cd /workspaces/devstack -echo " Output:" -DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes -cd "$TEST_WORKSPACE" -show_remotes "edx-platform" "AFTER" -cd edx-platform -if git remote | grep -q "openedx" && git remote | grep -q "edx" && ! git remote | grep -q "origin"; then - print_pass "EDX origin handling (edx-platform)" -else - print_fail "EDX origin handling (edx-platform)" -fi -cd .. - -echo -echo "TEST 3: OpenEDX Origin Repository (course-discovery)" -TOTAL_TESTS=$((TOTAL_TESTS + 1)) -create_test_repo "course-discovery" "https://github.com/openedx/course-discovery.git" -show_remotes "course-discovery" "BEFORE" -cd /workspaces/devstack -echo " Output:" -DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes -cd "$TEST_WORKSPACE" -show_remotes "course-discovery" "AFTER" -cd course-discovery -# course-discovery should be renamed from origin to openedx, and get an edx remote -if git remote get-url openedx | grep -q "openedx/course-discovery" && git remote get-url edx | grep -q "edx/course-discovery" && [ $(git remote | wc -l) -eq 2 ]; then - print_pass "OpenEDX origin handling (course-discovery)" -else - print_fail "OpenEDX origin handling (course-discovery)" -fi -cd .. - -echo -echo "TEST 4: Personal Fork Error" -TOTAL_TESTS=$((TOTAL_TESTS + 1)) -create_test_repo "credentials" "https://github.com/personaluser/credentials.git" -show_remotes "credentials" "BEFORE" -cd /workspaces/devstack -echo " Output:" -DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes -cd "$TEST_WORKSPACE" -show_remotes "credentials" "AFTER" -cd credentials -if git remote get-url origin | grep -q "personaluser"; then - print_pass "Personal fork error detection" -else - print_fail "Personal fork error detection" -fi -cd .. - -echo -echo "TEST 5: Non-Forked Repository" -TOTAL_TESTS=$((TOTAL_TESTS + 1)) -create_test_repo "unknown-repo" "https://github.com/edx/unknown-repo.git" -show_remotes "unknown-repo" "BEFORE" -cd /workspaces/devstack -echo " Output:" -DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes -cd "$TEST_WORKSPACE" -show_remotes "unknown-repo" "AFTER" -cd unknown-repo -if git remote | grep -q "^origin$" && [ $(git remote | wc -l) -eq 1 ]; then - print_pass "Non-forked repository handling" -else - print_fail "Non-forked repository handling" -fi -cd .. - -echo -echo "TEST 6: Idempotent Operations" -TOTAL_TESTS=$((TOTAL_TESTS + 1)) -create_test_repo "frontend-app-gradebook" "https://github.com/edx/frontend-app-gradebook.git" -show_remotes "frontend-app-gradebook" "BEFORE (fresh repo)" -cd /workspaces/devstack -echo " First run output:" -DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes -cd "$TEST_WORKSPACE" -show_remotes "frontend-app-gradebook" "AFTER FIRST RUN" -cd /workspaces/devstack -echo " Second run output (should be idempotent):" -DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes -cd "$TEST_WORKSPACE" -show_remotes "frontend-app-gradebook" "AFTER SECOND RUN (should be identical)" -cd frontend-app-gradebook -if [ $(git remote | wc -l) -eq 2 ] && git remote | grep -q "edx" && git remote | grep -q "openedx"; then - print_pass "Idempotent operations" -else - print_fail "Idempotent operations" -fi -cd .. - -echo -echo "TEST 7: Make Integration" -TOTAL_TESTS=$((TOTAL_TESTS + 1)) -cd /workspaces/devstack -if make -n dev.setup-remotes >/dev/null 2>&1 && make help | grep -q "dev.setup-remotes"; then - print_pass "Make command integration" -else - print_fail "Make command integration" -fi - -rm -rf "$TEST_WORKSPACE" - -echo -echo "======================================================================" -echo -e "${BLUE}TEST SUMMARY${NC}" -echo "======================================================================" -echo "Total Test Cases: $TOTAL_TESTS" -echo -e "Passed: ${GREEN}$PASSED_TESTS${NC}" -echo -e "Failed: ${RED}$FAILED_TESTS${NC}" -echo -echo "Test Results:" -for result in "${TEST_RESULTS[@]}"; do - if [[ $result == PASS:* ]]; then - echo -e " ${GREEN}${result}${NC}" - else - echo -e " ${RED}${result}${NC}" - fi -done -echo -if [ $FAILED_TESTS -eq 0 ]; then - echo -e "${GREEN}All tests passed successfully!${NC}" - exit 0 -else - echo -e "${RED}$FAILED_TESTS test(s) failed.${NC}" - exit 1 -fi From 5935957eccbde904fab844d7dd555fd85730d774 Mon Sep 17 00:00:00 2001 From: Akanshu-2u Date: Wed, 15 Oct 2025 11:35:57 +0000 Subject: [PATCH 7/7] fix: modified test file according to CI configurations --- tests/test_repo.sh | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/test_repo.sh b/tests/test_repo.sh index 9ab9adf..1956e80 100755 --- a/tests/test_repo.sh +++ b/tests/test_repo.sh @@ -1,5 +1,9 @@ #!/bin/bash +# Determine the script's directory and devstack root +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +DEVSTACK_ROOT="$( cd "$SCRIPT_DIR/.." && pwd )" + TEST_WORKSPACE="/tmp/devstack_test_$$" mkdir -p "$TEST_WORKSPACE" @@ -57,7 +61,7 @@ TOTAL_TESTS=$((TOTAL_TESTS + 1)) cd "$TEST_WORKSPACE" create_test_repo "frontend-app-gradebook" "https://github.com/edx/frontend-app-gradebook.git" show_remotes "frontend-app-gradebook" "BEFORE" -cd /workspaces/devstack +cd "$DEVSTACK_ROOT" echo " Output:" DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes cd "$TEST_WORKSPACE" @@ -75,7 +79,7 @@ echo "TEST 2: EDX Origin Repository (edx-platform)" TOTAL_TESTS=$((TOTAL_TESTS + 1)) create_test_repo "edx-platform" "https://github.com/edx/edx-platform.git" show_remotes "edx-platform" "BEFORE" -cd /workspaces/devstack +cd "$DEVSTACK_ROOT" echo " Output:" DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes cd "$TEST_WORKSPACE" @@ -93,7 +97,7 @@ echo "TEST 3: OpenEDX Origin Repository (course-discovery)" TOTAL_TESTS=$((TOTAL_TESTS + 1)) create_test_repo "course-discovery" "https://github.com/openedx/course-discovery.git" show_remotes "course-discovery" "BEFORE" -cd /workspaces/devstack +cd "$DEVSTACK_ROOT" echo " Output:" DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes cd "$TEST_WORKSPACE" @@ -112,7 +116,7 @@ echo "TEST 4: Personal Fork Error" TOTAL_TESTS=$((TOTAL_TESTS + 1)) create_test_repo "credentials" "https://github.com/personaluser/credentials.git" show_remotes "credentials" "BEFORE" -cd /workspaces/devstack +cd "$DEVSTACK_ROOT" echo " Output:" DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes cd "$TEST_WORKSPACE" @@ -130,7 +134,7 @@ echo "TEST 5: Non-Forked Repository" TOTAL_TESTS=$((TOTAL_TESTS + 1)) create_test_repo "unknown-repo" "https://github.com/edx/unknown-repo.git" show_remotes "unknown-repo" "BEFORE" -cd /workspaces/devstack +cd "$DEVSTACK_ROOT" echo " Output:" DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes cd "$TEST_WORKSPACE" @@ -148,12 +152,12 @@ echo "TEST 6: Idempotent Operations" TOTAL_TESTS=$((TOTAL_TESTS + 1)) create_test_repo "frontend-app-gradebook" "https://github.com/edx/frontend-app-gradebook.git" show_remotes "frontend-app-gradebook" "BEFORE (fresh repo)" -cd /workspaces/devstack +cd "$DEVSTACK_ROOT" echo " First run output:" DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes cd "$TEST_WORKSPACE" show_remotes "frontend-app-gradebook" "AFTER FIRST RUN" -cd /workspaces/devstack +cd "$DEVSTACK_ROOT" echo " Second run output (should be idempotent):" DEVSTACK_WORKSPACE="$TEST_WORKSPACE" make dev.setup-remotes cd "$TEST_WORKSPACE" @@ -169,7 +173,7 @@ cd .. echo echo "TEST 7: Make Integration" TOTAL_TESTS=$((TOTAL_TESTS + 1)) -cd /workspaces/devstack +cd "$DEVSTACK_ROOT" if make -n dev.setup-remotes >/dev/null 2>&1 && make help | grep -q "dev.setup-remotes"; then print_pass "Make command integration" else