Template request | Bug report | Generate Data Product
Tags: #github #pygithub #repo #api #python
Author: Florent Ravenel
Description: This notebook list all pull requests from a repository name using pygithub library.
References:
import os
import json
from github import Github
import naas
token
: Generate a personal access tokenrepo_name
: name of the repository
token = naas.secret.get("GITHUB_TOKEN") or "YOUR_TOKEN"
repo_name = "jupyter-naas/awesome-notebooks"
Using the Github
class from the github
library, we can connect to the GitHub API and get the all PR from a given repository.
# Connect to the GitHub API
g = Github(token)
# Get the repository
repo = g.get_repo(repo_name)
# Get the closed PR
pull_requests = repo.get_pulls(state="all")
# Print the closed PR
print("✅ Pull Requests fetched:", pull_requests.totalCount)
for index, pr in enumerate(pull_requests):
print(json.dumps(pr.raw_data, indent=4))
break