Skip to content

Commit 7ba4026

Browse files
author
Sam Davies
committed
List organization projects
1 parent 1e95d51 commit 7ba4026

8 files changed

Lines changed: 151 additions & 26 deletions

File tree

lib/github_api/client/orgs.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Client::Orgs < API
88
'hooks',
99
'members',
1010
'memberships',
11+
'projects',
1112
'teams'
1213

1314
# Access to Client::Orgs::Hooks API
@@ -19,6 +20,9 @@ class Client::Orgs < API
1920
# Access to Client::Orgs::Memberships API
2021
namespace :memberships
2122

23+
# Access to Client::Orgs::Projects API
24+
namespace :projects
25+
2226
# Access to Client::Orgs::Teams API
2327
namespace :teams
2428

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# frozen_string_literal: true
2+
3+
module Github
4+
class Client::Orgs::Projects < API
5+
OPTIONS = {
6+
headers: {
7+
ACCEPT => 'application/vnd.github.inertia-preview+json'
8+
}
9+
}
10+
11+
# List your organization projects
12+
#
13+
# @see List your organization projects
14+
#
15+
# @example
16+
# github = Github.new 'org-name'
17+
# github.orgs.projects.list 'org-name' { |project| ... }
18+
#
19+
# @example
20+
# github = Github.new
21+
# github.orgs.projects.list 'org-name', state: 'closed'
22+
#
23+
# @api public
24+
def list(*args)
25+
arguments(args, required: [:org_name])
26+
27+
params = arguments.params
28+
params['options'] = OPTIONS
29+
30+
response = get_request("/orgs/#{arguments.org_name}/projects", params)
31+
return response unless block_given?
32+
response.each { |el| yield el }
33+
end
34+
alias_method :all, :list
35+
end # Projects
36+
end # Github

lib/github_api/client/repos/projects.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ def list(*args)
3535
response.each { |el| yield el }
3636
end
3737
alias :all :list
38-
end
39-
end
38+
end # Projects
39+
end # Github

spec/fixtures/orgs/projects.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[
2+
{
3+
"owner_url": "https://api.github.com/orgs/octocat",
4+
"url": "https://api.github.com/projects/1002605",
5+
"id": 1002605,
6+
"name": "Organization Roadmap",
7+
"body": "High-level roadmap for the upcoming year.",
8+
"number": 1,
9+
"state": "open",
10+
"creator": {
11+
"login": "octocat",
12+
"id": 1,
13+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
14+
"gravatar_id": "",
15+
"url": "https://api.github.com/users/octocat",
16+
"html_url": "https://github.com/octocat",
17+
"followers_url": "https://api.github.com/users/octocat/followers",
18+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
19+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
20+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
21+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
22+
"organizations_url": "https://api.github.com/users/octocat/orgs",
23+
"repos_url": "https://api.github.com/users/octocat/repos",
24+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
25+
"received_events_url": "https://api.github.com/users/octocat/received_events",
26+
"type": "User",
27+
"site_admin": false
28+
},
29+
"created_at": "2011-04-11T20:09:31Z",
30+
"updated_at": "2014-03-04T18:58:10Z"
31+
}
32+
]

spec/fixtures/repos/projects.json

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
11
[
22
{
3-
"owner_url": "https://api.github.com/repos/samphilipd/github",
4-
"url": "https://api.github.com/projects/513163",
5-
"html_url": "https://github.com/samphilipd/github/projects/1",
6-
"columns_url": "https://api.github.com/projects/513163/columns",
7-
"id": 513163,
8-
"name": "Implement new APIs",
9-
"body": "Implement new APIs as per:\r\n\r\nhttps://github.com/piotrmurach/github/issues/289\r\n\r\n\r\n projects\r\n reactions\r\n issues.timeline\r\n migration\r\n orgs.outside_collaborators\r\n orgs.blocking\r\n pull_requests.review_requests\r\n users.gpg_keys\r\n users.blocking\r\n repos.invitations\r\n repos.traffic\r\n repos.community\r\n",
3+
"owner_url": "https://api.github.com/repos/api-playground/projects-test",
4+
"url": "https://api.github.com/projects/1002604",
5+
"id": 1002604,
6+
"name": "Projects Documentation",
7+
"body": "Developer documentation project for the developer site.",
108
"number": 1,
119
"state": "open",
1210
"creator": {
13-
"login": "samphilipd",
14-
"id": 4147639,
15-
"avatar_url": "https://avatars0.githubusercontent.com/u/4147639?v=3",
11+
"login": "octocat",
12+
"id": 1,
13+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
1614
"gravatar_id": "",
17-
"url": "https://api.github.com/users/samphilipd",
18-
"html_url": "https://github.com/samphilipd",
19-
"followers_url": "https://api.github.com/users/samphilipd/followers",
20-
"following_url": "https://api.github.com/users/samphilipd/following{/other_user}",
21-
"gists_url": "https://api.github.com/users/samphilipd/gists{/gist_id}",
22-
"starred_url": "https://api.github.com/users/samphilipd/starred{/owner}{/repo}",
23-
"subscriptions_url": "https://api.github.com/users/samphilipd/subscriptions",
24-
"organizations_url": "https://api.github.com/users/samphilipd/orgs",
25-
"repos_url": "https://api.github.com/users/samphilipd/repos",
26-
"events_url": "https://api.github.com/users/samphilipd/events{/privacy}",
27-
"received_events_url": "https://api.github.com/users/samphilipd/received_events",
15+
"url": "https://api.github.com/users/octocat",
16+
"html_url": "https://github.com/octocat",
17+
"followers_url": "https://api.github.com/users/octocat/followers",
18+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
19+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
20+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
21+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
22+
"organizations_url": "https://api.github.com/users/octocat/orgs",
23+
"repos_url": "https://api.github.com/users/octocat/repos",
24+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
25+
"received_events_url": "https://api.github.com/users/octocat/received_events",
2826
"type": "User",
2927
"site_admin": false
3028
},
31-
"created_at": "2017-04-05T08:38:38Z",
32-
"updated_at": "2017-04-05T08:40:06Z"
29+
"created_at": "2011-04-10T20:09:31Z",
30+
"updated_at": "2014-03-03T18:58:10Z"
3331
}
3432
]

spec/github/client/repos/projects/list_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
it "should get project information" do
4747
projects = subject.list user, repo
48-
projects.first.name.should == 'Implement new APIs'
48+
projects.first.name.should == 'Projects Documentation'
4949
end
5050

5151
it "should yield to a block" do
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'spec_helper'
2+
3+
describe Github::Client::Repos::Projects do
4+
5+
it_should_behave_like 'api interface'
6+
7+
end # Github::Repos::Projects
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# encoding: utf-8
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe Github::Client::Orgs::Projects, '#list' do
6+
let(:org) { 'API-sampler' }
7+
let(:request_path) { "/orgs/#{org}/projects" }
8+
9+
before do
10+
stub_get(request_path).to_return(body: body, status: status,
11+
headers: {content_type: "application/json; charset=utf-8"})
12+
end
13+
14+
after { reset_authentication_for(subject) }
15+
16+
context "resource found" do
17+
let(:body) { fixture('orgs/projects.json') }
18+
let(:status) { 200 }
19+
20+
it { expect(subject).to respond_to :all }
21+
22+
it { expect { subject.list }.to raise_error(ArgumentError) }
23+
24+
it "gets the resources" do
25+
subject.list(org)
26+
expect(a_get(request_path)).to have_been_made
27+
end
28+
29+
it_should_behave_like 'an array of resources' do
30+
let(:requestable) { subject.list org }
31+
end
32+
33+
it "gets project information" do
34+
projects = subject.list(org)
35+
expect(projects.first.name).to eq('Organization Roadmap')
36+
end
37+
38+
it "yields to a block" do
39+
yielded = []
40+
result = subject.list(org) { |obj| yielded << obj }
41+
expect(yielded).to eq(result)
42+
end
43+
end
44+
45+
it_should_behave_like 'request failure' do
46+
let(:requestable) { subject.list org }
47+
end
48+
end # list

0 commit comments

Comments
 (0)