-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgithub_invite.pl
More file actions
52 lines (43 loc) · 1.65 KB
/
Copy pathgithub_invite.pl
File metadata and controls
52 lines (43 loc) · 1.65 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
#!/usr/bin/perl
use Getopt::Long;
#################### Default inputs ####################
#$role="admin";
$role="direct_member";
########################################################
GetOptions('user:s' => \$user,
'token:s' => \$token,
'email:s' => \$email,
'org_name:s' => \$org_name,
'role:s' => \$role,
'file:s' => \$file);
die ("Must supply -user= parameter") unless $user;
die ("Must supply -token= parameter") unless $token;
if ($file eq ""){
die ("Must supply -email= parameter") unless $email;
die ("Must supply -org_name= parameter") unless $org_name;
};
if ($file){
$filecontents = `cat $file`;
@entries = split(/\n/,$filecontents);
foreach $line (@entries){
chomp $line;
@input = split(/,/,$line);
$email = @input[0];
$org_name = @input[1];
$role = @input[2];
print "Sending GitHub invitation to $email for $org_name organization as a $role\n";
$invite = `curl -s -u \"$user:$token\" -X POST -H \"Accept: application/vnd.github.v3+json\" https://api.github.com/orgs/$org_name/invitations -d '{\"email\":\"$email\",\"role\":\"$role\"}'`;
print "$invite";
}
} else {
print "Sending GitHub invitation to $email for $org_name organization as a $role\n";
$invite = `curl -s -u \"$user:$token\" -X POST -H \"Accept: application/vnd.github.v3+json\" https://api.github.com/orgs/$org_name/invitations -d '{\"email\":\"$email\",\"role\":\"$role\"}'`;
print "$invite";
}
# Send invitation format
# curl \
# -u "username:personal_token" \
# -X POST \
# -H "Accept: application/vnd.github.v3+json" \
# https://api.github.com/orgs/$org_name/invitations \
# -d '{"email":$email,"role":$role}'