forked from octokit/octokit.rb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request octokit#760 from octokit/reactions
Add Reactions Preview to Octokit
- Loading branch information
Showing
13 changed files
with
320 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
module Octokit | ||
class Client | ||
|
||
# Methods for the Reacions API | ||
# | ||
# @see https://developer.github.com/v3/reactions/ | ||
module Reactions | ||
|
||
# List reactions for a commit comment | ||
# | ||
# @param repo [Integer, String, Hash, Repository] A GitHub repository | ||
# @param id [Integer] The id of the commit comment | ||
# @see https://developer.github.com/v3/reactions/#list-reactions-for-a-commit-comment | ||
# | ||
# @example | ||
# @client.commit_comment_reactions("octokit/octokit.rb", 1) | ||
# | ||
# @return [Array<Sawyer::Resource>] Array of Hashes representing the reactions. | ||
def commit_comment_reactions(repo, id, options = {}) | ||
options = ensure_api_media_type(:reactions, options) | ||
get "#{Repository.path repo}/comments/#{id}/reactions", options | ||
end | ||
|
||
# Create a reaction for a commit comment | ||
# | ||
# @param repo [Integer, String, Hash, Repository] A GitHub repository | ||
# @param id [Integer] The id of the commit comment | ||
# @param reaction [String] The Reaction | ||
# @see https://developer.github.com/v3/reactions/#create-reaction-for-a-commit-comment | ||
# @see https://developer.github.com/v3/reactions/#reaction-types | ||
# | ||
# @example | ||
# @client.create_commit_comment_reactions("octokit/octokit.rb", 1) | ||
# | ||
# @return [<Sawyer::Resource>] Hash representing the reaction | ||
def create_commit_comment_reaction(repo, id, reaction, options = {}) | ||
options = ensure_api_media_type(:reactions, options.merge(:content => reaction)) | ||
post "#{Repository.path repo}/comments/#{id}/reactions", options | ||
end | ||
|
||
# List reactions for an issue | ||
# | ||
# @param repo [Integer, String, Hash, Repository] A GitHub repository | ||
# @param number [Integer] The Issue number | ||
# @see https://developer.github.com/v3/reactions/#list-reactions-for-an-issue | ||
# | ||
# @example | ||
# @client.issue_reactions("octokit/octokit.rb", 1) | ||
# | ||
# @return [Array<Sawyer::Resource>] Array of Hashes representing the reactions. | ||
def issue_reactions(repo, number, options = {}) | ||
options = ensure_api_media_type(:reactions, options) | ||
get "#{Repository.path repo}/issues/#{number}/reactions", options | ||
end | ||
|
||
# Create reaction for an issue | ||
# | ||
# @param repo [Integer, String, Hash, Repository] A GitHub repository | ||
# @param number [Integer] The Issue number | ||
# @param reaction [String] The Reaction | ||
# | ||
# @see https://developer.github.com/v3/reactions/#create-reaction-for-an-issue | ||
# @see https://developer.github.com/v3/reactions/#reaction-types | ||
# | ||
# @example | ||
# @client.create_issue_reaction("octokit/octokit.rb", 1) | ||
# | ||
# @return [<Sawyer::Resource>] Hash representing the reaction. | ||
def create_issue_reaction(repo, number, reaction, options = {}) | ||
options = ensure_api_media_type(:reactions, options.merge(:content => reaction)) | ||
post "#{Repository.path repo}/issues/#{number}/reactions", options | ||
end | ||
|
||
# List reactions for an issue comment | ||
# | ||
# @param repo [Integer, String, Hash, Repository] A GitHub repository | ||
# @param id [Integer] The Issue comment id | ||
# | ||
# @see https://developer.github.com/v3/reactions/#list-reactions-for-an-issue-comment | ||
# | ||
# @example | ||
# @client.issue_comment_reactions("octokit/octokit.rb", 1) | ||
# | ||
# @return [Array<Sawyer::Resource>] Array of Hashes representing the reactions. | ||
def issue_comment_reactions(repo, id, options = {}) | ||
options = ensure_api_media_type(:reactions, options) | ||
get "#{Repository.path repo}/issues/comments/#{id}/reactions", options | ||
end | ||
|
||
# Create reaction for an issue comment | ||
# | ||
# @param repo [Integer, String, Hash, Repository] A GitHub repository | ||
# @param id [Integer] The Issue comment id | ||
# @param reaction [String] The Reaction | ||
# | ||
# @see https://developer.github.com/v3/reactions/#create-reaction-for-an-issue-comment | ||
# @see https://developer.github.com/v3/reactions/#reaction-types | ||
# | ||
# @example | ||
# @client.create_issue_comment_reaction("octokit/octokit.rb", 1) | ||
# | ||
# @return [<Sawyer::Resource>] Hashes representing the reaction. | ||
def create_issue_comment_reaction(repo, id, reaction, options = {}) | ||
options = ensure_api_media_type(:reactions, options.merge(:content => reaction)) | ||
post "#{Repository.path repo}/issues/comments/#{id}/reactions", options | ||
end | ||
|
||
# List reactions for a pull request review comment | ||
# | ||
# @param repo [Integer, String, Hash, Repository] A GitHub repository | ||
# @param id [Integer] The Issue comment id | ||
# | ||
# @see https://developer.github.com/v3/reactions/#list-reactions-for-a-pull-request-review-comment | ||
# | ||
# @example | ||
# @client.pull_request_review_comment_reactions("octokit/octokit.rb", 1) | ||
# | ||
# @return [Array<Sawyer::Resource>] Array of Hashes representing the reactions. | ||
def pull_request_review_comment_reactions(repo, id, options = {}) | ||
options = ensure_api_media_type(:reactions, options) | ||
get "#{Repository.path repo}/pulls/comments/#{id}/reactions", options | ||
end | ||
|
||
# Create reaction for a pull request review comment | ||
# | ||
# @param repo [Integer, String, Hash, Repository] A GitHub repository | ||
# @param id [Integer] The Issue comment id | ||
# @param reaction [String] The Reaction | ||
# | ||
# @see https://developer.github.com/v3/reactions/#create-reaction-for-a-pull-request-review-comment | ||
# @see https://developer.github.com/v3/reactions/#reaction-types | ||
# | ||
# @example | ||
# @client.create_pull_request_reiew_comment_reaction("octokit/octokit.rb", 1) | ||
# | ||
# @return [<Sawyer::Resource>] Hash representing the reaction. | ||
def create_pull_request_review_comment_reaction(repo, id, reaction, options = {}) | ||
options = ensure_api_media_type(:reactions, options.merge(:content => reaction)) | ||
post "#{Repository.path repo}/pulls/comments/#{id}/reactions", options | ||
end | ||
|
||
# Delete a reaction | ||
# | ||
# @param id [Integer] Reaction id | ||
# | ||
# @see https://developer.github.com/v3/reactions/#delete-a-reaction | ||
# | ||
# @example | ||
# @client.delete_reaction(1) | ||
# | ||
# @return [Boolean] Return true if reaction was deleted, false otherwise. | ||
def delete_reaction(id, options = {}) | ||
options = ensure_api_media_type(:reactions, options) | ||
boolean_from_response :delete, "reactions/#{id}", options | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...pository/with_commit_comment/_commit_comment_reactions/returns_an_Array_of_reactions.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...th_repository/with_commit_comment/_create_commit_comment_reaction/creates_a_reaction.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...lient_Reactions/with_repository/with_issue/_create_issue_reaction/creates_a_reaction.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
..._Reactions/with_repository/with_issue/_issue_reactions/returns_an_Array_of_reactions.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...tory/with_issue/with_issue_comment/_create_issue_comment_reaction/creates_a_reaction.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...with_issue/with_issue_comment/_issue_comment_reactions/returns_an_Array_of_reactions.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...tions/with_repository/with_issue/with_reaction/_delete_reaction/deletes_the_reaction.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...quest_review_comment/_create_pull_request_review_comment_reaction/creates_a_reaction.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
..._review_comment/_pull_request_review_comment_reactions/returns_an_Array_of_reactions.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
require 'helper' | ||
|
||
describe Octokit::Client::Reactions do | ||
before do | ||
Octokit.reset! | ||
@client = oauth_client | ||
end | ||
|
||
context "with repository", :vcr do | ||
before(:each) do | ||
@repo = @client.create_repository("an-repo", :auto_init => true) | ||
end | ||
|
||
after(:each) do | ||
begin | ||
@client.delete_repository(@repo.full_name) | ||
rescue Octokit::NotFound | ||
end | ||
end | ||
|
||
context "with commit comment" do | ||
before do | ||
@commit = @client.commits(@repo.full_name).last.rels[:self].get.data | ||
@commit_comment = @client.create_commit_comment \ | ||
@repo.full_name, | ||
@commit.sha, ":metal:\n:sparkles:\n:cake:", | ||
@commit.files.last.filename | ||
end | ||
|
||
describe ".commit_comment_reactions" do | ||
it "returns an Array of reactions" do | ||
reactions = @client.commit_comment_reactions(@repo.full_name, @commit_comment.id) | ||
expect(reactions).to be_kind_of Array | ||
assert_requested :get, github_url("/repos/#{@repo.full_name}/comments/#{@commit_comment.id}/reactions") | ||
end | ||
end # .commit_comment_reactions | ||
|
||
describe ".create_commit_comment_reaction" do | ||
it "creates a reaction" do | ||
reaction = @client.create_commit_comment_reaction(@repo.full_name, @commit_comment.id, "+1") | ||
expect(reaction.content).to eql("+1") | ||
assert_requested :post, github_url("/repos/#{@repo.full_name}/comments/#{@commit_comment.id}/reactions") | ||
end | ||
end # .create_commit_comment_reaction | ||
end # with commit comment | ||
|
||
context "with issue", :vcr do | ||
before do | ||
@issue = @client.create_issue(@repo.full_name, "Migrate issues to v3", "Move all Issues calls to v3 of the API") | ||
end | ||
|
||
describe ".issue_reactions" do | ||
it "returns an Array of reactions" do | ||
reactions = @client.issue_reactions(@repo.full_name, @issue.number) | ||
expect(reactions).to be_kind_of Array | ||
assert_requested :get, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}/reactions") | ||
end | ||
end # .issue_reactions | ||
|
||
describe ".create_issue_reaction" do | ||
it "creates a reaction" do | ||
reaction = @client.create_issue_reaction(@repo.full_name, @issue.number, "+1") | ||
expect(reaction.content).to eql("+1") | ||
assert_requested :post, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}/reactions") | ||
end | ||
end # .create_issue_reaction | ||
|
||
context "with issue comment" do | ||
before do | ||
@issue_comment = @client.add_comment(@repo.full_name, @issue.number, "Another test comment") | ||
end | ||
|
||
describe ".issue_comment_reactions" do | ||
it "returns an Array of reactions" do | ||
reactions = @client.issue_comment_reactions(@repo.full_name, @issue_comment.id) | ||
expect(reactions).to be_kind_of Array | ||
assert_requested :get, github_url("/repos/#{@repo.full_name}/issues/comments/#{@issue_comment.id}/reactions") | ||
end | ||
end # .issue_commit_comment_reactions | ||
|
||
describe ".create_issue_comment_reaction" do | ||
it "creates a reaction" do | ||
reaction = @client.create_issue_comment_reaction(@repo.full_name, @issue_comment.id, "+1") | ||
expect(reaction.content).to eql("+1") | ||
assert_requested :post, github_url("/repos/#{@repo.full_name}/issues/comments/#{@issue_comment.id}/reactions") | ||
end | ||
end # .create_issue_comment_reaction | ||
end # with issue comment | ||
|
||
context "with reaction" do | ||
before do | ||
@reaction = @client.create_issue_reaction(@repo.full_name, @issue.number, "+1") | ||
end | ||
|
||
describe ".delete_reaction" do | ||
it "deletes the reaction" do | ||
@client.delete_reaction(@reaction.id) | ||
assert_requested :delete, github_url("/reactions/#{@reaction.id}") | ||
end | ||
end # .delete_reaction | ||
end # with reaction | ||
end # with issue | ||
|
||
context "with pull request" do | ||
before do | ||
master_ref = @client.ref(@repo.full_name, "heads/master") | ||
@client.create_ref(@repo.full_name, "heads/branch-for-pr", master_ref.object.sha) | ||
@content = @client.create_contents(@repo.full_name, "lib/test.txt", "Adding content", "File Content", :branch => "branch-for-pr") | ||
|
||
args = [@repo.full_name, "master", "branch-for-pr", "A new PR", "The Body"] | ||
@pull = @client.create_pull_request(*args) | ||
end | ||
|
||
context "with pull request review comment" do | ||
before do | ||
new_comment = { | ||
:body => "Looks good!", | ||
:commit_id => @content.commit.sha, | ||
:path => "lib/test.txt", | ||
:position => 1 | ||
} | ||
|
||
@pull_request_review_comment = @client.create_pull_request_comment \ | ||
@repo.full_name, | ||
@pull.number, | ||
new_comment[:body], | ||
new_comment[:commit_id], | ||
new_comment[:path], | ||
new_comment[:position] | ||
end | ||
|
||
describe ".pull_request_review_comment_reactions" do | ||
it "returns an Array of reactions" do | ||
reactions = @client.pull_request_review_comment_reactions(@repo.full_name, @pull_request_review_comment.id) | ||
expect(reactions).to be_kind_of Array | ||
assert_requested :get, github_url("/repos/#{@repo.full_name}/pulls/comments/#{@pull_request_review_comment.id}/reactions") | ||
end | ||
end # .pull_request_review_comment_reactions | ||
|
||
describe ".create_pull_request_review_comment_reaction" do | ||
it "creates a reaction" do | ||
reaction = @client.create_pull_request_review_comment_reaction(@repo.full_name, @pull_request_review_comment.id, "+1") | ||
expect(reaction.content).to eql("+1") | ||
assert_requested :post, github_url("/repos/#{@repo.full_name}/pulls/comments/#{@pull_request_review_comment.id}/reactions") | ||
end | ||
end # .create_pull_request_review_comment_reaction | ||
end # with pull request review comment | ||
end # with pull request | ||
end # with repository | ||
end |