Skip to content
lstahlman edited this page Oct 12, 2016 · 2 revisions

Pull Requests

List pull requests for a repository

GET /repos/:owner/:repo/pulls
Response
Status: 200 OK
Content-Type: application/json
[
{
  "id": 84,
  "number": 7,
  "user": {
    "id": 3,
    "username": "user3",
    "full_name": "Some User",
    "email": "[email protected]",
    "avatar_url": "https://secure.gravatar.com/avatar/30fa571d2f85bb1c5a5b574d5c5c5005"
  },
  "title": "Bugfix for XYZ",
  "body": "Fixes bug XYZ",
  "labels": [],
  "milestone": null,
  "assignee": null,
  "state": "closed",
  "comments": 0,
  "html_url": "http://example.com/user1/gogs/pulls/7",
  "mergeable": true,
  "merged": true,
  "merged_at": "2016-10-11T12:48:36-07:00",
  "merge_commit_sha": "a857e30a8af1bbbb43f065e1fc0fb1665036e95f",
  "merged_by": {
    "id": 1,
    "username": "user1",
    "full_name": "",
    "email": "[email protected]",
    "avatar_url": "https://secure.gravatar.com/avatar/30fa571d2f85bb1c5a5b574d5c5c5005"
  },
  "base": {
    "name": "devel",
    "repo_id": 25,
    "repo": {
      "id": 25,
      "owner": {
        "id": 1,
        "username": "user1",
        "full_name": "Some User",
        "email": "[email protected]",
        "avatar_url": "https://secure.gravatar.com/avatar/30fa571d2f85bb1c5a5b574d5c5c5005"
      },
      "name": "gogs",
      "full_name": "user1/gogs",
      "description": "",
      "private": false,
      "fork": false,
      "html_url": "http://example.com/user1/gogs",
      "ssh_url": "[email protected]:user1/gogs.git",
      "clone_url": "http://example.com/user1/gogs.git",
      "website": "",
      "stars_count": 0,
      "forks_count": 1,
      "watchers_count": 1,
      "open_issues_count": 1,
      "default_branch": "master",
      "created_at": "2016-08-09T23:00:42-07:00",
      "updated_at": "2016-08-09T23:08:04-07:00"
    }
  },
  "head": {
    "name": "bugfix-XYZ",
    "repo_id": 131,
    "repo": {
      "id": 131,
      "owner": {
        "id": 3,
        "username": "user3",
        "full_name": "Some User",
        "email": "[email protected]",
        "avatar_url": "https://secure.gravatar.com/avatar/30fa571d2f85bb1c5a5b574d5c5c5005"
      },
      "name": "gogs",
      "full_name": "user3/gogs",
      "description": "",
      "private": false,
      "fork": true,
      "html_url": "http://example.com/user3/gogs",
      "ssh_url": "[email protected]/user3/gogs.git",
      "clone_url": "http://example.com/user3/gogs.git",
      "website": "",
      "stars_count": 0,
      "forks_count": 0,
      "watchers_count": 1,
      "open_issues_count": 0,
      "default_branch": "master",
      "created_at": "2016-10-11T10:38:08-07:00",
      "updated_at": "2016-10-11T10:38:45-07:00"
    }
  },
  "merge_base": "66ef302b17e1d001043d8a9bb4fa93295a2d33c3"
}
]

Get a single pull request

GET /repos/:owner/:repo/pulls/:id
Response
Status: 200 OK
Content-Type: application/json
{
  "id": 84,
  "number": 7,
  "user": {
    "id": 3,
    "username": "user3",
    "full_name": "Some User",
    "email": "[email protected]",
    "avatar_url": "https://secure.gravatar.com/avatar/30fa571d2f85bb1c5a5b574d5c5c5005"
  },
  "title": "Bugfix for XYZ",
  "body": "Fixes bug XYZ",
  "labels": [],
  "milestone": null,
  "assignee": null,
  "state": "closed",
  "comments": 0,
  "html_url": "http://example.com/user1/gogs/pulls/7",
  "mergeable": true,
  "merged": true,
  "merged_at": "2016-10-11T12:48:36-07:00",
  "merge_commit_sha": "a857e30a8af1bbbb43f065e1fc0fb1665036e95f",
  "merged_by": {
    "id": 1,
    "username": "user1",
    "full_name": "",
    "email": "[email protected]",
    "avatar_url": "https://secure.gravatar.com/avatar/30fa571d2f85bb1c5a5b574d5c5c5005"
  },
  "base": {
    "name": "devel",
    "repo_id": 25,
    "repo": {
      "id": 25,
      "owner": {
        "id": 1,
        "username": "user1",
        "full_name": "Some User",
        "email": "[email protected]",
        "avatar_url": "https://secure.gravatar.com/avatar/30fa571d2f85bb1c5a5b574d5c5c5005"
      },
      "name": "gogs",
      "full_name": "user1/gogs",
      "description": "",
      "private": false,
      "fork": false,
      "html_url": "http://example.com/user1/gogs",
      "ssh_url": "[email protected]:user1/gogs.git",
      "clone_url": "http://example.com/user1/gogs.git",
      "website": "",
      "stars_count": 0,
      "forks_count": 1,
      "watchers_count": 1,
      "open_issues_count": 1,
      "default_branch": "master",
      "created_at": "2016-08-09T23:00:42-07:00",
      "updated_at": "2016-08-09T23:08:04-07:00"
    }
  },
  "head": {
    "name": "bugfix-XYZ",
    "repo_id": 131,
    "repo": {
      "id": 131,
      "owner": {
        "id": 3,
        "username": "user3",
        "full_name": "Some User",
        "email": "[email protected]",
        "avatar_url": "https://secure.gravatar.com/avatar/30fa571d2f85bb1c5a5b574d5c5c5005"
      },
      "name": "gogs",
      "full_name": "user3/gogs",
      "description": "",
      "private": false,
      "fork": true,
      "html_url": "http://example.com/user3/gogs",
      "ssh_url": "[email protected]/user3/gogs.git",
      "clone_url": "http://example.com/user3/gogs.git",
      "website": "",
      "stars_count": 0,
      "forks_count": 0,
      "watchers_count": 1,
      "open_issues_count": 0,
      "default_branch": "master",
      "created_at": "2016-10-11T10:38:08-07:00",
      "updated_at": "2016-10-11T10:38:45-07:00"
    }
  },
  "merge_base": "66ef302b17e1d001043d8a9bb4fa93295a2d33c3"
}

Create a pull request

POST /repos/:owner/:repo/pulls
Parameters
Name Type Description
head string Required Head branch
base string Required Base branch
title string Required Title of the pull request
body string Required Body of the pull request
assignee string Username for the user that this pull request should be assigned to. NOTE: Only users with write access can set the assignee for new pull requests. The assignee is silently dropped otherwise.
milestone int The ID of the milestone to associate this pull request with. NOTE: Only users with write access can set the milestone for new pull requests. The milestone is silently dropped otherwise.
labels array of int Label IDs to associate with this pull request. NOTE: Only users with write access can set labels for new pull requests. Labels are silently dropped otherwise.
Example
{
  "head": "bugfix-XYZ",
  "base": "develop",
  "title": "Bugfix for XYZ",
  "body": "Fixes bug XYZ",
  "assignee": "user3",
  "milestone": 1,
  "labels": [2, 5]
}
Response

If a pull request already exists for the same head & base:

Status: 409 Conflict

Otherwise if the pull request is created:

Status: 201 Created
Content-Type: application/json
{
  "id": 84,
  "number": 7,
  "user": {
    "id": 3,
    "username": "user3",
    "full_name": "Some User",
    "email": "[email protected]",
    "avatar_url": "https://secure.gravatar.com/avatar/30fa571d2f85bb1c5a5b574d5c5c5005"
  },
  "title": "Bugfix for XYZ",
  "body": "Fixes bug XYZ",
  "labels": [],
  "milestone": null,
  "assignee": null,
  "state": "open",
  "comments": 0,
  "html_url": "http://example.com/user1/gogs/pulls/7",
  "mergeable": true,
  "merged": false,
  "merged_at": null,
  "merge_commit_sha": null,
  "merged_by": null,
  "base": {
    "name": "devel",
    "repo_id": 25,
    "repo": {
      "id": 25,
      "owner": {
        "id": 1,
        "username": "user1",
        "full_name": "Some User",
        "email": "[email protected]",
        "avatar_url": "https://secure.gravatar.com/avatar/30fa571d2f85bb1c5a5b574d5c5c5005"
      },
      "name": "gogs",
      "full_name": "user1/gogs",
      "description": "",
      "private": false,
      "fork": false,
      "html_url": "http://example.com/user1/gogs",
      "ssh_url": "[email protected]:user1/gogs.git",
      "clone_url": "http://example.com/user1/gogs.git",
      "website": "",
      "stars_count": 0,
      "forks_count": 1,
      "watchers_count": 1,
      "open_issues_count": 1,
      "default_branch": "master",
      "created_at": "2016-08-09T23:00:42-07:00",
      "updated_at": "2016-08-09T23:08:04-07:00"
    }
  },
  "head": {
    "name": "bugfix-XYZ",
    "repo_id": 131,
    "repo": {
      "id": 131,
      "owner": {
        "id": 3,
        "username": "user3",
        "full_name": "Some User",
        "email": "[email protected]",
        "avatar_url": "https://secure.gravatar.com/avatar/30fa571d2f85bb1c5a5b574d5c5c5005"
      },
      "name": "gogs",
      "full_name": "user3/gogs",
      "description": "",
      "private": false,
      "fork": true,
      "html_url": "http://example.com/user3/gogs",
      "ssh_url": "[email protected]/user3/gogs.git",
      "clone_url": "http://example.com/user3/gogs.git",
      "website": "",
      "stars_count": 0,
      "forks_count": 0,
      "watchers_count": 1,
      "open_issues_count": 0,
      "default_branch": "master",
      "created_at": "2016-10-11T10:38:08-07:00",
      "updated_at": "2016-10-11T10:38:45-07:00"
    }
  },
  "merge_base": "66ef302b17e1d001043d8a9bb4fa93295a2d33c3"
}

Edit a pull request

Repository owners and users with write access can perform this action.

PATCH /repos/:owner/:repo/pulls/:index
Parameters
Name Type Description
title string Required Title of the pull request
body string Required Body of the pull request
assignee string Username for the user that this pull request should be assigned to. NOTE: Only users with write access can set the assignee for new pull requests. The assignee is silently dropped otherwise.
milestone int The ID of the milestone to associate this pull request with. NOTE: Only users with write access can set the milestone for new pull requests. The milestone is silently dropped otherwise.
labels array of int Label IDs to associate with this pull request. NOTE: Only users with write access can set labels for new pull requests. Labels are silently dropped otherwise.

If a parameter is empty, that part of the pull request will remain unchanged

Example
{
  "body":"Fixes bug XYZ. Updated PR to reflect feedback."
}
Response
Status: 200 OK
Content-Type: application/json
{
  "id": 84,
  "number": 7,
  "user": {
    "id": 3,
    "username": "user3",
    "full_name": "Some User",
    "email": "[email protected]",
    "avatar_url": "https://secure.gravatar.com/avatar/30fa571d2f85bb1c5a5b574d5c5c5005"
  },
  "title": "Bugfix for XYZ",
  "body": "Fixes bug XYZ. Updated PR to reflect feedback.",
  "labels": [],
  "milestone": null,
  "assignee": null,
  "state": "open",
  "comments": 0,
  "html_url": "http://example.com/user1/gogs/pulls/7",
  "mergeable": true,
  "merged": false,
  "merged_at": null,
  "merge_commit_sha": null,
  "merged_by": null,
  "base": {
    "name": "devel",
    "repo_id": 25,
    "repo": {
      "id": 25,
      "owner": {
        "id": 1,
        "username": "user1",
        "full_name": "Some User",
        "email": "[email protected]",
        "avatar_url": "https://secure.gravatar.com/avatar/30fa571d2f85bb1c5a5b574d5c5c5005"
      },
      "name": "gogs",
      "full_name": "user1/gogs",
      "description": "",
      "private": false,
      "fork": false,
      "html_url": "http://example.com/user1/gogs",
      "ssh_url": "[email protected]:user1/gogs.git",
      "clone_url": "http://example.com/user1/gogs.git",
      "website": "",
      "stars_count": 0,
      "forks_count": 1,
      "watchers_count": 1,
      "open_issues_count": 1,
      "default_branch": "master",
      "created_at": "2016-08-09T23:00:42-07:00",
      "updated_at": "2016-08-09T23:08:04-07:00"
    }
  },
  "head": {
    "name": "bugfix-XYZ",
    "repo_id": 131,
    "repo": {
      "id": 131,
      "owner": {
        "id": 3,
        "username": "user3",
        "full_name": "Some User",
        "email": "[email protected]",
        "avatar_url": "https://secure.gravatar.com/avatar/30fa571d2f85bb1c5a5b574d5c5c5005"
      },
      "name": "gogs",
      "full_name": "user3/gogs",
      "description": "",
      "private": false,
      "fork": true,
      "html_url": "http://example.com/user3/gogs",
      "ssh_url": "[email protected]/user3/gogs.git",
      "clone_url": "http://example.com/user3/gogs.git",
      "website": "",
      "stars_count": 0,
      "forks_count": 0,
      "watchers_count": 1,
      "open_issues_count": 0,
      "default_branch": "master",
      "created_at": "2016-10-11T10:38:08-07:00",
      "updated_at": "2016-10-11T10:38:45-07:00"
    }
  },
  "merge_base": "66ef302b17e1d001043d8a9bb4fa93295a2d33c3"
}

Merge a Pull Request

Only users with write access to a repository can perform this action.

POST /repos/:owner/:repo/pulls/:id/merge
Response

Success:

Status: 200 OK

Failed to auto-merge or PR already merged:

Status: 405 Method Not Allowed

Failure on attempt to merge a closed PR:

Status: 404 Not Found

All other errors:

Status: 500 Internal Server Error

Check if a Pull Request is Merged

GET /repos/:owner/:repo/pulls/:id/merge
Response

If merged:

Status: 204 No Content

If not merged:

Status: 404 Not Found
Clone this wiki locally