Module: GitWand::GitHub::API::Commands::PullRequest
- Included in:
- GitWand::GitHub::API::Client
- Defined in:
- lib/git_wand/github/api/commands/pull_request.rb
Instance Method Summary collapse
-
#create_pull_request(owner:, repo:, title:, head:, base:, body:) ⇒ Object
developer.github.com/v3/pulls/#create-a-pull-request | Name | Type | Description | |——-|——–|————-| | title | string | Required. The title of the pull request.
- #create_pull_request_from_issue(owner:, repo:, head:, base:, issue:) ⇒ Object
- #get_pull_request(owner:, repo:, number:) ⇒ Object
-
#list_pull_requests(owner:, repo:, state: nil, head: nil, base: nil, sort: nil, direction: nil) ⇒ Object
List pull requests developer.github.com/v3/pulls/#list-pull-requests GET /repos/:owner/:repo/pulls Parameters | Name | Type | Description | |——|——|————-| | state | string | Either open, closed, or all to filter by state.
-
#merge_pull_request(owner:, repo:, number:, message:, squash: false) ⇒ Object
Response if merge was successful: 200 Response if merge cannot be performed: 405 Response if sha was provided and pull request head did not match: 409.
- #raw_create_pull_request(owner:, repo:, parameters:) ⇒ Object
Instance Method Details
#create_pull_request(owner:, repo:, title:, head:, base:, body:) ⇒ Object
developer.github.com/v3/pulls/#create-a-pull-request | Name | Type | Description | |——-|——–|————-| | title | string | Required. The title of the pull request. | | head | string | Required. The name of the branch where your changes are implemented. For cross-repository pull requests in the same network, namespace head with a user like this: username:branch. | | base | string | Required. The name of the branch you want the changes pulled into. This should be an existing branch on the current repository. You cannot submit a pull request to one repository that requests a merge to a base of another repository. | | body | string | The contents of the pull request. |
51 52 53 54 55 56 57 58 59 |
# File 'lib/git_wand/github/api/commands/pull_request.rb', line 51 def create_pull_request(owner:, repo:, title:, head:, base:, body:) parameters = { title: title, head: head, base: base, body: body, } raw_create_pull_request(owner: owner, repo: repo, parameters: parameters) end |
#create_pull_request_from_issue(owner:, repo:, head:, base:, issue:) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/git_wand/github/api/commands/pull_request.rb', line 61 def create_pull_request_from_issue(owner:, repo:, head:, base:, issue:) parameters = { head: head, base: base, issue: issue, } raw_create_pull_request(owner: owner, repo: repo, parameters: parameters) end |
#get_pull_request(owner:, repo:, number:) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/git_wand/github/api/commands/pull_request.rb', line 35 def get_pull_request(owner:, repo:, number:) response = get(resource: "repos/#{owner}/#{repo}/pulls/#{number}") result = Result.new result.success = response[:status][:code] == "200" result.body = response[:body] result.resource = Resource::PullRequest.build_from_api_result(result) result end |
#list_pull_requests(owner:, repo:, state: nil, head: nil, base: nil, sort: nil, direction: nil) ⇒ Object
List pull requests developer.github.com/v3/pulls/#list-pull-requests GET /repos/:owner/:repo/pulls Parameters | Name | Type | Description | |——|——|————-| | state | string | Either open, closed, or all to filter by state. Default: open | | head | string | Filter pulls by head user and branch name in the format of user:ref-name. Example: github:new-script-format. | | base | string | Filter pulls by base branch name. Example: gh-pages. | | sort | string | What to sort results by. Can be either created, updated, popularity (comment count) or long-running (age, filtering by pulls updated in the last month). Default: created | | direction | string | The direction of the sort. Can be either asc or desc. Default: desc when sort is created or sort is not specified, otherwise asc. |
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/git_wand/github/api/commands/pull_request.rb', line 19 def list_pull_requests(owner:, repo:, state: nil, head: nil, base: nil, sort: nil, direction: nil) parameters = { } parameters[:state] = state if state parameters[:head] = head if head parameters[:base] = base if base parameters[:sort] = sort if sort parameters[:direction] = direction if direction response = get(resource: "repos/#{owner}/#{repo}/pulls", query_parameters: parameters) result = Result.new result.success = response[:status][:code] == "200" result.body = response[:body] result.resource = Resource::PullRequestList.build_from_api_result(result) result end |
#merge_pull_request(owner:, repo:, number:, message:, squash: false) ⇒ Object
Response if merge was successful: 200 Response if merge cannot be performed: 405 Response if sha was provided and pull request head did not match: 409
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/git_wand/github/api/commands/pull_request.rb', line 110 def merge_pull_request(owner:, repo:, number:, message:, squash: false) result = get_pull_request(owner: owner, repo: repo, number: number) pull_request = result.resource # TODO: handle errors while retrieving the resource parameters = { commit_message: , sha: pull_request.head_sha, squash: squash, } response = put(resource: "repos/#{owner}/#{repo}/pulls/#{number}/merge", parameters: parameters) result = Result.new result.success = response[:status][:code] == "200" result.body = response[:body] result end |
#raw_create_pull_request(owner:, repo:, parameters:) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/git_wand/github/api/commands/pull_request.rb', line 70 def raw_create_pull_request(owner:, repo:, parameters:) response = post(resource: "repos/#{owner}/#{repo}/pulls", parameters: parameters) result = Result.new result.success = response[:status][:code] == "201" result.body = response[:body] result.resource = Resource::PullRequest.build_from_api_result(result) result end |