library(github335) library(tidyverse) library(googlesheets4) library(gh) library(stringr) library(RVerbalExpressions)
First we will need to define a few variables that will help us when we are using the functions below.
semester_id <- "Test20" # fa20, sp20, wi20 creator_email <- "hathawayj@gmail.com" # The email that has access to google docs. semester_name <- str_c("student_", semester_id) ta_name <- str_c("ta_", semester_id) semester_id_upper <- str_to_upper(semester_id) google_sheet_githubnames <- "https://docs.google.com/spreadsheets/d/1TB_adLB9cNopQo0JLXfaCxtBW7abibIEmqYopqT-AAI/edit?usp=sharing"
First create the ta and the student group for the semester. Then get the GitHub ids for each team.
dwv_create_groups(semester_name = semester_name, ta_name = ta_name) teams <- dwv_get_teams(semester_name = semester_name, ta_name = ta_name) students_team_id <- pull(teams, students_team_id) ta_team_id <- pull(teams, ta_team_id)
We assume that a tibble object is created for the new student and that all groups have been created for the current semester.
one_student <- structure(list(Student = "J Hathaway", `BYUI Email` = "hathawayj@byui.edu", gitName = "hathawayj", description = "MCS 335 TEST repository for J Hathaway coursework", has_ghname = TRUE, name = "M335_TEST20_Hathaway_J"), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -1L))
Student | BYUI Email | gitName | description | has_ghname | name |
---|---|---|---|---|---|
J Hathaway | hathawayj@byui.edu | hathawayj | MCS 335 repository for J Hathaway coursework | TRUE | M335_SP20_Hathaway_J |
Creating Issues: If you are using GitHub for the students to manage their progress then you will need to create issues and push the tasks into them. It is built to pull information from an md file of the following format.
Use the wrapper dwv_one_student()
function with the body_lines
argument set to NULL
and no issues will be created for the student.
body_lines = read_lines("https://byuistats.github.io/M335/tasklist.md")
dwv_one_student(one_student = one_student, class_group = "student_Test20", ta_group = "ta_Test20", body_lines = body_lines) # You can delete a repo using the following commented function # dwv_delete_github("M335_Test20_Hathaway_J")
The dwv_one_student()
function simply works throught the following functions in the package in the order listed. You can run them individually if you prefer.
dwv_check_names(one_student) dwv_check_repos(one_student) dwv_copy_repo(one_student$name, one_student$description) team_ids <- dwv_get_teams(semester_name = "student_Test20", ta_name = "ta_Test20") dwv_invite_group(one_student, pull(team_ids,students_team_id)) dwv_add_student(one_student) dwv_add_group(one_student, "pull", pull(team_ids, students_team_id)) dwv_add_group(one_student, "admin", pull(team_ids, ta_team_id)) dwv_remove_watching(one_student) # run authenticad as user. dwv_team_repos(pull(team_ids, students_team_id)) dwv_issue_cs(body_lines, dat = one_student) dwv_issue_tasks(body_lines, dat = one_student) dwv_issue_semester(body_lines, dat = one_student)
The following code examples use purrr
to move through a full table of students.
First, we need to have the table of student emails and GitHub usernames. It is hard coded to use the google sheet column names above.
#drive_auth(email = creator_email) gs4_auth(email = creator_email) mdf <- read_sheet(google_sheet_githubnames, sheet = semester_id_upper) %>% mutate(Name = Name %>% str_trim() %>% str_remove_all("\\."), `BYUI Email` = str_to_lower(`BYUI Email`) %>% str_replace_all(rx() %>% rx_find("@") %>% rx_anything() %>% rx_end_of_line(), "@byui.edu")) %>% select(Student = Name, `BYUI Email`, gitName = `GitHub Username`)
Then we have to check if their GitHub username exists.
check_names <- dwv_check_names(mdf) has_ghname <- check_names$has_ghname git_students <- check_names$git_students
Now we build the table to create student repositories and check to see if the repos are created.
## prepare a data frame to drive repo creation repo_create_df <- mdf %>% mutate(description = paste("MCS 335 repository for", Student, "coursework"), has_ghname = has_ghname, # a bunch of code to build a repo id for each student name = str_c("M335_", semester_id_upper, "_", Student %>% str_split_fixed(" ", 2) %>% .[,2] %>% str_replace_all(" ", "_"), "_", Student %>% str_split_fixed(" ", 2) %>% .[,1] %>% str_sub(1,4), sep = "")) oops <- dwv_check_repos(repo_create_df)
Now we create the GitHub repos for the new students that don’t have a repository in their name and have a github username.
# (repo_create_df_new <- repo_create_df %>% filter(has_ghname & oops)) ## This makes the repositories for each student # purrr::map(repo_create_df_new$name, dwv_delete_github) res <- purrr::map2(repo_create_df_new$name, repo_create_df_new$description, dwv_copy_repo) # this just makes sure the repos were created. status <- repo_create_df_new %>% mutate(cr_success = map_lgl(transpose(res)$result, Negate(is.null))) %>% select(-description)
If you are using GitHub for the students to manage their progress then you will need to create issues and push the tasks into them. It is built to pull informatin from an md file of the following format.
body_lines = read_lines("https://byuistats.github.io/M335/tasklist.md")
The below code will push issues to each repository provided in the tibble. Run them in the following order to get the issues to show up in a clean viewable order.
# Create the case study (cs) issues. One for each case study dwv_issue_cs(body_lines, dat = repo_create_df_new) # Create one issue with all of the class task project tasks in it. dwv_issue_tasks(body_lines, dat = repo_create_df_new) # Create one issue with all the semester level items. Leadership, cover letter dwv_issue_semester(body_lines, dat = repo_create_df_new)