Pull requests

See the official GitHub API v2 documentation for pull requests.

class github2.pull_requests.PullRequest(type)[source]

Pull request container.

New in version 0.5.0.

diff_url

The URL to the unified diff.

title

The text of the pull request title.

base

The base repo

issue_user

The user who created the pull request.

discussion

Discussion thread for the pull request.

issue_updated_at

The date the issue for this pull request was last updated.

updated_at

The date when this pull request was last updated.

labels

A list of labels attached to the pull request.

mergeable

Whether the pull request can be merge cleanly

position

Floating point position of the pull request.

votes

Number of votes for this request.

number

Number of this request.

created_at

The date when this pull request was created.

closed_at

The date when this pull request was closed

comments

Number of comments made on this request.

user

The owner of the repo.

issue_created_at

The date the issue for this pull request was opened.

patch_url

The URL to the downloadable patch.

state

The pull request state

body

The text of the body.

html_url

The URL to the pull request.

head

The head of the pull request

class github2.pull_requests.PullRequests(type)[source]

GitHub API pull request functionality.

New in version 0.5.0.

create(project, base, head, title=None, body=None, issue=None)[source]

Create a new pull request.

Pull requests can be created from scratch, or attached to an existing issue. If an issue parameter is supplied the pull request is attached to that issue, else a new pull request is created.

Parameters:
  • project (str) – the GitHub project to send the pull request to
  • base (str) – branch changes should be pulled into
  • head (str) – branch of the changes to be pulled
  • title (str) – title for pull request
  • body (str) – optional body for pull request
  • issue (str) – existing issue to attach pull request to
list(project, state='open', page=1)[source]

List all pull requests for a project.

Parameters:
  • project (str) – GitHub project
  • state (str) – can be either open or closed
  • page (int) – optional page number
show(project, number)[source]

Show a single pull request.

Parameters:
  • project (str) – GitHub project
  • number (int) – pull request number in the GitHub database

Examples

Listing pull requests

>>> results = github.pull_requests.list("ask/python-github2")

By default the first page of results is returned, you can return further results with the page parameter:

>>> results = github.pull_requests.list("ask/python-github2", page=2)

View a pull request

>>> request = github.pull_requests.show("ask/python-github2", 28)
>>> pull.body
'This implements the github API pull requests functionality. '

Open pull request

To open a new pull request against the ask/python-github2 project:

>>> pull = github.pull_requests.create("ask/python-github2", "master",
...                                    "JNRowe:my_new_branch",
...                                    title="Fancy features")
>>> pull.number
4

This creates a pull request for changes in JNRowe‘s my_new_branch and asks for it to be merged to ask‘s master branch.

To attach code to an existing issue and make it a pull request:

>>> pull = github.pull_requests.create("ask/python-github2", "master",
...                                    "JNRowe:my_new_branch",
...                                    issue=4)

Note

You can use any tree-ish for the head argument, you are not restricted to symbolic references.

Table Of Contents

Previous topic

Issues

Next topic

Network

This Page