Skip to content

Commit dab0b27

Browse files
demo
1 parent 53a9830 commit dab0b27

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Day-11/04-demo-github-integration.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Program to demonstrate integration with GitHub to fetch the
2+
# details of Users who created Pull requests(Active) on Kubernetes Github repo.
3+
4+
import requests
5+
6+
# URL to fetch pull requests from the GitHub API
7+
url = f'https://api.github.com/repos/kubernetes/kubernetes/pulls'
8+
9+
# Make a GET request to fetch pull requests data from the GitHub API
10+
response = requests.get(url) # Add headers=headers inside get() for authentication
11+
12+
# Only if the response is successful
13+
if response.status_code == 200:
14+
# Convert the JSON response to a dictionary
15+
pull_requests = response.json()
16+
17+
# Create an empty dictionary to store PR creators and their counts
18+
pr_creators = {}
19+
20+
# Iterate through each pull request and extract the creator's name
21+
for pull in pull_requests:
22+
creator = pull['user']['login']
23+
if creator in pr_creators:
24+
pr_creators[creator] += 1
25+
else:
26+
pr_creators[creator] = 1
27+
28+
# Display the dictionary of PR creators and their counts
29+
print("PR Creators and Counts:")
30+
for creator, count in pr_creators.items():
31+
print(f"{creator}: {count} PR(s)")
32+
else:
33+
print(f"Failed to fetch data. Status code: {response.status_code}")

0 commit comments

Comments
 (0)