Skip to content

Commit 3656bc6

Browse files
committed
fix: BOMS-235 Create script to set up remotes for devstack
1 parent a5c0837 commit 3656bc6

File tree

3 files changed

+495
-20
lines changed

3 files changed

+495
-20
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,18 @@ dev.status: ## Prints the status of all git repositories.
143143
dev.checkout: ## Check out "openedx-release/$OPENEDX_RELEASE" in each repo if set, use default branch otherwise.
144144
./repo.sh checkout
145145

146+
dev.setup-remotes: ## Set up edx and openedx remotes for all forked repositories.
147+
./repo.sh setup-remotes
148+
146149
dev.clone: dev.clone.ssh ## Clone service repos to the parent directory.
147150

148151
dev.clone.https: ## Clone service repos using HTTPS method to the parent directory.
149152
./repo.sh clone
153+
make dev.setup-remotes
150154

151155
dev.clone.ssh: ## Clone service repos using SSH method to the parent directory.
152156
./repo.sh clone_ssh
157+
make dev.setup-remotes
153158

154159
########################################################################################
155160
# Developer interface: Docker image management.

repo.sh

Lines changed: 287 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ repos=(
2626
"https://github.com/openedx/cs_comments_service.git"
2727
"https://github.com/edx/ecommerce.git"
2828
"https://github.com/openedx/edx-notes-api.git"
29-
"https://github.com/openedx/edx-platform.git"
29+
"https://github.com/edx/edx-platform.git"
3030
"https://github.com/openedx/xqueue.git"
3131
"https://github.com/edx/edx-analytics-dashboard.git"
32-
"https://github.com/openedx/frontend-app-gradebook.git"
33-
"https://github.com/openedx/frontend-app-learner-dashboard.git"
34-
"https://github.com/openedx/frontend-app-learner-record.git"
32+
"https://github.com/edx/frontend-app-gradebook.git"
33+
"https://github.com/edx/frontend-app-learner-dashboard.git"
34+
"https://github.com/edx/frontend-app-learner-record.git"
3535
"https://github.com/edx/frontend-app-payment.git"
36-
"https://github.com/openedx/frontend-app-publisher.git"
36+
"https://github.com/edx/frontend-app-publisher.git"
3737
"https://github.com/edx/edx-analytics-dashboard.git"
3838
"https://github.com/edx/edx-analytics-data-api.git"
3939
"https://github.com/openedx/enterprise-catalog.git"
@@ -46,17 +46,30 @@ repos=(
4646
non_release_repos=(
4747
"https://github.com/openedx/frontend-app-authn.git"
4848
"https://github.com/openedx/frontend-app-course-authoring.git"
49-
"https://github.com/openedx/frontend-app-learning.git"
49+
"https://github.com/edx/frontend-app-learning.git"
5050
"https://github.com/edx/registrar.git"
5151
"https://github.com/edx/frontend-app-program-console.git"
5252
"https://github.com/openedx/frontend-app-account.git"
53-
"https://github.com/openedx/frontend-app-profile.git"
54-
"https://github.com/openedx/frontend-app-ora-grading.git"
53+
"https://github.com/edx/frontend-app-profile.git"
54+
"https://github.com/edx/frontend-app-ora-grading.git"
5555
"https://github.com/openedx/enterprise-subsidy.git"
56-
"https://github.com/openedx/frontend-app-admin-portal.git"
57-
"https://github.com/openedx/frontend-app-learner-portal-enterprise.git"
56+
"https://github.com/edx/frontend-app-admin-portal.git"
57+
"https://github.com/edx/frontend-app-learner-portal-enterprise.git"
5858
"https://github.com/edx/frontend-app-enterprise-checkout.git"
5959
"https://github.com/edx/edx-exams.git"
60+
"https://github.com/edx/frontend-app-skills.git"
61+
"https://github.com/edx/frontend-app-ora.git"
62+
"https://github.com/edx/frontend-app-exams-dashboard.git"
63+
"https://github.com/edx/frontend-app-learner-portal-programs.git"
64+
"https://github.com/edx/frontend-app-communications.git"
65+
"https://github.com/edx/frontend-app-discussions.git"
66+
"https://github.com/edx/frontend-app-enterprise-api-doc.git"
67+
"https://github.com/edx/frontend-app-enterprise-public-catalog.git"
68+
"https://github.com/edx/frontend-app-support-tools.git"
69+
"https://github.com/edx/frontend-app-authoring.git"
70+
"https://github.com/edx/frontend-app-instruct.git"
71+
"https://github.com/edx/frontend-app-catalog.git"
72+
"https://github.com/edx/openedx-translations.git"
6073
)
6174

6275
ssh_repos=(
@@ -66,14 +79,14 @@ ssh_repos=(
6679
"[email protected]:edx/ecommerce.git"
6780
"[email protected]:openedx/edx-notes-api.git"
6881
"[email protected]:openedx/enterprise-catalog.git"
69-
"[email protected]:openedx/edx-platform.git"
82+
"[email protected]:edx/edx-platform.git"
7083
"[email protected]:openedx/xqueue.git"
7184
"[email protected]:edx/edx-analytics-dashboard.git"
72-
"[email protected]:openedx/frontend-app-gradebook.git"
73-
"[email protected]:openedx/frontend-app-learner-dashboard.git"
74-
"[email protected]:openedx/frontend-app-learner-record.git"
85+
"[email protected]:edx/frontend-app-gradebook.git"
86+
"[email protected]:edx/frontend-app-learner-dashboard.git"
87+
"[email protected]:edx/frontend-app-learner-record.git"
7588
"[email protected]:edx/frontend-app-payment.git"
76-
"[email protected]:openedx/frontend-app-publisher.git"
89+
"[email protected]:edx/frontend-app-publisher.git"
7790
"[email protected]:edx/edx-analytics-dashboard.git"
7891
"[email protected]:edx/edx-analytics-data-api.git"
7992
"[email protected]:edx/portal-designer.git"
@@ -85,17 +98,30 @@ ssh_repos=(
8598
non_release_ssh_repos=(
8699
"[email protected]:openedx/frontend-app-authn.git"
87100
"[email protected]:openedx/frontend-app-course-authoring.git"
88-
"[email protected]:openedx/frontend-app-learning.git"
101+
"[email protected]:edx/frontend-app-learning.git"
89102
"[email protected]:edx/registrar.git"
90103
"[email protected]:edx/frontend-app-program-console.git"
91104
"[email protected]:openedx/frontend-app-account.git"
92-
"[email protected]:openedx/frontend-app-profile.git"
93-
"[email protected]:openedx/frontend-app-ora-grading.git"
105+
"[email protected]:edx/frontend-app-profile.git"
106+
"[email protected]:edx/frontend-app-ora-grading.git"
94107
"[email protected]:openedx/enterprise-subsidy.git"
95-
"[email protected]:openedx/frontend-app-admin-portal.git"
96-
"[email protected]:openedx/frontend-app-learner-portal-enterprise.git"
108+
"[email protected]:edx/frontend-app-admin-portal.git"
109+
"[email protected]:edx/frontend-app-learner-portal-enterprise.git"
97110
"[email protected]:edx/frontend-app-enterprise-checkout.git"
98111
"[email protected]:edx/edx-exams.git"
112+
"[email protected]:edx/frontend-app-skills.git"
113+
"[email protected]:edx/frontend-app-ora.git"
114+
"[email protected]:edx/frontend-app-exams-dashboard.git"
115+
"[email protected]:edx/frontend-app-learner-portal-programs.git"
116+
"[email protected]:edx/frontend-app-communications.git"
117+
"[email protected]:edx/frontend-app-discussions.git"
118+
"[email protected]:edx/frontend-app-enterprise-api-doc.git"
119+
"[email protected]:edx/frontend-app-enterprise-public-catalog.git"
120+
"[email protected]:edx/frontend-app-support-tools.git"
121+
"[email protected]:edx/frontend-app-authoring.git"
122+
"[email protected]:edx/frontend-app-instruct.git"
123+
"[email protected]:edx/frontend-app-catalog.git"
124+
"[email protected]:edx/openedx-translations.git"
99125
)
100126

101127
if [ -n "${OPENEDX_RELEASE}" ]; then
@@ -287,6 +313,245 @@ status ()
287313
cd - &> /dev/null
288314
}
289315

316+
# Define repositories that exist in both edx and openedx organizations
317+
# These are the ones that need remote setup for forked repositories
318+
declare -A FORKED_REPOS
319+
FORKED_REPOS=(
320+
["course-discovery"]="openedx"
321+
["credentials"]="openedx"
322+
["cs_comments_service"]="openedx"
323+
["ecommerce"]="edx"
324+
["edx-notes-api"]="openedx"
325+
["edx-platform"]="edx"
326+
["xqueue"]="openedx"
327+
["edx-analytics-dashboard"]="edx"
328+
["frontend-app-gradebook"]="edx"
329+
["frontend-app-learner-dashboard"]="edx"
330+
["frontend-app-learner-record"]="edx"
331+
["frontend-app-skills"]="edx"
332+
["frontend-app-learning"]="edx"
333+
["frontend-app-ora"]="edx"
334+
["frontend-app-ora-grading"]="edx"
335+
["frontend-app-exams-dashboard"]="edx"
336+
["frontend-app-learner-portal-programs"]="edx"
337+
["frontend-app-program-console"]="edx"
338+
["frontend-app-communications"]="edx"
339+
["frontend-app-discussions"]="edx"
340+
["frontend-app-profile"]="edx"
341+
["frontend-app-enterprise-api-doc"]="edx"
342+
["frontend-app-enterprise-public-catalog"]="edx"
343+
["frontend-app-publisher"]="edx"
344+
["frontend-app-support-tools"]="edx"
345+
["frontend-app-admin-portal"]="edx"
346+
["frontend-app-learner-portal-enterprise"]="edx"
347+
["frontend-app-enterprise-checkout"]="edx"
348+
["frontend-app-authoring"]="edx"
349+
["frontend-app-instruct"]="edx"
350+
["frontend-app-catalog"]="edx"
351+
["openedx-translations"]="edx"
352+
["frontend-app-payment"]="edx"
353+
["edx-analytics-data-api"]="edx"
354+
["enterprise-catalog"]="openedx"
355+
["portal-designer"]="edx"
356+
["license-manager"]="openedx"
357+
["codejail-service"]="openedx"
358+
["enterprise-access"]="openedx"
359+
["frontend-app-authn"]="openedx"
360+
["frontend-app-course-authoring"]="openedx"
361+
["registrar"]="edx"
362+
["frontend-app-account"]="openedx"
363+
["enterprise-subsidy"]="openedx"
364+
["edx-exams"]="edx"
365+
)
366+
367+
setup_forked_repo_remotes ()
368+
{
369+
local repo_name=$1
370+
local expected_primary_org=${FORKED_REPOS[$repo_name]}
371+
372+
if [ -z "$expected_primary_org" ]; then
373+
echo "Repository $repo_name is not configured as a forked repo. Skipping remote setup."
374+
return 0
375+
fi
376+
377+
echo "Setting up remotes for forked repository: $repo_name"
378+
379+
# Check if we're in a git repository
380+
if [ ! -d ".git" ]; then
381+
echo "ERROR: $repo_name is not a git repository"
382+
return 1
383+
fi
384+
385+
# Check if both remotes already exist (idempotency check)
386+
local edx_remote_exists
387+
local openedx_remote_exists
388+
local origin_exists
389+
edx_remote_exists=$(git remote | grep "^edx$" || true)
390+
openedx_remote_exists=$(git remote | grep "^openedx$" || true)
391+
origin_exists=$(git remote | grep "^origin$" || true)
392+
393+
if [ -n "$edx_remote_exists" ] && [ -n "$openedx_remote_exists" ] && [ -z "$origin_exists" ]; then
394+
echo "Both edx and openedx remotes already exist in $repo_name. No changes needed."
395+
return 0
396+
fi
397+
398+
# Determine the origin URL and organization
399+
local origin_url=""
400+
local origin_org=""
401+
402+
# Try to get origin URL first
403+
origin_url=$(git remote get-url origin 2>/dev/null || true)
404+
405+
if [ -n "$origin_url" ]; then
406+
# Origin exists, determine its organization
407+
if [[ $origin_url =~ github\.com[:/]edx/ ]]; then
408+
origin_org="edx"
409+
elif [[ $origin_url =~ github\.com[:/]openedx/ ]]; then
410+
origin_org="openedx"
411+
else
412+
echo "ERROR: Unexpected origin URL in $repo_name: $origin_url"
413+
echo "Expected URL to be from either edx or openedx organization"
414+
return 1
415+
fi
416+
417+
# Rename origin to the correct organization name if not already done
418+
if [ -z "$(git remote | grep "^${origin_org}$")" ]; then
419+
echo "Renaming origin to '$origin_org' in $repo_name"
420+
git remote rename origin "$origin_org"
421+
if [ $? -ne 0 ]; then
422+
echo "ERROR: Failed to rename origin to $origin_org in $repo_name"
423+
return 1
424+
fi
425+
else
426+
echo "Remote '$origin_org' already exists, removing origin"
427+
git remote remove origin 2>/dev/null || true
428+
fi
429+
else
430+
# No origin, check if either edx or openedx remote exists to determine URL format
431+
if [ -n "$edx_remote_exists" ]; then
432+
origin_url=$(git remote get-url edx)
433+
origin_org="edx"
434+
elif [ -n "$openedx_remote_exists" ]; then
435+
origin_url=$(git remote get-url openedx)
436+
origin_org="openedx"
437+
else
438+
echo "ERROR: No origin remote and no edx/openedx remotes found in $repo_name"
439+
return 1
440+
fi
441+
fi
442+
443+
# Determine the other organization and add its remote if missing
444+
local other_org
445+
if [ "$origin_org" = "edx" ]; then
446+
other_org="openedx"
447+
else
448+
other_org="edx"
449+
fi
450+
451+
# Check if the other remote exists
452+
local other_remote_exists
453+
other_remote_exists=$(git remote | grep "^${other_org}$" || true)
454+
455+
if [ -z "$other_remote_exists" ]; then
456+
# Construct the URL for the other organization
457+
local other_url
458+
if [[ $origin_url =~ ^git@ ]]; then
459+
# SSH URL format
460+
other_url="[email protected]:${other_org}/${repo_name}.git"
461+
else
462+
# HTTPS URL format
463+
other_url="https://github.com/${other_org}/${repo_name}.git"
464+
fi
465+
466+
echo "Adding $other_org remote: $other_url"
467+
git remote add "$other_org" "$other_url"
468+
if [ $? -ne 0 ]; then
469+
echo "ERROR: Failed to add $other_org remote in $repo_name"
470+
return 1
471+
fi
472+
else
473+
echo "Remote '$other_org' already exists in $repo_name"
474+
fi
475+
476+
echo "Successfully configured remotes for $repo_name"
477+
return 0
478+
}
479+
480+
setup_all_forked_repo_remotes ()
481+
{
482+
local successful_repos=()
483+
local failed_repos=()
484+
local skipped_repos=()
485+
486+
echo "Setting up remotes for all forked repositories..."
487+
echo "========================================"
488+
489+
for repo in "${repos[@]}" "${non_release_repos[@]}"
490+
do
491+
# Extract repo name from URL
492+
if [[ ! $repo =~ $name_pattern ]]; then
493+
echo "Cannot setup remotes for repo; URL did not match expected pattern: $repo"
494+
continue
495+
fi
496+
local name="${BASH_REMATCH[1]}"
497+
498+
# Check if directory exists
499+
if [ ! -d "$name" ]; then
500+
echo "Repository $name is not cloned. Skipping."
501+
skipped_repos+=("$name")
502+
continue
503+
fi
504+
505+
# Check if this repo is configured as a forked repo
506+
if [ -z "${FORKED_REPOS[$name]}" ]; then
507+
echo "Repository $name is not configured as a forked repo. Skipping."
508+
skipped_repos+=("$name")
509+
continue
510+
fi
511+
512+
# Change to repo directory and setup remotes
513+
cd "$name"
514+
if setup_forked_repo_remotes "$name"; then
515+
successful_repos+=("$name")
516+
else
517+
failed_repos+=("$name")
518+
fi
519+
cd "$DEVSTACK_WORKSPACE"
520+
echo ""
521+
done
522+
523+
# Print summary report
524+
echo "========================================"
525+
echo "Remote Setup Summary:"
526+
echo "========================================"
527+
528+
if [ ${#successful_repos[@]} -gt 0 ]; then
529+
echo "✓ Successfully configured remotes for ${#successful_repos[@]} repositories:"
530+
printf " - %s\n" "${successful_repos[@]}"
531+
echo ""
532+
fi
533+
534+
if [ ${#failed_repos[@]} -gt 0 ]; then
535+
echo "✗ Failed to configure remotes for ${#failed_repos[@]} repositories:"
536+
printf " - %s\n" "${failed_repos[@]}"
537+
echo ""
538+
fi
539+
540+
if [ ${#skipped_repos[@]} -gt 0 ]; then
541+
echo "◦ Skipped ${#skipped_repos[@]} repositories (not cloned or not forked):"
542+
printf " - %s\n" "${skipped_repos[@]}"
543+
echo ""
544+
fi
545+
546+
echo "Total repositories processed: $((${#successful_repos[@]} + ${#failed_repos[@]} + ${#skipped_repos[@]}))"
547+
548+
if [ ${#failed_repos[@]} -gt 0 ]; then
549+
return 1
550+
else
551+
return 0
552+
fi
553+
}
554+
290555
if [ "$1" == "checkout" ]; then
291556
checkout
292557
elif [ "$1" == "clone" ]; then
@@ -297,4 +562,6 @@ elif [ "$1" == "reset" ]; then
297562
reset
298563
elif [ "$1" == "status" ]; then
299564
status
565+
elif [ "$1" == "setup-remotes" ]; then
566+
setup_all_forked_repo_remotes
300567
fi

0 commit comments

Comments
 (0)