Initialize self. See help(type(self)) for accurate signature.
Type
Default
Details
credentials_fp
str
the file path to the credential json
org
str
the organization name
verbosity
int
1
Controls the verbosity: 0=silent, 1=print status
GitHub Authentication
View this document for how to set up your GitHub Personal Access Token. (TODO: be sure to specify scopes)
Store the token information in a json file.
credentials_fp ="credentials.json"withopen(credentials_fp, "r") as f:# take a look at the tokenprint(f.read())g = GitHubGroup(credentials_fp=credentials_fp, org="COGS118A", verbosity=1)
Usually, you want to create students repositories under a course GitHub organization. To set the target organization, you can call the following function.
the permission of collaborators. pull, push or admin
rename_files
dict
{}
dictionary of files renames {:}
repo_template
str
If empty string, an empty repo will be created. Put in the format of “/”
private
bool
True
visibility of the created repository
description
str
description for the GitHub repository
team_slug
str
team slug, add to this repo
team_permission
str
team permission to this repository pull, push or admin
feedback_dir
bool
False
whether to create a feedback directory for each repository created
feedback_template_fp
str
the directory of the feedback template
Returns
Repository
created repository
repo = g.create_group_repo( repo_name="API_test_repo", collaborators=["jasongfleischer"], permission="admin", repo_template="COGS118A/group_template", rename_files={"Checkpoint_groupXXX.ipynb": "Checkpoint_group001.ipynb","FinalProject_groupXXX.ipynb": "FinalProject_group001.ipynb","Proposal_groupXXX.ipynb": "Proposal_group001.ipynb" }, private=False, description="Test Creation of Group Repo for COGS118A final project group", team_slug="Instructors_Sp23", team_permission="admin")
Repo API_test_repo Created... Wait for 3 sec to updates
File Successfully Renamed from Checkpoint_groupXXX.ipynb to Checkpoint_group001.ipynb
File Successfully Renamed from FinalProject_groupXXX.ipynb to FinalProject_group001.ipynb
File Successfully Renamed from Proposal_groupXXX.ipynb to Proposal_group001.ipynb
Added Collaborator: jasongfleischer to: API_test_repo with permission: admin
Team Instructors_Sp23 added to API_test_repo with permission admin
Group Repo: API_test_repo successfuly created!
Lower Level Methods
Belows are the components that faciliate the GitHubGroup.create_group_repo. If errors were prompted during group creation scripts, or simply you want more flexibility, you can call those components individually.
Create GitHub Repository
Note:GtiHubGroup.create_group_repo call this method to create a GitHub repository
personal_account argument controls the location of the repository creation. If set to False (default), it will create repository in the target organization. If set to True, the new repository will be created in the personal GitHub account.
Create a repository, either blank, or from a template
Type
Default
Details
repo_name
str
repository name
repo_template
str
template repository that new repo will use. If empty string, an empty repo will be created. Put in the format of “/”
private
bool
True
visibility of the created repository
description
str
description for the GitHub repository
personal_account
bool
False
create repos in personal GitHub account
Returns
Repository
Note:GtiHubGroup.create_group_repo call this method to create a GitHub repository
personal_account argument controls the location of the repository creation. If set to False (default), it will create repository in the target organization. If set to True, the new repository will be created in the personal GitHub account.
# create a repo under the orgrepo = g.create_repo("test-repo-organizational", private=True)print(repo)
You can also create a repository with a template repository. To do that, specify the full name of the template repository to the repo_template parameter. From the output, we can see that the repository test-repo-from-template is created with the template files.
# create a repo from a templaterepo = g.create_repo( repo_name="test-repo-from-template", repo_template="COGS118A/group_template", private=True)print(repo)# wait 3 sec for repository creation.time.sleep(3)print("\nThis Repository contains... \n")pprint(repo.get_contents("."))
Repository(full_name="COGS118A/test-repo-from-template")
This Repository contains...
[ContentFile(path=".gitignore"),
ContentFile(path="Checkpoint_groupXXX.ipynb"),
ContentFile(path="FinalProject_groupXXX.ipynb"),
ContentFile(path="Proposal_groupXXX.ipynb"),
ContentFile(path="README.md")]
Rename Files in the Repository
Usually, the template file names are generics and is not specific to a group. Under the context of group project, we want to rename each notebook files with thier group numbers. For example, for Group 1, we want to rename the file Checkpoint_groupXXX.ipynb to Checkpoint_group001.ipynb. To do that, we can use the following method.
Rename the file by delete the old file and commit the new file
Type
Details
repo
Repository
the repository that we want to rename file
og_filename
str
old file name
new_filename
str
new file name
Note: This method simply delete the old files and create new files with the updated file name. Therefore, 2 commits for each file is expected. (1 for delete, 1 for re-upload). For example, if I want to rename 5 files, I will have 10 commits need to do in total.
g.rename_files( repo=repo, og_filename="Checkpoint_groupXXX.ipynb", new_filename="Checkpoint_group001.ipynb")# take a look at new filesprint("\nThis Repository contains... \n")pprint(repo.get_contents("."))
File Successfully Renamed from Checkpoint_groupXXX.ipynb to Checkpoint_group001.ipynb
This Repository contains...
[ContentFile(path=".gitignore"),
ContentFile(path="Checkpoint_group001.ipynb"),
ContentFile(path="FinalProject_groupXXX.ipynb"),
ContentFile(path="Proposal_groupXXX.ipynb"),
ContentFile(path="README.md")]
Notice that the files were renamed as expected.
Collaborators and Teams Access Repository
Once the repository was created, we need to give the student team members proper permission to write to the repository and instructional team to be the admin of the repository. Those two functionalities are achieve by the following two methods.
Add collaborator to the repository with specified permission
Type
Details
repo
Repository
target repository
collaborator
str
GitHub username of the collaborator
permission
str
pull, push or admin
# add collaborator to the repository with push permissiong.add_collaborator( repo=repo, collaborator="Andrina-iris", permission="write")
Added Collaborator: Andrina-iris to: test-repo-from-template with permission: write
In almost every quarter, at least 10 students forgot to accept the invitation to join the group repository. Historially, our instructional team handle those student’s GitHub account on a case-by-case basis. However, with this module, it is possible to resent all pending and expired invitations to those students with one call.
Resent Invitation to invitee who did not accept the invitation
Type
Details
repo
Repository
target repository
Returns
[<class ‘github.NamedUser.NamedUser’>]
list of re-invited user
Students will receive an email from GitHub with the freshly made, unexpired invitation to their group repository.
g.resend_invitations(repo)
The list of pending invitation:
[NamedUser(login="Andrina-iris")]
Andrina-iris Invite Revoked Andrina-iris
Added Collaborator: Andrina-iris to: test-repo-from-template with permission: write
Invite Resent to Andrina-iris
[NamedUser(login="Andrina-iris")]
Additionally, course staffs should be in a team in the GitHub Organization in order to manage student repositories.
Team Instructors_Sp23 added to test-repo-from-template with permission admin
If you have all the students repositories under the same team, you can use the following method to resent all pending invitations from all the repositories under that team.
Repository AssignmentNotebooksSource_SP23 :
The list of pending invitation:
[]
Repository AssignmentNotebooks_SP23 :
The list of pending invitation:
[]
Repository DiscussionSectionNotebooks :
The list of pending invitation:
[]
Repository Dockerfiles :
The list of pending invitation:
[]
Repository Lectures :
The list of pending invitation:
[]
Repository Notebooks :
The list of pending invitation:
[]
Repository test-repo-from-template :
The list of pending invitation:
[NamedUser(login="Andrina-iris")]
Andrina-iris Invite Revoked Andrina-iris
Added Collaborator: Andrina-iris to: test-repo-from-template with permission: write
Invite Resent to Andrina-iris
Project Feedback and GitHub Issues
Thanks for the group nature of the created repository, we can also use the created GitHub repository to create group project feedback to students via GitHub issues.
We can create a directory under the instructors’ computer. Each directory will have a folder for each group repository with the template file. The template files are usually the rubrics for the project grading.
TODO: add file superlink to the repo to see the examples.
g.create_feedback_dir(repo, "feedback_template")# take a look at the generated tempalte files.os.listdir(f"feedback/{repo.name}")
File checkpoint_feedback.md created at feedback/test-repo-from-template
File proposal_feedback.md created at feedback/test-repo-from-template
File final_project_feedback.md created at feedback/test-repo-from-template
# create a test issueissue = g.create_issue(repo, "Test Issue", "This is just a test issue.")issue
In the repo: test-repo-from-template,
Issue Test Issue Created!
Issue(title="Test Issue", number=1)
Alternatively, you can create issue from markdown files, where it contains all the comments and rubrics for this project. The first line of the markdown file will be the title of the github issue.
During projct grading, we will handle numerous groups at once. Once the instructor team finish modifying the markdown file for each group, we can release feedback to each of the project repository, as long as they have the same file name. For example, we have finish grading the final project, in the file name of feedback/<repo_name>/final_project_feedback.md, and they are ready to be publish, we can call the following function to create issue in batch.