-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-repo-for-team.pl
41 lines (31 loc) · 1.35 KB
/
create-repo-for-team.pl
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
#!/usr/bin/perl
#
# Create a team repo for each team.
# This requires a csv file that contains team names and team Ids.
# Note: create-team-and-add-members.pl prints the team Ids.
#
# Example csv format (showing the header and a sample row):
# Team Name, Team Id
# Group 0, 1991963
use strict;
use warnings;
use JSON::Parse 'parse_json';
my $token = $ARGV[0];
my $orgName = $ARGV[1];
my $githubUrl = "https://api.github.com";
my $file = $ARGV[2] or die "Need to get CSV file on the command line\n";
open(my $data, '<', $file) or die "Could not open '$file' $!\n";
my $header_line = <$data>;
my @headers = split "," , $header_line;
while (my $line = <$data>) {
chomp $line;
my @fields = split "," , $line;
my $teamName = $fields[0];
my $teamId = $fields[1];
print "create repo for $teamName : $teamId\n";
my $response = `curl -s -H "Authorization: token $token" -H "Content-type: application/json" -X POST -d '{"name": "$teamName Project", "description": "$teamName Project", "private": true, "team_id": $teamId, "auto_init": true}' "$githubUrl/orgs/$orgName/repos"`;
$response = parse_json $response;
my $repo_name = $response->{"name"};
print "change $repo_name permission\n";
`curl -s -H "Authorization: token $token" -H "Content-type: application/json" -X PUT -d '{"permission": "push"}' "$githubUrl/teams/$teamId/repos/$orgName/$repo_name"`;
}