Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,20 +8,33 @@ def invite_user(username):
|
|
8 |
headers = {
|
9 |
'Authorization': f'token {GITHUB_TOKEN}',
|
10 |
'Accept': 'application/vnd.github.v3+json',
|
11 |
-
'Content-Type': 'application/json',
|
12 |
}
|
13 |
-
data = {'invitee_id': username}
|
14 |
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
f'https://api.github.com/orgs/{GITHUB_ORG}/invitations',
|
17 |
headers=headers,
|
18 |
-
json=
|
19 |
)
|
20 |
-
|
21 |
-
if
|
22 |
return f'Invitation sent to {username}'
|
23 |
else:
|
24 |
-
return f'Error: {
|
25 |
|
26 |
with gr.Blocks() as iface:
|
27 |
gr.Markdown("# Join AccioINTERN")
|
|
|
8 |
headers = {
|
9 |
'Authorization': f'token {GITHUB_TOKEN}',
|
10 |
'Accept': 'application/vnd.github.v3+json',
|
|
|
11 |
}
|
|
|
12 |
|
13 |
+
# Step 1: Fetch the user ID based on the username
|
14 |
+
user_response = requests.get(
|
15 |
+
f'https://api.github.com/users/{username}',
|
16 |
+
headers=headers
|
17 |
+
)
|
18 |
+
|
19 |
+
if user_response.status_code != 200:
|
20 |
+
return f'Error fetching user ID: {user_response.json().get("message", "Unknown error")}'
|
21 |
+
|
22 |
+
user_id = user_response.json().get('id')
|
23 |
+
|
24 |
+
if not user_id:
|
25 |
+
return 'Error: Could not retrieve user ID'
|
26 |
+
|
27 |
+
# Step 2: Send the invitation using the user ID
|
28 |
+
invite_response = requests.post(
|
29 |
f'https://api.github.com/orgs/{GITHUB_ORG}/invitations',
|
30 |
headers=headers,
|
31 |
+
json={'invitee_id': user_id}
|
32 |
)
|
33 |
+
|
34 |
+
if invite_response.status_code == 201:
|
35 |
return f'Invitation sent to {username}'
|
36 |
else:
|
37 |
+
return f'Error: {invite_response.json().get("message", "Unknown error")}'
|
38 |
|
39 |
with gr.Blocks() as iface:
|
40 |
gr.Markdown("# Join AccioINTERN")
|