-
Notifications
You must be signed in to change notification settings - Fork 5
feat: create github repo on course creation #615
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
base: main
Are you sure you want to change the base?
feat: create github repo on course creation #615
Conversation
"Course published with auto-export enabled. Starting export... (course id: %s)", # noqa: E501 | ||
course_key, | ||
) | ||
# HACK: To create auto git repo for Re-runs as it does not emit COURSE_CREATED signal # noqa: E501 FIX004 |
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.
Is it a bug that reruns don't emit COURSE_CREATED
signal?
Is there a different signal emitted when a rerun is created? @asadali145
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.
Is there a different signal emitted when a rerun is created? @asadali145
I am not sure about a specific signal, but we listen for the post_save signal on changes in CourseRerunState
model. It actually tracks the status of reruns, like in_progress, failed, and completed. When a rerun state is completed, then we update our course sync mappings.
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.
I discussed this with @marslanabdulrauf and @arslanashraf7; reruns do not trigger the COURSE_CREATED signal, which looks like a bug to me. The reason is that course reruns follow a completely different code path, and that never sends a COURSE_CREATED signal.
We can listen for CourseRerunState post save here like we do for the course sync plugin.
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.
thanks @asadali145 I will update it to catch course re-run creation through post_save
signal 👍
When we create a repo, I want to make sure that it is set to private in Github. Course exports are considered sensitive since they can contain exam solutions. This is critical, so should be in this PR. If possible, I'd also like to set the repo description at creation time, with a string like @cachob anything else we learned recently about creating repos? |
The repository is set to Private. I can update the repository description, current set to very minimal description, can be seen from attached SS as well: ![]() |
} | ||
payload = { | ||
"name": course_id_slugified, | ||
"description": f"Git repository for {course_id!s}", |
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.
Can we do something like f"{display_name}, exported from {studio_url}" so repo users can easily see which repo goes with which course and can link to it in Studio?
|
||
def listen_for_course_created(**kwargs): | ||
course_id = kwargs.get("course").course_key | ||
course_id_slugified = slugify(str(course_id)) |
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.
Can you give an example of the output of slugify for a typical course key?
I'm concerned that we might be dropping all the +
s, which act as delimiters and make it easier to read and parse.
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.
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.
I tested it with all special characters that I could type from my laptop and other than .
, -
and _
it converts all of them into -
Let me add a formatter to convert course_id
into Github supported format, it will increase readability
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.
Can we also drop the course-v1-
from the start of the repo name? It will be the same for all repos. (unless maybe someday there is a course-v2).
@pdpinch I updated the repository name and added a screenshot of repo page in PR description |
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.
This is a high-level code review. I will proceed with the testing in the next review.
"FEATURES": { | ||
"ENABLE_EXPORT_GIT": true, | ||
"ENABLE_AUTO_GITHUB_REPO_CREATION": true # Optional, to auto create github repo for new courses |
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.
How about we create a waffle flag? A feature flag will require a code change in ol-infra to enable/disable it, followed by redeployment.
} | ||
# Set when ENABLE_AUTO_GITHUB_REPO_CREATION is true | ||
GITHUB_ORG_API_URL = "https://api.github.com/orgs/<GITHUB_ORG_NAME>" # For GitHub Enterprise, change the URL accordingly | ||
GITHUB_ACCESS_TOKEN = "<GITHUB_PERSONAL_ACCESS_TOKEN>" # Token must have repo creation permissions |
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.
Can we list down the steps and exact permissions required?
---------------------- | ||
- Open studio then course and go to advanced settings. | ||
- Choose field GIT URL and add you OLX git repo. For example ``[email protected]:<GITHUB_USERNAME>/edx4edxlite.git``. | ||
- Open studio `admin <http://studio.local.openedx.io:8001/admin/ol_openedx_git_auto_export/coursegitrepo/>`_ |
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.
- Open studio `admin <http://studio.local.openedx.io:8001/admin/ol_openedx_git_auto_export/coursegitrepo/>`_ | |
- Open studio admin at `/ol_openedx_git_auto_export/coursegitrepo/` |
- Open studio then course and go to advanced settings. | ||
- Choose field GIT URL and add you OLX git repo. For example ``[email protected]:<GITHUB_USERNAME>/edx4edxlite.git``. | ||
- Open studio `admin <http://studio.local.openedx.io:8001/admin/ol_openedx_git_auto_export/coursegitrepo/>`_ | ||
- Add your course_id and in GIT URL add you OLX git repo. For example ``[email protected]:<GITHUB_USERNAME>/edx4edxlite.git``. |
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.
- Add your course_id and in GIT URL add you OLX git repo. For example ``[email protected]:<GITHUB_USERNAME>/edx4edxlite.git``. | |
- Add your course_id and in the GIT URL, add your OLX git repo. For example ``[email protected]:<GITHUB_USERNAME>/edx4edxlite.git``. |
list_per_page = 20 | ||
|
||
|
||
admin.site.register(CourseGitRepo, CourseGitRepoAdmin) |
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.
We can use the @admin.register
decorator here.
"""Create a GitHub repository for the given course key. | ||
Args: | ||
course_key (CourseKey): The course key for which to create the repository. | ||
Returns: | ||
str or None: The SSH URL of the created repository, or None if creation failed. | ||
""" |
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.
"""Create a GitHub repository for the given course key. | |
Args: | |
course_key (CourseKey): The course key for which to create the repository. | |
Returns: | |
str or None: The SSH URL of the created repository, or None if creation failed. | |
""" | |
""" | |
Create a GitHub repository for the given course key. | |
Args: | |
course_key (CourseKey): The course key for which to create the repository. | |
Returns: | |
str or None: The SSH URL of the created repository, or None if creation failed. | |
""" |
return repo_name.replace("course-v1-", "") | ||
|
||
|
||
def create_github_repo(course_key): |
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.
I think we should move the repo creation to a Celery task.
) | ||
return None | ||
|
||
# SignalHandler.course_published is called before COURSE_CREATED signal |
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.
Is this a valid comment?
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.
yes, I faced issues but its not valid now as we have moved repo creation to post_save
signal
"description": repo_desc, | ||
"private": True, | ||
"has_issues": False, | ||
"has_project": False, |
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.
correct key is has_projects
"auto_init": True, | ||
} | ||
response = requests.post(url, headers=headers, json=payload, timeout=30) | ||
if response.status_code != 201: # noqa: PLR2004 |
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.
we can use restframework status.201
We discussed this in the morning, and I am posting here on behalf of @marslanabdulrauf as he is out sick and could not post this comment. @pdpinch Do we want to auto-create GitHub repos for all the new courses, including UAI and non-UAI courses? If the goal is to create repositories only for UAI courses, would it make sense to use |
All courses should get a repo, UAI and non-UAI. In particular, we need to have version control of all UAI_SOURCE courseruns. |
Thanks for clarifying @pdpinch I have also updated migration command to:
|
What are the relevant tickets?
https://github.com/mitodl/hq/issues/6962
Description (What does it do?)
This PR:
Screenshot
How can this be tested?
tutor dev exec cms ./manange.py cms migrate
Testing management command
tutor dev exec cms ./manage.py cms migrate_giturl
Auto repo creation testing
ENABLE_AUTO_GITHUB_REPO_CREATION
GITHUB_ORG_API_URL
GITHUB_ACCESS_TOKEN
-- This token should have repo read/write and pull/push access.