Skip to content
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

GitHub script2.0 #96

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update the readme file and corresponding opt descriptions.
  • Loading branch information
a544266477 committed Sep 22, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit d4c05a1a1411e5d28a206ebeaaab063136a57b40
2 changes: 1 addition & 1 deletion scripts/github-repos/README.md
Original file line number Diff line number Diff line change
@@ -104,7 +104,7 @@ to the students in csv file. For students NOT in STUDENTTEAM, invite them to STU

**Use case:** Create groups for students for CHIP 10.5.

### Create CHIPS repo for each stedent
### Create CHIPS repo for each student

**Use case:** Create CHIP repos for each student in STUDENTTEAM.
The repos' names are formed like "[PREFIX]-[username]-[ASSIGNMENT]". There will
37 changes: 18 additions & 19 deletions scripts/github-repos/github-repos.rb
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
require 'octokit'
require 'csv'

ENV['GITHUB_ORG_API_KEY'] = ""
ENV['GITHUB_ORG_API_KEY'] = "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"

def main()
puts "Script start."
@@ -43,7 +43,7 @@ def main()
opt.on('-pPREFIX', '--prefix=PREFIX', 'Semester prefix, eg fa23.') do |pfx|
org.semester = pfx
end
opt.on('-aASSIGNMENT', '--assignment=ASSIGNMENT', 'The assignment name. eg chip-10.5') do |filename|
opt.on('-aASSIGNMENT', '--assignment=ASSIGNMENT', 'The assignment name. eg chip-10.5') do |assignment|
org.assignment = assignment
end
opt.on('-tTEMPLATE', '--template=TEMPLATE', 'The repo name within the org to use as template') do |template|
@@ -55,17 +55,7 @@ def main()
end
$opts.parse!
command = ARGV.pop
case command
when 'invite' then org.invite
when 'create_teams' then org.create_teams
when 'indiv_repos' then org.indiv_repos
when 'group_repos' then org.group_repos
when 'remove_indiv_repos' then org.remove_indiv_repos
when 'remove_group_repos' then org.remove_group_repos
when 'remove_teams' then org.remove_teams
when 'remove_group_repos_access' then org.remove_group_repos_access
else org.print_error
end
org.invoke_command command
puts "Run successfully."
puts "Script ends."
end
@@ -97,14 +87,14 @@ def read_users_from csv
end
end

def read_teams_and_users_from csv
def read_groups_and_users_from csv
data = CSV.parse(IO.read(csv), headers: true)
hash = data.first.to_h
print_error "Need at least 'Team' (int) and 'Username' (str) columns in #{csv}" unless
hash.has_key?('Team') && hash.has_key?('Username')
print_error "Need at least 'Group' (int) and 'Username' (str) columns in #{csv}" unless
hash.has_key?('Group') && hash.has_key?('Username')
data.each do |row|
username = row['Username']
@childteams[row['Team']] << username
@childteams[row['Group']] << username
end
end

@@ -133,7 +123,7 @@ def invite_valid?
if @semester.nil?
read_users_from @csv
else
read_teams_and_users_from @csv
read_groups_and_users_from @csv
end
true
end
@@ -142,7 +132,7 @@ def create_teams_valid?
if @orgname.nil? || @orgname.empty? || @csv.nil? || @parentteam.nil? || @parentteam.empty? || @semester.nil?
return false
end
read_teams_and_users_from @csv
read_groups_and_users_from @csv
true
end

@@ -172,6 +162,15 @@ def gsiteam_valid?

public

def invoke_command command
command = command.to_sym
if respond_to? command
send(command)
else
print_error
end
end

def print_error(msg=nil)
STDERR.puts "Error: #{msg}" if msg
STDERR.puts $opts
3 changes: 3 additions & 0 deletions scripts/github-repos/team-test.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Group,Username,Name
1,KCsama,Amy
2,Gangster-Who,Gang