-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateGithubTeamRepos.py
More file actions
64 lines (47 loc) · 1.94 KB
/
Copy pathCreateGithubTeamRepos.py
File metadata and controls
64 lines (47 loc) · 1.94 KB
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
#!/usr/bin/env python3
"""
mass create repos for teams
example with spreadsheet with usernames in column C, teamname in column D
python CreateGithubTeamRepos.py my.xlsx ~/.ssh/orgOauth myorg -stem sw -col C D
oauth token must have "admin:org" and public_repo (or repo for private) permissions
https://developer.github.com/v3/repos/#oauth-scope-requirements
"""
import pandas
from gitbulk import connect, repo_exists, check_api_limit
from pathlib import Path
from argparse import ArgumentParser
TEAMS = "Team"
NAME = "Name"
def by_name(teams: pandas.DataFrame, stem: str, private: bool, op, sess):
for _, row in teams.iterrows():
reponame = f"{stem}{row[TEAMS]:02.0f}-{row[NAME]}"
if repo_exists(op, reponame):
continue
print(f"creating {op.login}/{reponame}")
op.create_repo(name=reponame, private=private)
def by_num(teams: pandas.DataFrame, stem: str, private: bool, op, sess):
for teamnum in teams.values:
reponame = f"{stem}{teamnum}"
if repo_exists(op, reponame):
continue
print("creating", reponame)
op.create_repo(name=reponame, private=private)
p = ArgumentParser(description="mass create repos for teams")
p.add_argument("fn", help=".xlsx with group info")
p.add_argument("oauth", help="Oauth file")
p.add_argument("orgname", help="Github Organization")
p.add_argument("-stem", help="beginning of repo names", default="")
p.add_argument(
"-col", help="column(s) for TeamName OR TeamNumber, TeamName", nargs="+", required=True
)
p.add_argument("-private", help="create private repos", action="store_true")
P = p.parse_args()
fn = Path(P.fn).expanduser()
teams = pandas.read_excel(fn, usecols=",".join(P.col)).squeeze().dropna().drop_duplicates()
# %%
op, sess = connect(P.oauth, P.orgname)
check_api_limit(sess)
if teams.ndim == 1:
by_num(teams, P.stem, P.private, op, sess)
elif teams.shape[1] == 2:
by_name(teams, P.stem, P.private, op, sess)