-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithubapi.ph
43 lines (34 loc) · 1.19 KB
/
githubapi.ph
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
import requests
# Your personal access token
token = 'your_token_here'
headers = {'Authorization': f'token {token}'}
# Base URL for the GitHub API
base_url = 'https://api.github.com'
# Function to get a repository
def get_repo(owner, repo):
response = requests.get(f'{base_url}/repos/{owner}/{repo}', headers=headers)
data = response.json()
return data
# Function to list issues on a repository
def list_issues(owner, repo):
response = requests.get(f'{base_url}/repos/{owner}/{repo}/issues', headers=headers)
data = response.json()
return data
# Function to create an issue
def create_issue(owner, repo, title, body):
issue = {'title': title, 'body': body}
response = requests.post(f'{base_url}/repos/{owner}/{repo}/issues', headers=headers, json=issue)
data = response.json()
return data
# Replace 'owner' and 'repo' with the owner and name of the repository you're interested in
owner = 'owner'
repo = 'repo'
# Get a repository
repo_data = get_repo(owner, repo)
print(repo_data)
# List issues on a repository
issues = list_issues(owner, repo)
print(issues)
# Create an issue
new_issue = create_issue(owner, repo, 'New issue', 'This is a new issue.')
print(new_issue)