Skip to content

Commit

Permalink
Update pull_requests.cr
Browse files Browse the repository at this point in the history
  • Loading branch information
GrantBirki authored Aug 12, 2024
1 parent 582a57d commit 76c411b
Showing 1 changed file with 252 additions and 3 deletions.
255 changes: 252 additions & 3 deletions src/octokit/client/pull_requests.cr
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,50 @@ module Octokit

alias_method :pull_requests, :pulls

# Create a pull request
#
# **See Also:**
# - [https://developer.github.com/v3/pulls/#create-a-pull-request](https://developer.github.com/v3/pulls/#create-a-pull-request)
#
# **Examples:**
#
# ```
# Octokit.create_pull_request("crystal-lang/crystal", "master", "new-branch", "Title", "Body")
# ```
def create_pull_request(repo : String, base : String, head : String, title : String, body : String, **options)
options = {base: base, head: head, title: title, body: body}.merge(options)
post "#{Repository.path repo}/pulls", {json: options}
end

# Create a pull request for an issue
#
# **See Also:**
# - [https://developer.github.com/v3/pulls/#create-a-pull-request](https://developer.github.com/v3/pulls/#create-a-pull-request)
#
# **Examples:**
#
# ```
# Octokit.create_pull_request_for_issue("crystal-lang/crystal", "master", "new-branch", 123)
# ```
def create_pull_request_for_issue(repo : String, base : String, head : String, issue : Int32, **options)
options = {base: base, head: head, issue: issue}.merge(options)
post "#{Repository.path repo}/pulls", {json: options}
end

# Update a pull request
#
# **See Also:**
# - [https://developer.github.com/v3/pulls/#update-a-pull-request](https://developer.github.com/v3/pulls/#update-a-pull-request)
#
# **Examples:**
#
# ```
# Octokit.update_pull_request("crystal-lang/crystal", 123, title: "New Title", body: "New Body")
# ```
def update_pull_request(repo : String, number : Int64, **options)
patch "#{Repository.path repo}/pulls/#{number}", {json: options}
end

# Close a pull request
#
# **See Also:**
Expand All @@ -68,9 +112,179 @@ module Octokit
# ```
# Octokit.close_pull_request("crystal-lang/crystal", 123)
# ```
# def close_pull_request(repo : String, number : Int64, **options)
# TODO
# end
def close_pull_request(repo : String, number : Int64, **options)
options = {state: "closed"}.merge(options)
patch "#{Repository.path repo}/pulls/#{number}", {json: options}
end

# List commits on a pull request
#
# **See Also:**
# - [https://developer.github.com/v3/pulls/#list-commits-on-a-pull-request](https://developer.github.com/v3/pulls/#list-commits-on-a-pull-request)
#
# **Examples:**
#
# ```
# Octokit.pull_request_commits("crystal-lang/crystal", 123)
# ```
def pull_request_commits(repo : String, number : Int64, **options) : Paginator(Commit)
paginate(
Commit,
"#{Repository.path(repo)}/pulls/#{number}/commits",
options: {params: options}
)
end

alias_method :pull_request_commits, :pull_commits

# List comments on a pull request
#
# **See Also:**
# - [https://developer.github.com/v3/pulls/comments/#list-comments-on-a-pull-request](https://developer.github.com/v3/pulls/comments/#list-comments-on-a-pull-request)
#
# **Examples:**
#
# ```
# Octokit.pull_requests_comments("crystal-lang/crystal", 123)
# ```
def pull_requests_comments(repo : String, number : Int64, **options) : Paginator(PullRequestComment)
paginate(
PullRequestComment,
"#{Repository.path(repo)}/pulls/#{number}/comments",
options: {params: options}
)
end

alias_method :pull_requests_comments, :reviews_comments

# List comments on a pull request
#
# **See Also:**
# - [https://developer.github.com/v3/pulls/comments/#list-comments-on-a-pull-request](https://developer.github.com/v3/pulls/comments/#list-comments-on-a-pull-request)
#
# **Examples:**
#
# ```
# Octokit.pull_request_comments("crystal-lang/crystal", 123)
# ```
def pull_request_comments(repo : String, number : Int64, **options) : Paginator(PullRequestComment)
paginate(
PullRequestComment,
"#{Repository.path(repo)}/pulls/#{number}/comments",
options: {params: options}
)
end

alias_method :pull_request_comments, :pull_comments
alias_method :pull_request_comments, :review_comments

# Get a single comment on a pull request
#
# **See Also:**
# - [https://developer.github.com/v3/pulls/comments/#get-a-single-comment](https://developer.github.com/v3/pulls/comments/#get-a-single-comment)
#
# **Examples:**
#
# ```
# Octokit.pull_request_comment("crystal-lang/crystal", 123, 456)
# ```
def pull_request_comment(repo : String, number : Int64, comment_id : Int64, **options)
get "#{Repository.path(repo)}/pulls/#{number}/comments/#{comment_id}", {params: options}
end

alias_method :pull_request_comment, :pull_comment
alias_method :pull_request_comment, :review_comment

# Create a comment on a pull request
#
# **See Also:**
# - [https://developer.github.com/v3/pulls/comments/#create-a-comment](https://developer.github.com/v3/pulls/comments/#create-a-comment)
#
# **Examples:**
#
# ```
# Octokit.create_pull_request_comment("crystal-lang/crystal", 123, "Comment body", "commit_id", "path", 1)
# ```
def create_pull_request_comment(repo : String, number : Int64, body : String, commit_id : String, path : String, position : Int32, **options)
options = {body: body, commit_id: commit_id, path: path, position: position}.merge(options)
post "#{Repository.path repo}/pulls/#{number}/comments", {json: options}
end

alias_method :create_pull_request_comment, :create_pull_comment
alias_method :create_pull_request_comment, :create_review_comment

# Create a reply to a comment on a pull request
#
# **See Also:**
# - [https://developer.github.com/v3/pulls/comments/#create-a-reply-to-a-comment](https://developer.github.com/v3/pulls/comments/#create-a-reply-to-a-comment)
#
# **Examples:**
#
# ```
# Octokit.create_pull_request_comment_reply("crystal-lang/crystal", 123, "Comment body", 456)
# ```
def create_pull_request_comment_reply(repo : String, number : Int64, body : String, in_reply_to : Int64, **options)
options = {body: body, in_reply_to: in_reply_to}.merge(options)
post "#{Repository.path repo}/pulls/#{number}/comments", {json: options}
end

alias_method :create_pull_request_comment_reply, :create_pull_reply
alias_method :create_pull_request_comment_reply, :create_review_reply

# Update a comment on a pull request
#
# **See Also:**
# - [https://developer.github.com/v3/pulls/comments/#update-a-comment](https://developer.github.com/v3/pulls/comments/#update-a-comment)
#
# **Examples:**
#
# ```
# Octokit.update_pull_request_comment("crystal-lang/crystal", 123, 456, "New comment body")
# ```
def update_pull_request_comment(repo : String, number : Int64, comment_id : Int64, body : String, **options)
options = {body: body}.merge(options)
patch "#{Repository.path repo}/pulls/#{number}/comments/#{comment_id}", {json: options}
end

alias_method :update_pull_request_comment, :update_pull_comment
alias_method :update_pull_request_comment, :update_review_comment

# Delete a comment on a pull request
#
# **See Also:**
# - [https://developer.github.com/v3/pulls/comments/#delete-a-comment](https://developer.github.com/v3/pulls/comments/#delete-a-comment)
#
# **Examples:**
#
# ```
# Octokit.delete_pull_request_comment("crystal-lang/crystal", 123, 456)
# ```
def delete_pull_request_comment(repo : String, number : Int64, comment_id : Int64, **options)
delete "#{Repository.path repo}/pulls/#{number}/comments/#{comment_id}", {params: options}
end

alias_method :delete_pull_request_comment, :delete_pull_comment
alias_method :delete_pull_request_comment, :delete_review_comment

# List files on a pull request
#
# **See Also:**
# - [https://developer.github.com/v3/pulls/#list-pull-requests-files](https://developer.github.com/v3/pulls/#list-pull-requests-files)
#
# **Examples:**
#
# ```
# Octokit.pull_request_files("crystal-lang/crystal", 123)
# ```
def pull_request_files(repo : String, number : Int64, **options) : Paginator(PullRequestFile)
paginate(
PullRequestFile,
"#{Repository.path(repo)}/pulls/#{number}/files",
options: {params: options}
)
end

alias_method :pull_request_files, :pull_files

# Update a pull request branch
#
Expand All @@ -88,6 +302,41 @@ module Octokit
)
end

# Merge a pull request
#
# **See Also:**
# - [https://developer.github.com/v3/pulls/#merge-a-pull-request](https://developer.github.com/v3/pulls/#merge-a-pull-request)
#
# **Examples:**
#
# ```
# Octokit.merge_pull_request("crystal-lang/crystal", 123, "Commit message")
# ```
def merge_pull_request(repo : String, number : Int64, commit_message : String, **options)
options = {commit_message: commit_message}.merge(options)
put "#{Repository.path repo}/pulls/#{number}/merge", {json: options}
end

# Check if a pull request has been merged
#
# **See Also:**
# - [https://developer.github.com/v3/pulls/#get-if-a-pull-request-has-been-merged](https://developer.github.com/v3/pulls/#get-if-a-pull-request-has-been-merged)
#
# **Examples:**
#
# ```
# Octokit.pull_merged?("crystal-lang/crystal", 123)
# ```
def pull_merged?(repo : String, number : Int64, **options) : Bool
boolean_from_response(
:get,
"#{Repository.path(repo)}/pulls/#{number}/merge",
options: {params: options}
)
end

alias_method :pull_merged?, :pull_request_merged?

# Validate options for filtering issues and log a warning if an incorrect
# filter is used.
protected def validate_options(options)
Expand Down

0 comments on commit 76c411b

Please sign in to comment.