From 4e117b0d2d057cac2d9a8420e85ad30adb04058d Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Sun, 11 Aug 2024 17:53:35 -0700 Subject: [PATCH 01/32] init working `pull_requests()` method --- src/octokit/client/pull_requests.cr | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/octokit/client/pull_requests.cr b/src/octokit/client/pull_requests.cr index e69de29b..f1c59d4b 100644 --- a/src/octokit/client/pull_requests.cr +++ b/src/octokit/client/pull_requests.cr @@ -0,0 +1,37 @@ +require "uri" +require "../models/repos" +require "../models/pulls" + +module Octokit + class Client + # Methods for the Pull Requests API + # + # All "repo" params are constructed in the format of `/` + # + # **See Also:** + # - [https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28](https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28) + + module PullRequests + # :nodoc: + alias Repository = Models::Repository + # :nodoc: + alias PullRequest = Octokit::Models::PullRequest + + # List pull requests for a repository + # + # **See Also:** + # - [https://developer.github.com/v3/pulls/#list-pull-requests](https://developer.github.com/v3/pulls/#list-pull-requests) + # + # **Examples:** + # + # ``` + # Octokit.pull_requests("crystal-lang/crystal") + # ``` + def pull_requests(repo : String, **options) : Paginator(PullRequest) + paginate PullRequest, "#{Repository.path(repo)}/pulls", **options + end + + alias_method :pull_requests, :pulls + end + end +end From a1ed2098e664429604683d65b9a36bb2f8c4d326 Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Sun, 11 Aug 2024 17:54:02 -0700 Subject: [PATCH 02/32] update PullRequest model --- src/octokit/client.cr | 1 + src/octokit/models/pulls.cr | 45 ++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/octokit/client.cr b/src/octokit/client.cr index 21b31698..ce68c142 100644 --- a/src/octokit/client.cr +++ b/src/octokit/client.cr @@ -110,6 +110,7 @@ module Octokit include Octokit::Client::Issues include Octokit::Client::Markdown include Octokit::Client::PubSubHubbub + include Octokit::Client::PullRequests include Octokit::Client::Users include Octokit::Client::RateLimit include Octokit::Client::Repositories diff --git a/src/octokit/models/pulls.cr b/src/octokit/models/pulls.cr index 32b86360..0e698318 100644 --- a/src/octokit/models/pulls.cr +++ b/src/octokit/models/pulls.cr @@ -1,3 +1,6 @@ +require "../core_ext/time" +require "./issue_labels" + module Octokit module Models struct PullRequest @@ -6,24 +9,24 @@ module Octokit number: Int32, state: String, title: String, - body: String, + body: String?, created_at: {type: Time, converter: Time::ISO8601Converter}, updated_at: {type: Time, converter: Time::ISO8601Converter}, - closed_at: String, - merged_at: String, - labels: Array(Label), + closed_at: String?, + merged_at: String?, + labels: Array(Label)?, user: User, draft: Bool, - merged: Bool, - mergeable: Bool, - mergeable_state: String, - merged_by: String, + merged: Bool?, + mergeable: Bool?, + mergeable_state: String?, + merged_by: String?, merge_commit_sha: String, - comments: Int32, - commits: Int32, - additions: Int32, - deletions: Int32, - changed_files: Int32, + comments: Int32?, + commits: Int32?, + additions: Int32?, + deletions: Int32?, + changed_files: Int32?, url: String, html_url: String, issue_url: String, @@ -33,22 +36,22 @@ module Octokit commits_url: String, comments_url: String, review_comment_url: String, - review_comments: Int32, - assignee: User, - assignees: Array(User), - milestone: Milestone, - maintainer_can_modify: Bool, + review_comments: Int32?, + assignee: User?, + assignees: Array(User)?, + milestone: Milestone?, + maintainer_can_modify: Bool?, author_association: String, node_id: String, requested_reviewers: Array(User), requested_teams: Array(Team), - links: PRLinks, + links: PRLinks?, head: PullRequestBranch, base: PullRequestBranch, - active_lock_reason: String + active_lock_reason: String? ) end @@ -76,7 +79,7 @@ module Octokit label: String, ref: String, sha: String, - repo: Repository, + repo: Repository?, user: User ) end From ef5c819b441708e737f132d3d1bcb8e0f70c083a Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Sun, 11 Aug 2024 18:26:00 -0700 Subject: [PATCH 03/32] fix the logger --- src/octokit/warnable.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octokit/warnable.cr b/src/octokit/warnable.cr index c8f5c203..db829c9f 100644 --- a/src/octokit/warnable.cr +++ b/src/octokit/warnable.cr @@ -5,7 +5,7 @@ module Octokit # OCTOKIT_SILENT is set to true. def octokit_warn(message) unless !!ENV["OCTOKIT_SILENT"]? - Octokit.logger.warn(message) + @logger.warn { message } end end end From f70e5713ac04db53109ef6563ed00d746b0e5704 Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Sun, 11 Aug 2024 18:27:04 -0700 Subject: [PATCH 04/32] add `validate_options()` method for PullRequests --- src/octokit/client/pull_requests.cr | 47 ++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/octokit/client/pull_requests.cr b/src/octokit/client/pull_requests.cr index f1c59d4b..0de9bcc8 100644 --- a/src/octokit/client/pull_requests.cr +++ b/src/octokit/client/pull_requests.cr @@ -17,6 +17,18 @@ module Octokit # :nodoc: alias PullRequest = Octokit::Models::PullRequest + # Valid filters for PullRequests + FILTERS = ["all", "assigned", "created", "mentioned", "subscribed"] + + # Valid states for PullRequests + STATES = ["all", "open", "closed"] + + # Valid sort for PullRequests + SORTS = ["created", "updated", "comments"] + + # Valid directions in which to sort PullRequests + DIRECTIONS = ["asc", "desc"] + # List pull requests for a repository # # **See Also:** @@ -28,10 +40,43 @@ module Octokit # Octokit.pull_requests("crystal-lang/crystal") # ``` def pull_requests(repo : String, **options) : Paginator(PullRequest) - paginate PullRequest, "#{Repository.path(repo)}/pulls", **options + validate_options(options) + paginate( + PullRequest, + "#{Repository.path(repo)}/pulls", + options: {json: options} + ) end alias_method :pull_requests, :pulls + + # Validate options for filtering issues and log a warning if an incorrect + # filter is used. + protected def validate_options(options) + if filter = options[:filter]? + unless FILTERS.includes?(filter.to_s) + octokit_warn "'#{filter}' is not a valid Issue filter. Valid values are: #{FILTERS}" + end + end + + if state = options[:state]? + unless STATES.includes?(state.to_s) + octokit_warn "'#{state}' is not a valid Issue state. Valid values are: #{STATES}" + end + end + + if sort = options[:sort]? + unless SORTS.includes?(sort.to_s) + octokit_warn "'#{sort}' is not a valid Issue sort. Valid values are: #{SORTS}" + end + end + + if direction = options[:direction]? + unless DIRECTIONS.includes(direction.to_s) + octokit_warn "'#{direction}' is not a valid Issue sort direction. Valid values are: #{DIRECTIONS}" + end + end + end end end end From 12bdee586e939ba12450070096af6c05f654a5cc Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Sun, 11 Aug 2024 18:37:09 -0700 Subject: [PATCH 05/32] use `params` instead of `json` with PullRequest options fetching --- src/octokit/client/pull_requests.cr | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/octokit/client/pull_requests.cr b/src/octokit/client/pull_requests.cr index 0de9bcc8..0668348a 100644 --- a/src/octokit/client/pull_requests.cr +++ b/src/octokit/client/pull_requests.cr @@ -29,6 +29,13 @@ module Octokit # Valid directions in which to sort PullRequests DIRECTIONS = ["asc", "desc"] + # The default options for listing pull requests + DEFAULTS = { + state: "open", + sort: "created", + direction: "desc" + } + # List pull requests for a repository # # **See Also:** @@ -38,13 +45,14 @@ module Octokit # # ``` # Octokit.pull_requests("crystal-lang/crystal") + # Octokit.pull_requests("crystal-lang/crystal", state: "closed") # ``` def pull_requests(repo : String, **options) : Paginator(PullRequest) validate_options(options) paginate( PullRequest, "#{Repository.path(repo)}/pulls", - options: {json: options} + options: {params: DEFAULTS.merge(options)} ) end From cbb09023fb058098a9b0e561ddd6afe4c11e2cea Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Sun, 11 Aug 2024 18:44:26 -0700 Subject: [PATCH 06/32] lint --- src/octokit/client/pull_requests.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octokit/client/pull_requests.cr b/src/octokit/client/pull_requests.cr index 0668348a..ef1a3d98 100644 --- a/src/octokit/client/pull_requests.cr +++ b/src/octokit/client/pull_requests.cr @@ -45,7 +45,7 @@ module Octokit # # ``` # Octokit.pull_requests("crystal-lang/crystal") - # Octokit.pull_requests("crystal-lang/crystal", state: "closed") + # Octokit.pull_requests("crystal-lang/crystal", state: "closed") # ``` def pull_requests(repo : String, **options) : Paginator(PullRequest) validate_options(options) From a79930039b0d9342a8467cc9274644c56ba868db Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Sun, 11 Aug 2024 18:45:40 -0700 Subject: [PATCH 07/32] lint --- src/octokit/client/pull_requests.cr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/octokit/client/pull_requests.cr b/src/octokit/client/pull_requests.cr index ef1a3d98..fedb35d0 100644 --- a/src/octokit/client/pull_requests.cr +++ b/src/octokit/client/pull_requests.cr @@ -31,9 +31,9 @@ module Octokit # The default options for listing pull requests DEFAULTS = { - state: "open", - sort: "created", - direction: "desc" + state: "open", + sort: "created", + direction: "desc", } # List pull requests for a repository From fc8bee3059f221ca8483c9b0c25cb77e30293f3b Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Sun, 11 Aug 2024 19:07:37 -0700 Subject: [PATCH 08/32] add `update_pull_request_branch()` method --- src/octokit/client/pull_requests.cr | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/octokit/client/pull_requests.cr b/src/octokit/client/pull_requests.cr index fedb35d0..3380beac 100644 --- a/src/octokit/client/pull_requests.cr +++ b/src/octokit/client/pull_requests.cr @@ -58,6 +58,36 @@ module Octokit alias_method :pull_requests, :pulls + # Close 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.close_pull_request("crystal-lang/crystal", 123) + # ``` + # def close_pull_request(repo : String, number : Int64, **options) + # TODO + # end + + # Update a pull request branch + # + # **See Also:** + # - [https://developer.github.com/v3/pulls/#update-a-pull-request-branch](https://developer.github.com/v3/pulls/#update-a-pull-request-branch) + # + # **Examples:** + # ``` + # Octokit.update_pull_request_branch("crystal-lang/crystal", 123) + # ``` + def update_pull_request_branch(repo : String, number : Int64, **options) : Bool + boolean_from_response( + :put, + "#{Repository.path(repo)}/pulls/#{number}/update-branch" + ) + end + # Validate options for filtering issues and log a warning if an incorrect # filter is used. protected def validate_options(options) From 73023faaaddc10f488d19f04a5ba409b26d40c57 Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Sun, 11 Aug 2024 19:08:04 -0700 Subject: [PATCH 09/32] update the `boolean_from_response()` status codes that are successful --- src/octokit/connection.cr | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/octokit/connection.cr b/src/octokit/connection.cr index b0d6fac7..8709ebbc 100644 --- a/src/octokit/connection.cr +++ b/src/octokit/connection.cr @@ -16,6 +16,9 @@ module Octokit # Header keys that can be passed in options hash to {#get},{#head} CONVENIENCE_HEADERS = Set{"accept", "content_type"} + # Successful status codes from PUT/POST/PATCH requests + SUCCESSFUL_STATUSES = [200, 201, 202, 204] + # Make a HTTP GET request def get(url, options = nil) request "get", url, make_options(options) @@ -134,7 +137,7 @@ module Octokit # Executes the request, checking if it was successful protected def boolean_from_response(method, path, options = nil) request(method, path, options) - @last_response.not_nil!.status_code == 204 + @last_response.not_nil!.status_code.in?(SUCCESSFUL_STATUSES) rescue Error::NotFound false end From 67e16f0ea233e74616eb36e41bb0481142635ad4 Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Sun, 11 Aug 2024 19:08:50 -0700 Subject: [PATCH 10/32] match octokit.rb status codes --- src/octokit/connection.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octokit/connection.cr b/src/octokit/connection.cr index 8709ebbc..89dfd2fa 100644 --- a/src/octokit/connection.cr +++ b/src/octokit/connection.cr @@ -17,7 +17,7 @@ module Octokit CONVENIENCE_HEADERS = Set{"accept", "content_type"} # Successful status codes from PUT/POST/PATCH requests - SUCCESSFUL_STATUSES = [200, 201, 202, 204] + SUCCESSFUL_STATUSES = [201, 202, 204] # Make a HTTP GET request def get(url, options = nil) From 582a57dc801ddb9e2678e4e7e48afde0b466e8ed Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Sun, 11 Aug 2024 19:09:05 -0700 Subject: [PATCH 11/32] lint --- src/octokit/client/pull_requests.cr | 4 ++-- src/octokit/connection.cr | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/octokit/client/pull_requests.cr b/src/octokit/client/pull_requests.cr index 3380beac..ebc16f2a 100644 --- a/src/octokit/client/pull_requests.cr +++ b/src/octokit/client/pull_requests.cr @@ -69,7 +69,7 @@ module Octokit # Octokit.close_pull_request("crystal-lang/crystal", 123) # ``` # def close_pull_request(repo : String, number : Int64, **options) - # TODO + # TODO # end # Update a pull request branch @@ -80,7 +80,7 @@ module Octokit # **Examples:** # ``` # Octokit.update_pull_request_branch("crystal-lang/crystal", 123) - # ``` + # ``` def update_pull_request_branch(repo : String, number : Int64, **options) : Bool boolean_from_response( :put, diff --git a/src/octokit/connection.cr b/src/octokit/connection.cr index 89dfd2fa..18494b5f 100644 --- a/src/octokit/connection.cr +++ b/src/octokit/connection.cr @@ -17,7 +17,7 @@ module Octokit CONVENIENCE_HEADERS = Set{"accept", "content_type"} # Successful status codes from PUT/POST/PATCH requests - SUCCESSFUL_STATUSES = [201, 202, 204] + SUCCESSFUL_STATUSES = [201, 202, 204] # Make a HTTP GET request def get(url, options = nil) From 76c411b9c9a771d692375d012ea08311b3f1dd8a Mon Sep 17 00:00:00 2001 From: Grant Birkinbine Date: Sun, 11 Aug 2024 21:34:20 -0700 Subject: [PATCH 12/32] Update pull_requests.cr --- src/octokit/client/pull_requests.cr | 255 +++++++++++++++++++++++++++- 1 file changed, 252 insertions(+), 3 deletions(-) diff --git a/src/octokit/client/pull_requests.cr b/src/octokit/client/pull_requests.cr index ebc16f2a..aba98244 100644 --- a/src/octokit/client/pull_requests.cr +++ b/src/octokit/client/pull_requests.cr @@ -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:** @@ -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 # @@ -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) From 14432ad157752544b5f2ca79f4b1de7b1d27739c Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Sun, 11 Aug 2024 22:54:59 -0700 Subject: [PATCH 13/32] handle edge cases where all results fit on a single page --- src/octokit/connection.cr | 10 ++++++---- src/octokit/models/commits.cr | 22 +++++++++++----------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/octokit/connection.cr b/src/octokit/connection.cr index 18494b5f..c17df3ed 100644 --- a/src/octokit/connection.cr +++ b/src/octokit/connection.cr @@ -345,17 +345,19 @@ module Octokit # Utility method to set the `@total_pages` variable. private def set_total_pages! - return 0 if @client.last_response.nil? + return @total_pages = 0 if @client.last_response.nil? if links = @client.last_response.try(&.links) - return 0 unless links["last"]? + unless links["last"]? + @total_pages = 1 + return + end if target = links["last"].target if match = target.match(/page=([0-9]+)/) @total_pages = match[1].to_i end - else end else - 0 + @total_pages = 1 end end end diff --git a/src/octokit/models/commits.cr b/src/octokit/models/commits.cr index ba5d5690..743752ec 100644 --- a/src/octokit/models/commits.cr +++ b/src/octokit/models/commits.cr @@ -12,24 +12,24 @@ module Octokit struct Commit Octokit.rest_model( sha: String, - author: CommitAuthor, - committer: CommitAuthor, - message: String, - tree: Tree, - parents: Array(Commit), - stats: CommitStats, + author: CommitAuthor?, + committer: CommitAuthor?, + message: String?, + tree: Tree?, + parents: Array(Commit)?, + stats: CommitStats?, html_url: String, url: String, - verification: SignatureVerification, - node_id: String + verification: SignatureVerification?, + node_id: String? ) end struct CommitAuthor Octokit.rest_model( - date: String, - name: String, - email: String, + date: String?, + name: String?, + email: String?, login: String ) From 2ac7b896a4bcceca6ac85d2df5d8fe4b937f763a Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Sun, 11 Aug 2024 22:55:11 -0700 Subject: [PATCH 14/32] add `Commit` model to PullRequests --- src/octokit/client/pull_requests.cr | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/octokit/client/pull_requests.cr b/src/octokit/client/pull_requests.cr index aba98244..33ffd5c3 100644 --- a/src/octokit/client/pull_requests.cr +++ b/src/octokit/client/pull_requests.cr @@ -1,6 +1,7 @@ require "uri" require "../models/repos" require "../models/pulls" +require "../models/commits" module Octokit class Client @@ -16,6 +17,8 @@ module Octokit alias Repository = Models::Repository # :nodoc: alias PullRequest = Octokit::Models::PullRequest + # :nodoc: + alias Commit = Octokit::Models::Commit # Valid filters for PullRequests FILTERS = ["all", "assigned", "created", "mentioned", "subscribed"] From ae03b3cf05a12e839c1bd2dcfaf01336e3fcb8f9 Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Sun, 11 Aug 2024 22:55:45 -0700 Subject: [PATCH 15/32] lint --- src/octokit/client/pull_requests.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octokit/client/pull_requests.cr b/src/octokit/client/pull_requests.cr index 33ffd5c3..e69be826 100644 --- a/src/octokit/client/pull_requests.cr +++ b/src/octokit/client/pull_requests.cr @@ -18,7 +18,7 @@ module Octokit # :nodoc: alias PullRequest = Octokit::Models::PullRequest # :nodoc: - alias Commit = Octokit::Models::Commit + alias Commit = Octokit::Models::Commit # Valid filters for PullRequests FILTERS = ["all", "assigned", "created", "mentioned", "subscribed"] From dc94e82d62846227edc1f3e31af9c2a5658eeee8 Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Sun, 11 Aug 2024 22:59:44 -0700 Subject: [PATCH 16/32] pull_comments model fixes --- src/octokit/client/pull_requests.cr | 7 +++++-- src/octokit/models/pull_comments.cr | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/octokit/client/pull_requests.cr b/src/octokit/client/pull_requests.cr index e69be826..f02b77dd 100644 --- a/src/octokit/client/pull_requests.cr +++ b/src/octokit/client/pull_requests.cr @@ -2,6 +2,7 @@ require "uri" require "../models/repos" require "../models/pulls" require "../models/commits" +require "../models/pull_comments" module Octokit class Client @@ -19,6 +20,8 @@ module Octokit alias PullRequest = Octokit::Models::PullRequest # :nodoc: alias Commit = Octokit::Models::Commit + # :nodoc: + alias PullRequestComment = Octokit::Models::PullRequestComment # Valid filters for PullRequests FILTERS = ["all", "assigned", "created", "mentioned", "subscribed"] @@ -140,8 +143,8 @@ module Octokit alias_method :pull_request_commits, :pull_commits - # List comments on a pull request - # + # List review comments on a pull request + # This method applies to pull request review comments # **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) # diff --git a/src/octokit/models/pull_comments.cr b/src/octokit/models/pull_comments.cr index bbb639cf..b71615c0 100644 --- a/src/octokit/models/pull_comments.cr +++ b/src/octokit/models/pull_comments.cr @@ -4,7 +4,7 @@ module Octokit Octokit.rest_model( id: Int64, node_id: String, - in_reply_to: Int64, + in_reply_to: Int64?, body: String, path: String, diff_hunk: String, From 819cc176845cf875047338dcdd10a295ae2513b8 Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Sun, 11 Aug 2024 23:19:43 -0700 Subject: [PATCH 17/32] fix `pull_request_comment()` it does not need the PR number --- src/octokit/client/pull_requests.cr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/octokit/client/pull_requests.cr b/src/octokit/client/pull_requests.cr index f02b77dd..ea203092 100644 --- a/src/octokit/client/pull_requests.cr +++ b/src/octokit/client/pull_requests.cr @@ -192,10 +192,10 @@ module Octokit # **Examples:** # # ``` - # Octokit.pull_request_comment("crystal-lang/crystal", 123, 456) + # Octokit.pull_request_comment("crystal-lang/crystal", 456) # ``` - def pull_request_comment(repo : String, number : Int64, comment_id : Int64, **options) - get "#{Repository.path(repo)}/pulls/#{number}/comments/#{comment_id}", {params: options} + def pull_request_comment(repo : String, comment_id : Int64, **options) + get "#{Repository.path(repo)}/pulls/comments/#{comment_id}", {params: options} end alias_method :pull_request_comment, :pull_comment From 38f4617be2d7c3eb40c5077fa19812880bc3ddcc Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Sun, 11 Aug 2024 23:19:56 -0700 Subject: [PATCH 18/32] lint --- src/octokit/client/pull_requests.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octokit/client/pull_requests.cr b/src/octokit/client/pull_requests.cr index ea203092..6a3e4b0b 100644 --- a/src/octokit/client/pull_requests.cr +++ b/src/octokit/client/pull_requests.cr @@ -21,7 +21,7 @@ module Octokit # :nodoc: alias Commit = Octokit::Models::Commit # :nodoc: - alias PullRequestComment = Octokit::Models::PullRequestComment + alias PullRequestComment = Octokit::Models::PullRequestComment # Valid filters for PullRequests FILTERS = ["all", "assigned", "created", "mentioned", "subscribed"] From fb9ffb34ca4679dbf706d6b43afd97b2cc5d5ef4 Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Mon, 12 Aug 2024 09:27:13 -0700 Subject: [PATCH 19/32] update `create_pull_request_comment` --- src/octokit/client/pull_requests.cr | 33 +++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/octokit/client/pull_requests.cr b/src/octokit/client/pull_requests.cr index 6a3e4b0b..e296c861 100644 --- a/src/octokit/client/pull_requests.cr +++ b/src/octokit/client/pull_requests.cr @@ -206,13 +206,38 @@ module Octokit # **See Also:** # - [https://developer.github.com/v3/pulls/comments/#create-a-comment](https://developer.github.com/v3/pulls/comments/#create-a-comment) # + # repo (String) — A GitHub repository + # number (Integer) — Pull request number + # body (String) — Comment content + # commit_id (String) — Sha of the commit to comment on + # path (String) — Relative path of the file to comment on + # line (Integer) — Line number in the diff to comment on + # side (String) — Side of the diff that the comment applies to (LEFT or RIGHT) + # start_line (Integer) — Start line for multi-line comments + # start_side (String) — Start side for multi-line comments (LEFT or RIGHT) + # in_reply_to (Integer) — ID of the review comment to reply to + # subject_type (String) — Level at which the comment is targeted (line or file) + # # **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) + # Octokit.create_pull_request_comment("crystal-lang/crystal", 123, "Comment body", "commit_id", "path", 1, side: "RIGHT") + # ``` + def create_pull_request_comment( + repo : String, + number : Int64, + body : String, + commit_id : String, + path : String, + line : Int32, + **options + ) + options = { + body: body, + commit_id: commit_id, + path: path, + line: line, + }.merge(options) post "#{Repository.path repo}/pulls/#{number}/comments", {json: options} end From 61b6d03d0963f3b031abfff0eb4d8ef210929b24 Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Mon, 12 Aug 2024 09:32:52 -0700 Subject: [PATCH 20/32] remove `number` from URL in `update_pull_request_comment()` --- src/octokit/client/pull_requests.cr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/octokit/client/pull_requests.cr b/src/octokit/client/pull_requests.cr index e296c861..c18575c5 100644 --- a/src/octokit/client/pull_requests.cr +++ b/src/octokit/client/pull_requests.cr @@ -270,11 +270,11 @@ module Octokit # **Examples:** # # ``` - # Octokit.update_pull_request_comment("crystal-lang/crystal", 123, 456, "New comment body") + # Octokit.update_pull_request_comment("crystal-lang/crystal", 456, "New comment body") # ``` - def update_pull_request_comment(repo : String, number : Int64, comment_id : Int64, body : String, **options) + def update_pull_request_comment(repo : String, comment_id : Int64, body : String, **options) options = {body: body}.merge(options) - patch "#{Repository.path repo}/pulls/#{number}/comments/#{comment_id}", {json: options} + patch "#{Repository.path repo}/pulls/comments/#{comment_id}", {json: options} end alias_method :update_pull_request_comment, :update_pull_comment From 7f4d859707c1a71a4af99351eb365ee64fc93623 Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Mon, 12 Aug 2024 09:34:24 -0700 Subject: [PATCH 21/32] remove `number` from `delete_pull_request_comment()` --- src/octokit/client/pull_requests.cr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/octokit/client/pull_requests.cr b/src/octokit/client/pull_requests.cr index c18575c5..de846ed2 100644 --- a/src/octokit/client/pull_requests.cr +++ b/src/octokit/client/pull_requests.cr @@ -288,10 +288,10 @@ module Octokit # **Examples:** # # ``` - # Octokit.delete_pull_request_comment("crystal-lang/crystal", 123, 456) + # Octokit.delete_pull_request_comment("crystal-lang/crystal", 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} + def delete_pull_request_comment(repo : String, comment_id : Int64, **options) + delete "#{Repository.path repo}/pulls/comments/#{comment_id}", {params: options} end alias_method :delete_pull_request_comment, :delete_pull_comment From 58bb7291a912a78824b3452712628eb665abeb6a Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Mon, 12 Aug 2024 09:38:28 -0700 Subject: [PATCH 22/32] fix `pull_request_files()` method and data model --- src/octokit/client/pull_requests.cr | 7 +++++-- src/octokit/models/repo_commits.cr | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/octokit/client/pull_requests.cr b/src/octokit/client/pull_requests.cr index de846ed2..ec0edb14 100644 --- a/src/octokit/client/pull_requests.cr +++ b/src/octokit/client/pull_requests.cr @@ -3,6 +3,7 @@ require "../models/repos" require "../models/pulls" require "../models/commits" require "../models/pull_comments" +require "../models/repo_commits" module Octokit class Client @@ -22,6 +23,8 @@ module Octokit alias Commit = Octokit::Models::Commit # :nodoc: alias PullRequestComment = Octokit::Models::PullRequestComment + # :nodoc: + alias CommitFile = Octokit::Models::CommitFile # Valid filters for PullRequests FILTERS = ["all", "assigned", "created", "mentioned", "subscribed"] @@ -307,9 +310,9 @@ module Octokit # ``` # Octokit.pull_request_files("crystal-lang/crystal", 123) # ``` - def pull_request_files(repo : String, number : Int64, **options) : Paginator(PullRequestFile) + def pull_request_files(repo : String, number : Int64, **options) : Paginator(CommitFile) paginate( - PullRequestFile, + CommitFile, "#{Repository.path(repo)}/pulls/#{number}/files", options: {params: options} ) diff --git a/src/octokit/models/repo_commits.cr b/src/octokit/models/repo_commits.cr index a457e67d..4fcf97d6 100644 --- a/src/octokit/models/repo_commits.cr +++ b/src/octokit/models/repo_commits.cr @@ -37,7 +37,7 @@ module Octokit blob_url: String, raw_url: String, contents_url: String, - previous_filename: String + previous_filename: String? ) end From 6bbb00cb10a6b2c3a6baab606482291df5580545 Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Mon, 12 Aug 2024 09:56:12 -0700 Subject: [PATCH 23/32] ensure `make_options()` is called when running request though `boolean_from_response()` - also adding types --- src/octokit/connection.cr | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/octokit/connection.cr b/src/octokit/connection.cr index c17df3ed..9f8f942e 100644 --- a/src/octokit/connection.cr +++ b/src/octokit/connection.cr @@ -117,7 +117,7 @@ module Octokit @agent = nil end - protected def request(method, path, options = nil) + protected def request(method : Symbol, path : String, options = nil) path = File.join(endpoint, path) unless path.nil? || path.starts_with?("http") options = options ? @connection_options.merge(options) : @connection_options @last_response = response = agent.request(verb: method.to_s, uri: path, options: options) @@ -125,7 +125,7 @@ module Octokit response.body end - protected def request(method, path, options = nil, &) + protected def request(method : Symbol, path : String, options = nil, &) path = File.join(endpoint, path) unless path.nil? || path.starts_with?("http") options = options ? @connection_options.merge(options) : @connection_options @last_response = response = agent.request(verb: method, uri: path, options: options) @@ -135,8 +135,8 @@ module Octokit end # Executes the request, checking if it was successful - protected def boolean_from_response(method, path, options = nil) - request(method, path, options) + protected def boolean_from_response(method : Symbol, path : String, options = nil) + request(method, path, make_options(options)) @last_response.not_nil!.status_code.in?(SUCCESSFUL_STATUSES) rescue Error::NotFound false @@ -149,7 +149,7 @@ module Octokit end end - protected def make_options(options) + protected def make_options(options) : Halite::Options? return if options.nil? options.is_a?(Halite::Options) ? options : Halite::Options.new(**options) end From f019978506159342fc1f7efab6b5a5de79b34607 Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Mon, 12 Aug 2024 09:58:36 -0700 Subject: [PATCH 24/32] adding types to `boolean_from_response()` --- src/octokit/connection.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octokit/connection.cr b/src/octokit/connection.cr index 9f8f942e..0e3a28f3 100644 --- a/src/octokit/connection.cr +++ b/src/octokit/connection.cr @@ -135,7 +135,7 @@ module Octokit end # Executes the request, checking if it was successful - protected def boolean_from_response(method : Symbol, path : String, options = nil) + protected def boolean_from_response(method : Symbol, path : String, options : NamedTuple | Nil = nil) : Bool request(method, path, make_options(options)) @last_response.not_nil!.status_code.in?(SUCCESSFUL_STATUSES) rescue Error::NotFound From dc6a860fde87314bfde13b905e5bb5aab5313993 Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Mon, 12 Aug 2024 09:58:44 -0700 Subject: [PATCH 25/32] fmt --- src/octokit/client/pull_requests.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octokit/client/pull_requests.cr b/src/octokit/client/pull_requests.cr index ec0edb14..f666d1ea 100644 --- a/src/octokit/client/pull_requests.cr +++ b/src/octokit/client/pull_requests.cr @@ -24,7 +24,7 @@ module Octokit # :nodoc: alias PullRequestComment = Octokit::Models::PullRequestComment # :nodoc: - alias CommitFile = Octokit::Models::CommitFile + alias CommitFile = Octokit::Models::CommitFile # Valid filters for PullRequests FILTERS = ["all", "assigned", "created", "mentioned", "subscribed"] From 0c507d729419e1ef94919af925ec63ed731563aa Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Mon, 12 Aug 2024 10:00:37 -0700 Subject: [PATCH 26/32] fix `request` method types to be a Symbol or a String --- src/octokit/connection.cr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/octokit/connection.cr b/src/octokit/connection.cr index 0e3a28f3..7d06de3d 100644 --- a/src/octokit/connection.cr +++ b/src/octokit/connection.cr @@ -117,7 +117,7 @@ module Octokit @agent = nil end - protected def request(method : Symbol, path : String, options = nil) + protected def request(method : Symbol | String, path : String, options = nil) path = File.join(endpoint, path) unless path.nil? || path.starts_with?("http") options = options ? @connection_options.merge(options) : @connection_options @last_response = response = agent.request(verb: method.to_s, uri: path, options: options) @@ -125,7 +125,7 @@ module Octokit response.body end - protected def request(method : Symbol, path : String, options = nil, &) + protected def request(method : Symbol | String, path : String, options = nil, &) path = File.join(endpoint, path) unless path.nil? || path.starts_with?("http") options = options ? @connection_options.merge(options) : @connection_options @last_response = response = agent.request(verb: method, uri: path, options: options) From e6f8abe9af3fcd85d6ceb29b72b0ae2c1d271cc4 Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Mon, 12 Aug 2024 10:08:26 -0700 Subject: [PATCH 27/32] adding types and updating the logger --- src/octokit/connection.cr | 4 ++-- src/octokit/default.cr | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/octokit/connection.cr b/src/octokit/connection.cr index 7d06de3d..e9aed413 100644 --- a/src/octokit/connection.cr +++ b/src/octokit/connection.cr @@ -334,12 +334,12 @@ module Octokit # pages.fetch_all # pages.last? # => Bool # ``` - def last? + def last? : Bool @current_page == @total_pages end # Checks if the paginator is empty. - def empty? + def empty? : Bool @records.empty? end diff --git a/src/octokit/default.cr b/src/octokit/default.cr index 16fc2785..b18b80d2 100644 --- a/src/octokit/default.cr +++ b/src/octokit/default.cr @@ -36,7 +36,7 @@ module Octokit end # Default access token from ENV - def access_token + def access_token : String? ENV["OCTOKIT_ACCESS_TOKEN"]? end @@ -76,7 +76,7 @@ module Octokit end # Default options for `Halite::Options` - def connection_options + def connection_options : Halite::Options Halite::Options.new( headers: { accept: default_media_type, @@ -90,7 +90,7 @@ module Octokit end # Default GitHub username for Basic Auth from ENV - def login + def login : String? ENV["OCTOKIT_LOGIN"]? end @@ -100,12 +100,12 @@ module Octokit end # Default GitHub password for Basic Auth from ENV - def password + def password : String? ENV["OCTOKIT_PASSWORD"]? end # Default pagination page size from ENV - def per_page + def per_page : Int32? page_size = ENV["OCTOKIT_PER_PAGE"]? page_size.to_i if page_size end @@ -117,7 +117,7 @@ module Octokit end # Default SSL verify mode from ENV - def ssl_verify_mode + def ssl_verify_mode : Int32 # 0 is OpenSSL::SSL::NONE # 1 is OpenSSL::SSL::PEER # the standard default for SSL is PEER which requires a server certificate check on the client @@ -125,18 +125,19 @@ module Octokit end # Default User-Agent header string from ENV or `USER_AGENT` - def user_agent + def user_agent : String ENV["OCTOKIT_USER_AGENT"]? || USER_AGENT end # Default web endpoint from ENV or `WEB_ENDPOINT` - def web_endpoint + def web_endpoint : String ENV["OCTOKIT_WEB_ENDPOINT"]? || WEB_ENDPOINT end # Default logger def logger - Log.setup(:warn) + log_level = ENV["OCTOKIT_LOG_LEVEL"]?.to_s.upcase || "INFO".to_s.upcase + Log.setup(log_level) ::Log.for(self) end end From 4357a604e9947557093b207cec7f53f05463f968 Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Mon, 12 Aug 2024 10:25:02 -0700 Subject: [PATCH 28/32] comment --- src/octokit/client/pull_requests.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octokit/client/pull_requests.cr b/src/octokit/client/pull_requests.cr index f666d1ea..f2128331 100644 --- a/src/octokit/client/pull_requests.cr +++ b/src/octokit/client/pull_requests.cr @@ -147,7 +147,7 @@ module Octokit alias_method :pull_request_commits, :pull_commits # List review comments on a pull request - # This method applies to pull request review comments + # This method applies to pull request review comments. Pull request review comments are NOT the same as standard comments left on PRs - those are issue comments. # **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) # From 22014b327271a4734e32be9ebffd879de2fc02e2 Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Mon, 12 Aug 2024 10:25:11 -0700 Subject: [PATCH 29/32] patch can be `nil` --- src/octokit/models/repo_commits.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octokit/models/repo_commits.cr b/src/octokit/models/repo_commits.cr index 4fcf97d6..b7719997 100644 --- a/src/octokit/models/repo_commits.cr +++ b/src/octokit/models/repo_commits.cr @@ -33,7 +33,7 @@ module Octokit deletions: Int32, changes: Int32, status: String, - patch: String, + patch: String?, blob_url: String, raw_url: String, contents_url: String, From 077e1ff790b8faf425ae7873f1e5ac6d9da22e74 Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Mon, 12 Aug 2024 10:25:17 -0700 Subject: [PATCH 30/32] updated acceptance tests --- spec/acceptance/acceptance.cr | 92 +++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/spec/acceptance/acceptance.cr b/spec/acceptance/acceptance.cr index ca08987a..83cf34ac 100644 --- a/spec/acceptance/acceptance.cr +++ b/spec/acceptance/acceptance.cr @@ -4,6 +4,8 @@ require "spec" describe Octokit do github = Octokit.client + github.auto_paginate = true + github.per_page = 100 describe ".get" do context "when fetching info about the octokit.cr repo" do @@ -23,4 +25,94 @@ describe Octokit do end end end + + describe "pull requests" do + context "fetches closed pull requests" do + pulls = github.pull_requests("octokit-cr/octokit.cr", state: "closed").records + + it "should find at least one closed pull request" do + pulls.size.should be > 0 + end + + it "should fetch the title of the first closed pull request" do + pulls.first.title.should_not be_nil + end + end + + context "fetches pull request comments" do + comments = github.pull_request_comments("octokit-cr/octokit.cr", 15).records + + it "should find at least one comment" do + comments.size.should be > 0 + end + + it "should fetch the body of the first comment" do + comments.first.body.should_not be_nil + end + + it "should fetch the diff_hunk of the first comment" do + comments.first.diff_hunk.should_not be_nil + end + + it "should fetch the path of the first comment" do + comments.first.path.should_not be_nil + end + + it "should fetch the position of the first comment" do + comments.first.position.should_not be_nil + end + + it "should fetch the ID of the first comment" do + comments.first.id.should_not be_nil + end + end + + context "fetches pull request files" do + files = github.pull_request_files("octokit-cr/octokit.cr", 15).records + + it "should find at least one file" do + files.size.should be > 0 + end + + it "should fetch the filename of the first file" do + files.first.filename.should_not be_nil + end + + it "should fetch the sha of the first file" do + files.first.sha.should_not be_nil + end + + it "should fetch the status of the first file" do + files.first.status.should_not be_nil + end + + it "should fetch the additions of the first file" do + files.first.additions.should_not be_nil + end + + it "should fetch the deletions of the first file" do + files.first.deletions.should_not be_nil + end + + it "should fetch the contents_url of the first file" do + files.first.contents_url.should_not be_nil + end + + it "should fetch the patch of the first file" do + files.first.patch.should_not be_nil + end + + it "should fetch the sha of the second file" do + files[1].sha.should_not be_nil + end + end + + context "merged pull request" do + pull = github.pull_merged?("octokit-cr/octokit.cr", 15) + + it "checks if the pull request is merged and finds that it is" do + pull.should eq true + end + end + end end From c553cc51be875fee97ed6f640c50edd5fe5283b5 Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Mon, 12 Aug 2024 10:28:09 -0700 Subject: [PATCH 31/32] complete PullRequests --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 682e1bb1..b8029be1 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ There are a lot of pieces of the GitHub API to cover. Here are the ones that nee - [ ] [Pages]() - [ ] [Projects]() - [x] [PubSubHubbub](https://octokit-cr.github.io/octokit.cr/Octokit/Client/PubSubHubbub.html) -- [ ] [PullRequests]() +- [x] [PullRequests](https://octokit-cr.github.io/octokit.cr/Octokit/Client/PullRequests.html) - [x] [RateLimit](https://octokit-cr.github.io/octokit.cr/Octokit/Client/RateLimit.html) - [ ] [Reactions]() - [ ] [Refs]() From e83eeb0a5d8ac69312a8e85df6d381afd9a3482e Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Mon, 12 Aug 2024 10:32:17 -0700 Subject: [PATCH 32/32] update version and comments --- shard.yml | 2 +- src/octokit/client/pull_requests.cr | 32 ++++++++++++++++++----------- src/octokit/version.cr | 2 +- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/shard.yml b/shard.yml index 6e921d6a..d5cae59c 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: octokit -version: 0.2.5 +version: 0.3.0 authors: - Grant Birkinbine diff --git a/src/octokit/client/pull_requests.cr b/src/octokit/client/pull_requests.cr index f2128331..039f00ab 100644 --- a/src/octokit/client/pull_requests.cr +++ b/src/octokit/client/pull_requests.cr @@ -147,7 +147,9 @@ module Octokit alias_method :pull_request_commits, :pull_commits # List review comments on a pull request + # # This method applies to pull request review comments. Pull request review comments are NOT the same as standard comments left on PRs - those are issue comments. + # # **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) # @@ -168,6 +170,8 @@ module Octokit # List comments on a pull request # + # This method applies to pull request review comments. Pull request review comments are NOT the same as standard comments left on PRs - those are issue comments. + # # **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) # @@ -189,6 +193,8 @@ module Octokit # Get a single comment on a pull request # + # This method applies to pull request review comments. Pull request review comments are NOT the same as standard comments left on PRs - those are issue comments. + # # **See Also:** # - [https://developer.github.com/v3/pulls/comments/#get-a-single-comment](https://developer.github.com/v3/pulls/comments/#get-a-single-comment) # @@ -206,25 +212,27 @@ module Octokit # Create a comment on a pull request # + # This method applies to pull request review comments. Pull request review comments are NOT the same as standard comments left on PRs - those are issue comments. + # # **See Also:** # - [https://developer.github.com/v3/pulls/comments/#create-a-comment](https://developer.github.com/v3/pulls/comments/#create-a-comment) # - # repo (String) — A GitHub repository - # number (Integer) — Pull request number - # body (String) — Comment content - # commit_id (String) — Sha of the commit to comment on - # path (String) — Relative path of the file to comment on - # line (Integer) — Line number in the diff to comment on - # side (String) — Side of the diff that the comment applies to (LEFT or RIGHT) - # start_line (Integer) — Start line for multi-line comments - # start_side (String) — Start side for multi-line comments (LEFT or RIGHT) - # in_reply_to (Integer) — ID of the review comment to reply to - # subject_type (String) — Level at which the comment is targeted (line or file) + # - repo (String) — A GitHub repository + # - number (Integer) — Pull request number + # - body (String) — Comment content + # - commit_id (String) — Sha of the commit to comment on + # - path (String) — Relative path of the file to comment on + # - line (Integer) — Line number in the diff to comment on + # - side (String) — Side of the diff that the comment applies to (LEFT or RIGHT) + # - start_line (Integer) — Start line for multi-line comments + # - start_side (String) — Start side for multi-line comments (LEFT or RIGHT) + # - in_reply_to (Integer) — ID of the review comment to reply to + # - subject_type (String) — Level at which the comment is targeted (line or file) # # **Examples:** # # ``` - # Octokit.create_pull_request_comment("crystal-lang/crystal", 123, "Comment body", "commit_id", "path", 1, side: "RIGHT") + # Octokit.create_pull_request_comment("crystal-lang/crystal", 123, "Comment body", "commit_id", "path/to/file.txt", 1, side: "RIGHT") # ``` def create_pull_request_comment( repo : String, diff --git a/src/octokit/version.cr b/src/octokit/version.cr index f00d8126..db2becd1 100644 --- a/src/octokit/version.cr +++ b/src/octokit/version.cr @@ -1,3 +1,3 @@ module Octokit - VERSION = "0.2.5" + VERSION = "0.3.0" end