Skip to content

Latest commit

 

History

History
64 lines (42 loc) · 2.2 KB

GitHub_List_all_pull_requests.md

File metadata and controls

64 lines (42 loc) · 2.2 KB



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:

Input

Import libraries

import os
import json
from github import Github
import naas

Setup Variables

token = naas.secret.get("GITHUB_TOKEN") or "YOUR_TOKEN"
repo_name = "jupyter-naas/awesome-notebooks"

Model

List pull requests

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")

Output

Display result

# 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