Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jupyter-naas
GitHub Repository: jupyter-naas/awesome-notebooks
Path: blob/master/GitHub/GitHub_Create_pull_request.ipynb
2973 views
Kernel: Python 3

GitHub.png

GitHub - Create pull request

Give Feedback | Bug report

Tags: #github #pygithub #pullrequest #create #assign #issue

Last update: 2023-04-12 (Created: 2023-03-09)

Description: This notebook creates a pull request using pygithub library.

Input

Import libraries

try: import github except: !pip install pygithub --user import github import naas

Setup Variables

  • token: GitHub token

  • repo: repository name

  • owner: repository owner

  • title: pull request title

  • body: pull request body

  • head: branch name where your changes are implemented

  • base: branch name where your changes will be merged into

token = naas.secret.get('GITHUB_TOKEN') or "YOUR_TOKEN" repo = "YOUR_REPO" owner = "YOUR_OWNER" title = "YOUR_TITLE" body = "YOUR_BODY" #To link your PR to an issue, you can add the following in your body 'This PR resolves {issue_html_url}' head = "YOUR_HEAD" base = "YOUR_BASE"

Model

Create Pull Request

Create a pull request with assignee and link to issue using pygithub library.

# Create a Github instance gh = github.Github(token) # Get the repository repo = gh.get_repo(f"{owner}/{repo}") # Create the pull request pull_request = repo.create_pull( title=title, body=body, head=head, base=base )

Output

Display result

# Display the pull request pull_request