Created
February 17, 2018 04:02
-
-
Save mchow01/4c961f04a57c6e4fcf9b5a6abe982c01 to your computer and use it in GitHub Desktop.
Create private GitHub repos under an organization for students in a class for homework and lab submissions
This file contains 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
require "csv" | |
require 'Octokit' | |
# See documentation at: | |
# 1. https://github.com/octokit/octokit.rb | |
# 2. http://www.rubydoc.info/github/pengwynn/octokit/Octokit | |
# Settings | |
# *.tsv is a tab-delimited file with the columns separated by tab: lastname, firstname, githubusername | |
tsv_file_name = "20.tsv" | |
course_prefix = "comp20" | |
outfile_name = "clone_comp20_repos.sh" | |
github_org = "tuftsdev" | |
repo_description_prefix = "COMP 20 Spring 2018 Private Repo for" | |
begin | |
outfile = File.open(outfile_name, "w") | |
client = Octokit::Client.new(:access_token => #ACCESS_TOKEN_HERE) | |
parsed_file = CSV.read(tsv_file_name, { :col_sep => "\t" }) | |
parsed_file.each do |student| | |
# This is the name of the team and private GitHub repo | |
repo_group_name = course_prefix + "-" + student[1][0].downcase + student[0].downcase | |
# Create new repository for team and set it to private | |
# team_id is for TAs team on GitHub | |
repo = client.create_repository(repo_group_name, { | |
:description => "#{repo_description_prefix} #{student[1]} #{student[0]}", | |
:private => "true", | |
:team_id => #TEAM_ID_HERE, | |
:organization => github_org | |
}) | |
# Add student to repository as admin | |
client.add_collaborator("#{github_org}/#{repo_group_name}", student[2], permission: 'admin') | |
# This creates script to clone each student's repo | |
outfile.write("git clone [email protected]:#{github_org}/#{repo_group_name};\n") | |
# Set repository from private to public, used at end of semester | |
#client.set_public(github_org + "/" + repo_group_name) | |
end | |
rescue IOError => e | |
puts "Whoops, something went terribly wrong! " + e.to_s | |
ensure | |
outfile.close unless outfile.nil? | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment