Skip to content

Commit

Permalink
Add Projects Apis
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyw committed Oct 31, 2016
1 parent 55b201b commit d14f5aa
Show file tree
Hide file tree
Showing 22 changed files with 292 additions and 118 deletions.
245 changes: 179 additions & 66 deletions lib/octokit/client/projects.rb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"http_interactions":[{"request":{"method":"post","uri":"https://api.github.com/orgs/<GITHUB_TEST_ORGANIZATION>/projects","body":{"encoding":"UTF-8","base64_string":"eyJib2R5IjoiZG8gaXQiLCJuYW1lIjoic3luZXJneSJ9\n"},"headers":{"Accept":["application/vnd.github.inertia-preview+json"],"User-Agent":["Octokit Ruby Gem 4.3.1.pre1"],"Content-Type":["application/json"],"Authorization":["token <<ACCESS_TOKEN>>"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"]}},"response":{"status":{"code":201,"message":"Created"},"headers":{"Server":["GitHub.com"],"Date":["Mon, 31 Oct 2016 04:07:13 GMT"],"Content-Type":["application/json; charset=utf-8"],"Content-Length":["1167"],"Status":["201 Created"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4611"],"X-Ratelimit-Reset":["1477887689"],"Cache-Control":["private, max-age=60, s-maxage=60"],"Vary":["Accept, Authorization, Cookie, X-GitHub-OTP","Accept-Encoding"],"Etag":["\"5ea80ad6ad496ffaebff2cdacfdcac5f\""],"X-Oauth-Scopes":["admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user"],"X-Accepted-Oauth-Scopes":["repo"],"Location":["https://api.github.com/projects/147743"],"X-Github-Media-Type":["github.inertia-preview; format=json"],"Access-Control-Expose-Headers":["ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"],"Access-Control-Allow-Origin":["*"],"Content-Security-Policy":["default-src 'none'"],"Strict-Transport-Security":["max-age=31536000; includeSubdomains; preload"],"X-Content-Type-Options":["nosniff"],"X-Frame-Options":["deny"],"X-Xss-Protection":["1; mode=block"],"X-Served-By":["593010132f82159af0ded24b4932e109"],"X-Github-Request-Id":["4C6B2AEE:3E51:18C90E5E:5816C371"]},"body":{"encoding":"UTF-8","base64_string":"eyJvd25lcl91cmwiOiJodHRwczovL2FwaS5naXRodWIuY29tL29yZ3MvPEdJ\nVEhVQl9URVNUX09SR0FOSVpBVElPTj4iLCJ1cmwiOiJodHRwczovL2FwaS5n\naXRodWIuY29tL3Byb2plY3RzLzE0Nzc0MyIsImlkIjoxNDc3NDMsIm5hbWUi\nOiJzeW5lcmd5IiwiYm9keSI6ImRvIGl0IiwibnVtYmVyIjoxMCwiY3JlYXRv\nciI6eyJsb2dpbiI6IjxHSVRIVUJfTE9HSU4+IiwiaWQiOjE2MjcxMTM2LCJh\ndmF0YXJfdXJsIjoiaHR0cHM6Ly9hdmF0YXJzMy5naXRodWJ1c2VyY29udGVu\ndC5jb20vdS8xNjI3MTEzNj92PTMiLCJncmF2YXRhcl9pZCI6IiIsInVybCI6\nImh0dHBzOi8vYXBpLmdpdGh1Yi5jb20vdXNlcnMvPEdJVEhVQl9MT0dJTj4i\nLCJodG1sX3VybCI6Imh0dHBzOi8vZ2l0aHViLmNvbS88R0lUSFVCX0xPR0lO\nPiIsImZvbGxvd2Vyc191cmwiOiJodHRwczovL2FwaS5naXRodWIuY29tL3Vz\nZXJzLzxHSVRIVUJfTE9HSU4+L2ZvbGxvd2VycyIsImZvbGxvd2luZ191cmwi\nOiJodHRwczovL2FwaS5naXRodWIuY29tL3VzZXJzLzxHSVRIVUJfTE9HSU4+\nL2ZvbGxvd2luZ3svb3RoZXJfdXNlcn0iLCJnaXN0c191cmwiOiJodHRwczov\nL2FwaS5naXRodWIuY29tL3VzZXJzLzxHSVRIVUJfTE9HSU4+L2dpc3Rzey9n\naXN0X2lkfSIsInN0YXJyZWRfdXJsIjoiaHR0cHM6Ly9hcGkuZ2l0aHViLmNv\nbS91c2Vycy88R0lUSFVCX0xPR0lOPi9zdGFycmVkey9vd25lcn17L3JlcG99\nIiwic3Vic2NyaXB0aW9uc191cmwiOiJodHRwczovL2FwaS5naXRodWIuY29t\nL3VzZXJzLzxHSVRIVUJfTE9HSU4+L3N1YnNjcmlwdGlvbnMiLCJvcmdhbml6\nYXRpb25zX3VybCI6Imh0dHBzOi8vYXBpLmdpdGh1Yi5jb20vdXNlcnMvPEdJ\nVEhVQl9MT0dJTj4vb3JncyIsInJlcG9zX3VybCI6Imh0dHBzOi8vYXBpLmdp\ndGh1Yi5jb20vdXNlcnMvPEdJVEhVQl9MT0dJTj4vcmVwb3MiLCJldmVudHNf\ndXJsIjoiaHR0cHM6Ly9hcGkuZ2l0aHViLmNvbS91c2Vycy88R0lUSFVCX0xP\nR0lOPi9ldmVudHN7L3ByaXZhY3l9IiwicmVjZWl2ZWRfZXZlbnRzX3VybCI6\nImh0dHBzOi8vYXBpLmdpdGh1Yi5jb20vdXNlcnMvPEdJVEhVQl9MT0dJTj4v\ncmVjZWl2ZWRfZXZlbnRzIiwidHlwZSI6IlVzZXIiLCJzaXRlX2FkbWluIjpm\nYWxzZX0sImNyZWF0ZWRfYXQiOiIyMDE2LTEwLTMxVDA0OjA3OjEzWiIsInVw\nZGF0ZWRfYXQiOiIyMDE2LTEwLTMxVDA0OjA3OjEzWiJ9\n"},"http_version":null},"recorded_at":"Mon, 31 Oct 2016 04:07:12 GMT"}],"recorded_with":"VCR 2.9.3"}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"http_interactions":[{"request":{"method":"get","uri":"https://api.github.com/repos/octokit/octokit.rb/projects","body":{"encoding":"US-ASCII","base64_string":""},"headers":{"Accept":["application/vnd.github.inertia-preview+json"],"User-Agent":["Octokit Ruby Gem 4.3.1.pre1"],"Content-Type":["application/json"],"Authorization":["token <<ACCESS_TOKEN>>"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Server":["GitHub.com"],"Date":["Sun, 23 Oct 2016 16:20:59 GMT"],"Content-Type":["application/json; charset=utf-8"],"Content-Length":["2"],"Status":["200 OK"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4997"],"X-Ratelimit-Reset":["1477240786"],"Cache-Control":["private, max-age=60, s-maxage=60"],"Vary":["Accept, Authorization, Cookie, X-GitHub-OTP","Accept-Encoding"],"Etag":["\"5da13e89d760ca31342c38013ce101db\""],"X-Oauth-Scopes":["admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user"],"X-Accepted-Oauth-Scopes":["public_repo, repo"],"X-Github-Media-Type":["github.inertia-preview; format=json"],"Link":["<https://api.github.com/repositories/417862/projects?page=0>; rel=\"last\""],"Access-Control-Expose-Headers":["ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"],"Access-Control-Allow-Origin":["*"],"Content-Security-Policy":["default-src 'none'"],"Strict-Transport-Security":["max-age=31536000; includeSubdomains; preload"],"X-Content-Type-Options":["nosniff"],"X-Frame-Options":["deny"],"X-Xss-Protection":["1; mode=block"],"X-Served-By":["52189b7290fad804d77890ef34a1eeae"],"X-Github-Request-Id":["4C6B2AEE:3E4D:119CE8DB:580CE36B"]},"body":{"encoding":"UTF-8","base64_string":"W10=\n"},"http_version":null},"recorded_at":"Sun, 23 Oct 2016 16:21:00 GMT"}],"recorded_with":"VCR 2.9.3"}
{"http_interactions":[{"request":{"method":"get","uri":"https://api.github.com/repos/octokit/octokit.rb/projects","body":{"encoding":"US-ASCII","base64_string":""},"headers":{"Accept":["application/vnd.github.inertia-preview+json"],"User-Agent":["Octokit Ruby Gem 4.3.1.pre1"],"Content-Type":["application/json"],"Authorization":["token <<ACCESS_TOKEN>>"],"Accept-Encoding":["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Server":["GitHub.com"],"Date":["Mon, 31 Oct 2016 04:07:12 GMT"],"Content-Type":["application/json; charset=utf-8"],"Content-Length":["2"],"Status":["200 OK"],"X-Ratelimit-Limit":["5000"],"X-Ratelimit-Remaining":["4615"],"X-Ratelimit-Reset":["1477887689"],"Cache-Control":["private, max-age=60, s-maxage=60"],"Vary":["Accept, Authorization, Cookie, X-GitHub-OTP","Accept-Encoding"],"Etag":["\"5da13e89d760ca31342c38013ce101db\""],"X-Oauth-Scopes":["admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user"],"X-Accepted-Oauth-Scopes":["public_repo, repo"],"X-Github-Media-Type":["github.inertia-preview; format=json"],"Link":["<https://api.github.com/repositories/417862/projects?page=0>; rel=\"last\""],"Access-Control-Expose-Headers":["ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"],"Access-Control-Allow-Origin":["*"],"Content-Security-Policy":["default-src 'none'"],"Strict-Transport-Security":["max-age=31536000; includeSubdomains; preload"],"X-Content-Type-Options":["nosniff"],"X-Frame-Options":["deny"],"X-Xss-Protection":["1; mode=block"],"X-Served-By":["49aa99f015c25437a7443c4d3a58cd17"],"X-Github-Request-Id":["4C6B2AEE:3E51:18C90E01:5816C370"]},"body":{"encoding":"UTF-8","base64_string":"W10=\n"},"http_version":null},"recorded_at":"Mon, 31 Oct 2016 04:07:11 GMT"}],"recorded_with":"VCR 2.9.3"}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

134 changes: 94 additions & 40 deletions spec/octokit/client/projects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,116 +18,170 @@
end
end # .create_project

describe ".org_projects", :vcr do
it "returns the projects for an organization" do
projects = oauth_client.org_projects(test_github_org)
expect(projects).to be_kind_of Array
assert_requested :get, github_url("/orgs/#{test_github_org}/projects")
end
end # .org_project

describe ".create_org_project", :vcr do
it "returns the new org project" do
project = oauth_client.create_org_project(test_github_org, "synergy", body: "do it")
expect(project.name).to eq "synergy"
expect(project.body).to eq "do it"
assert_requested :post, github_url("/orgs/#{test_github_org}/projects")
end
end # .create_org_project

context "with repository" do
before(:each) do
@repo = oauth_client.create_repository(test_github_repository)
delete_test_repo
end

after(:each) do
begin
oauth_client.delete_repository(@repo.full_name)
rescue Octokit::NotFound
end
delete_test_repo
end

context "with project" do
before(:each) do
@project = oauth_client.create_project(@repo.full_name, "implement apis")
@project = oauth_client.create_project(@test_repo, "implement apis")
end

describe ".project", :vcr do
it "returns a project" do
project = Octokit.project(@repo.full_name, @project.number)
project = oauth_client.project(@project.id)
expect(project.name).not_to be_nil
assert_requested :get, github_url("/repos/#{@repo.full_name}/projects/#{@project.number}")
assert_requested :get, github_url("/projects/#{@project.id}")
end
end # .project

describe ".update_project", :vcr do
it "updates the project name and body then returns the updated project" do
name = "new name"
body = "new body"
project = oauth_client.update_project(@repo.full_name, @project.number, {name: name, body: body})
project = oauth_client.update_project(@project.id, {name: name, body: body})
expect(project.name).to eq name
expect(project.body).to eq body
assert_requested :patch, github_url("/repos/#{@repo.full_name}/projects/#{@project.number}")
assert_requested :patch, github_url("/projects/#{@project.id}")
end
end # .update_project

describe ".delete_project", :vcr do
it "returns the result of deleting a project" do
result = oauth_client.delete_project(@repo.full_name, @project.number)
result = oauth_client.delete_project(@project.id)
expect(result).to eq true
assert_requested :delete, github_url("/repos/#{@repo.full_name}/projects/#{@project.number}")
assert_requested :delete, github_url("/projects/#{@project.id}")
end
end # .delete_project

describe ".project_columns", :vcr do
it "returns the columns for a project" do
columns = Octokit.project_columns(@repo.full_name, @project.number)
columns = oauth_client.project_columns(@project.id)
expect(columns).to be_kind_of Array
assert_requested :get, github_url("/repos/#{@repo.full_name}/projects/#{@project.number}/columns")
assert_requested :get, github_url("/projects/#{@project.id}/columns")
end
end # .project_columns

describe ".create_project_column", :vcr do
it "returns the newly created project column" do
column = oauth_client.create_project_column(@repo.full_name, @project.number, "Todos")
column = oauth_client.create_project_column(@project.id, "Todos")
expect(column.name).to eq "Todos"
assert_requested :post, github_url("/repos/#{@repo.full_name}/projects/#{@project.number}/columns")
assert_requested :post, github_url("/projects/#{@project.id}/columns")
end
end # .create_project_column

context "with project column" do
before(:each) do
@column = oauth_client.create_project_column(@repo.full_name, @project.number, 'Todos')
@column = oauth_client.create_project_column(@project.id, "Todos #{Time.now.to_f}")
end

describe ".project_column", :vcr do
it "returns a project column by id" do
skip "pending api"
column = oauth_client.project_column(@repo.full_name, @project.number, @column.id)
column = oauth_client.project_column(@column.id)
expect(column.name).to be_kind_of String
assert_requested :get, github_url("/repos/#{@repo.full_name}/projects/#{@projects.number}/columns/#{@column.id}")
assert_requested :get, github_url("/projects/columns/#{@column.id}")
end
end # .project_column

describe ".update_project_column", :vcr do
it "updates the project column and returns the updated column" do
skip "pending api"
column = oauth_client.update_project_column(@repo.full_name, @project.number, @column.id, "new name")
column = oauth_client.update_project_column(@column.id, "new name")
expect(column.name).to eq "new name"
assert_requested :patch, github_url("/repos/#{@repo.full_name}/projects/#{@project.number}/columns/#{@column.id}")
assert_requested :patch, github_url("/projects/columns/#{@column.id}")
end
end # .update_project_column

describe ".move_project_column", :vcr do
it "moves the project column" do
result = oauth_client.move_project_column(@column.id, "last")
assert_requested :post, github_url("/projects/columns/#{@column.id}/moves")
end
end # .move_project_column

describe ".delete_project_column", :vcr do
it "deletes the project column" do
skip "pending api"
result = oauth_client.delete_project_column(@repo.full_name, @project.number, @column.id)
result = oauth_client.delete_project_column(@column.id)
expect(result).to eq true
assert_requested :delete, github_url("/repos/#{@repo.full_name}/projects/#{@project.number}/columns/#{@column.id}")
assert_requested :delete, github_url("/projects/columns/#{@column.id}")
end
end # .delete_project_column

describe ".move_project_column", :vcr do
it "moves the project column" do
skip "pending api"
result = oauth_client.move_project_column(@repo.full_name, @project.number, @column.id, "last")
expect(result).to eq true
assert_requested :post, github_url("/repos/#{@repo.full_name}/projects/#{@project.number}/columns/#{@column.id}/moves")
describe ".column_cards", :vcr do
it "returns a list of the cards in a project column" do
cards = oauth_client.column_cards(@column.id)
expect(cards).to be_kind_of Array
assert_requested :get, github_url("/projects/columns/#{@column.id}/cards")
end
end # .move_project_column
end # .column_cards

describe ".projects_cards", :vcr do
it "returns projects cards by column id" do
skip "pending api"
cards = oauth_client.projects_cards(@repo.full_name, @project.number, @column.id)
expect(cards).to be_kind_of Array
assert_requested :get, github_url("/repos/#{@repo.full_name}/projects/#{@project.number}/columns/#{@column.id}/cards")
describe ".create_project_card", :vcr do
it "creates a new card with a note" do
card = oauth_client.create_project_card(@column.id, note: 'thing')
expect(card.note).to eq 'thing'
assert_requested :post, github_url("/projects/columns/#{@column.id}/cards")
end
end # .create_project_card

context "with project card" do
before(:each) do
@card = oauth_client.create_project_card(@column.id, note: 'octocard')
end
end # .projects_cards

describe ".project_card", :vcr do
it "returns a project card by id" do
card = oauth_client.project_card(@card.id)
expect(card.note).to be_kind_of String
assert_requested :get, github_url("/projects/columns/cards/#{@card.id}")
end
end # .project_card

describe ".update_project_card", :vcr do
it "updates the project card" do
card = oauth_client.update_project_card(@card.id, note: 'new note')
expect(card.note).to eq 'new note'
assert_requested :patch, github_url("/projects/columns/cards/#{@card.id}")
end
end # .update_project_card

describe ".move_project_card", :vcr do
it "moves the project card" do
success = oauth_client.move_project_card(@card.id, 'bottom')
expect(success).to eq true
assert_requested :post, github_url("/projects/columns/cards/#{@card.id}/moves")
end
end # .move_project_card

describe ".delete_project_card", :vcr do
it "deletes the project card" do
success = oauth_client.delete_project_card(@card.id)
expect(success).to eq true
assert_requested :delete, github_url("/projects/columns/cards/#{@card.id}")
end
end # .delete_project_card

end # with project card
end # with project column
end # with project
end # with repository
Expand Down

0 comments on commit d14f5aa

Please sign in to comment.