-
-
Notifications
You must be signed in to change notification settings - Fork 883
Add field to store github_branch for challenges #4745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Zahed-Riyaz
wants to merge
23
commits into
Cloud-CV:master
Choose a base branch
from
Zahed-Riyaz:starters-versions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
8d6ae67
Store Github branch with challenge data
Zahed-Riyaz 9164bf0
Modify backend to store github branch
Zahed-Riyaz 3cf0b12
Merge branch 'master' into starters-versions
Zahed-Riyaz 2f6e1a3
Handle empty branches
Zahed-Riyaz 69b9535
Merge migrations
Zahed-Riyaz 4bff095
Update seed.py
Zahed-Riyaz 75a7868
Add GitHub branch versioning support for multi-version challenges
Zahed-Riyaz e2d7f53
Revert unnecessary changes
Zahed-Riyaz f6a06d7
Fix tests
Zahed-Riyaz 3287cc9
Update Github branch var
Zahed-Riyaz 34cbec3
Merge branch 'master' into starters-versions
Zahed-Riyaz a1bd1ea
Fix failing tests
Zahed-Riyaz 6bbcea7
Pass flake8 and pylint tests
Zahed-Riyaz 4188b9c
Add github_branch field to backend
Zahed-Riyaz 831fec2
Add scripts for populating field
Zahed-Riyaz 1cb4fcf
Merge branch 'master' into starters-versions
Zahed-Riyaz 8af18d5
Allow alphanumeric values for branch name
Zahed-Riyaz 350936f
Remove duplicate params
Zahed-Riyaz fb379aa
Update migrations and fallback logic
Zahed-Riyaz 8a8e2d8
Update branch validation logic
Zahed-Riyaz 1355c62
Merge branch 'master' into starters-versions
Zahed-Riyaz d136023
Merge branch 'master' into starters-versions
Zahed-Riyaz c8bd7c9
Reformat for quality checks
Zahed-Riyaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/env python | ||
# Command to run: python manage.py shell < scripts/migration/populate_github_branch.py | ||
""" | ||
Populate existing challenges with github_branch="challenge" for backward compatibility. | ||
This script should be run after the migration to ensure all existing challenges | ||
have the github_branch field populated with the default value. | ||
""" | ||
|
||
import traceback | ||
|
||
from challenges.models import Challenge | ||
from django.db import models | ||
|
||
|
||
def populate_github_branch_fields(): | ||
""" | ||
Populate existing challenges with empty github_branch fields to use "challenge" as default. | ||
""" | ||
print("Starting github_branch field population...") | ||
|
||
challenges_to_update = ( | ||
Challenge.objects.filter(github_repository__isnull=False) | ||
.exclude(github_repository="") | ||
.filter( | ||
models.Q(github_branch__isnull=True) | models.Q(github_branch="") | ||
) | ||
Comment on lines
+1
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we already have this script to populate and back-fill, why do we need to the populate/reverse populate methods at all? |
||
) | ||
|
||
count = challenges_to_update.count() | ||
|
||
if count == 0: | ||
print("No challenges found that need github_branch population.") | ||
return | ||
|
||
print(f"Found {count} challenges that need github_branch population.") | ||
|
||
updated_count = challenges_to_update.update(github_branch="challenge") | ||
|
||
print( | ||
f"Successfully updated {updated_count} challenges with github_branch='challenge'" | ||
) | ||
|
||
remaining_empty = ( | ||
Challenge.objects.filter(github_repository__isnull=False) | ||
.exclude(github_repository="") | ||
.filter( | ||
models.Q(github_branch__isnull=True) | models.Q(github_branch="") | ||
) | ||
.count() | ||
) | ||
|
||
if remaining_empty == 0: | ||
print("✅ All challenges now have github_branch populated!") | ||
else: | ||
print( | ||
f"⚠️ Warning: {remaining_empty} challenges still have empty github_branch fields" | ||
) | ||
|
||
sample_challenges = ( | ||
Challenge.objects.filter(github_repository__isnull=False) | ||
.exclude(github_repository="") | ||
.values("id", "title", "github_repository", "github_branch")[:5] | ||
) | ||
|
||
print("\nSample updated challenges:") | ||
for challenge in sample_challenges: | ||
print( | ||
f" ID: {challenge['id']}, Title: {challenge['title']}, " | ||
f"Repo: {challenge['github_repository']}, Branch: {challenge['github_branch']}" | ||
) | ||
|
||
|
||
try: | ||
populate_github_branch_fields() | ||
print("\n✅ Script completed successfully!") | ||
except Exception as e: | ||
print(f"\n❌ Error occurred: {e}") | ||
print(traceback.print_exc()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this also be okay with just "challenge" (default) if passed?