forked from iam-veeramalla/python-for-devops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04-demo-github-integration.py
33 lines (26 loc) · 1.18 KB
/
04-demo-github-integration.py
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
# Program to demonstrate integration with GitHub to fetch the
# details of Users who created Pull requests(Active) on Kubernetes Github repo.
import requests
# URL to fetch pull requests from the GitHub API
url = f'https://api.github.com/repos/kubernetes/kubernetes/pulls'
# Make a GET request to fetch pull requests data from the GitHub API
response = requests.get(url) # Add headers=headers inside get() for authentication
# Only if the response is successful
if response.status_code == 200:
# Convert the JSON response to a dictionary
pull_requests = response.json()
# Create an empty dictionary to store PR creators and their counts
pr_creators = {}
# Iterate through each pull request and extract the creator's name
for pull in pull_requests:
creator = pull['user']['login']
if creator in pr_creators:
pr_creators[creator] += 1
else:
pr_creators[creator] = 1
# Display the dictionary of PR creators and their counts
print("PR Creators and Counts:")
for creator, count in pr_creators.items():
print(f"{creator}: {count} PR(s)")
else:
print(f"Failed to fetch data. Status code: {response.status_code}")