File size: 1,514 Bytes
4ad2293
 
 
 
 
 
 
 
 
 
 
 
da2c1fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4ad2293
 
da2c1fb
4ad2293
da2c1fb
 
4ad2293
 
da2c1fb
4ad2293
88783a0
 
 
 
 
 
 
 
4ad2293
88783a0
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
import gradio as gr
import requests
import os

def invite_user(username):
    GITHUB_TOKEN = os.getenv('GITHUB_TOKEN')
    GITHUB_ORG = os.getenv('GITHUB_ORG')
    headers = {
        'Authorization': f'token {GITHUB_TOKEN}',
        'Accept': 'application/vnd.github.v3+json',
    }
    
    # Step 1: Fetch the user ID based on the username
    user_response = requests.get(
        f'https://api.github.com/users/{username}',
        headers=headers
    )
    
    if user_response.status_code != 200:
        return f'Error fetching user ID: {user_response.json().get("message", "Unknown error")}'
    
    user_id = user_response.json().get('id')
    
    if not user_id:
        return 'Error: Could not retrieve user ID'
    
    # Step 2: Send the invitation using the user ID
    invite_response = requests.post(
        f'https://api.github.com/orgs/{GITHUB_ORG}/invitations',
        headers=headers,
        json={'invitee_id': user_id}
    )
    
    if invite_response.status_code == 201:
        return f'Invitation sent to {username}'
    else:
        return f'Error: {invite_response.json().get("message", "Unknown error")}'

with gr.Blocks() as iface:
    gr.Markdown("# Join AccioINTERN")
    with gr.Row():
        username_input = gr.Textbox(label="GitHub Username")
        response_output = gr.Textbox(label="Response", interactive=False)
    submit_btn = gr.Button("Get Invitation")
    
    submit_btn.click(fn=invite_user, inputs=username_input, outputs=response_output)

iface.launch()