-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_teams.py
102 lines (86 loc) · 3.12 KB
/
create_teams.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import github
import os
# import requests
# import shutil
# import yaml
from dotenv import load_dotenv
from os.path import join, dirname
try:
dotenv_path = join(dirname(__file__), '.env')
load_dotenv(dotenv_path)
except Exception as e:
print "\nMissing .env file\n"
GITHUB_ACCESS_TOKEN = os.environ.get('GITHUB_ACCESS_TOKEN', None)
STUDENTS_TO_TEAMS = "teams2students.txt"
TEAMS_FILE = "teams-sp18.txt"
ORG_NAME = "ct-product-challenge-2017"
STUDIO_TEAM_ID = 2477099
def create_student_team(g, team_name, student_usernames):
team = g.get_organization(ORG_NAME).create_team(team_name)
for student in student_usernames:
team.add_to_members(g.get_user(student))
return team
# try / catch for typos --> print to logs
def create_empty_team_repo(g, repo_name):
repo = g.get_organization(ORG_NAME).create_repo(repo_name, private=True,
auto_init=True)
studio_team = g.get_organization(ORG_NAME).get_team(id=STUDIO_TEAM_ID)
studio_team.add_to_repos(g.get_organization(ORG_NAME).get_repo(repo_name))
return repo
def create_team_repo(g, repo_name, student_team):
repo = g.get_organization(ORG_NAME).create_repo(repo_name,
team_id=student_team, private=True, auto_init=True)
studio_team = g.get_organization(ORG_NAME).get_team(id=STUDIO_TEAM_ID)
studio_team.add_to_repos(g.get_organization(ORG_NAME).get_repo(repo_name), permission="admin")
return repo
def create_teams_map():
students = {}
with open(STUDENTS_TO_TEAMS) as f:
lines = [line.strip() for line in f.readlines()]
for line in lines:
line = line.split('\t')
if len(line) == 2:
students[line[1]] = line[0]
elif line[0]:
print line, 'team member missing github username'
teams = {}
for student in students.keys():
team = students[student]
if team in teams:
teams[team].append(student)
else:
teams[team] = [student]
return teams
def create_all_teams(g):
with open(TEAMS_FILE) as rd:
team_repos = [repo.strip() for repo in rd.readlines()]
print 'Creating team repos...'
for team in team_repos:
create_empty_team_repo(g, team)
print team
def populate_all_teams(g):
teams = create_teams_map()
for team in teams.keys():
repo_name = ORG_NAME + "/" + team
repo = g.get_repo(repo_name)
for member in teams[team]:
repo.add_to_collaborators(member)
print 'adding', member, 'to', repo.name
if __name__ == '__main__':
g = github.Github(GITHUB_ACCESS_TOKEN)
# create_all_teams(g)
populate_all_teams(g)
# ts = create_teams_map()
# for t in ts.keys():
# repo_name = ORG_NAME + "/" + t
# print repo_name
# for member in ts[t]:
# print member
# print
# g = github.Github(GITHUB_ACCESS_TOKEN)
# students = ['elanid', 'sahuguet']
# t = create_student_team(g, 'example-product-team', students)
# repo = create_team_repo(g, 'example-product-team', t)
# teams = create_teams_map()
# for team in teams.keys():
# print team