Skip to content

Commit 03f8d50

Browse files
author
Sam Davies
committed
Create a repository project
1 parent 583ba8a commit 03f8d50

3 files changed

Lines changed: 79 additions & 4 deletions

File tree

lib/github_api/client/orgs/projects.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ class Client::Orgs::Projects < API
2222
#
2323
# @api public
2424
def list(*args)
25-
arguments(args, required: [:org_name])
26-
25+
arguments(args, required: [:org_name]) do
26+
permit %w[ state ]
27+
end
2728
params = arguments.params
29+
2830
params['options'] = OPTIONS
2931

3032
response = get_request("/orgs/#{arguments.org_name}/projects", params)

lib/github_api/client/repos/projects.rb

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,40 @@ class Client::Repos::Projects < API
2525
#
2626
# @api public
2727
def list(*args)
28-
arguments(args, required: [:owner, :repo])
29-
28+
arguments(args, required: [:owner, :repo]) do
29+
permit %w[ state ]
30+
end
3031
params = arguments.params
32+
3133
params['options'] = OPTIONS
3234

3335
response = get_request("/repos/#{arguments.owner}/#{arguments.repo}/projects", params)
3436
return response unless block_given?
3537
response.each { |el| yield el }
3638
end
3739
alias :all :list
40+
41+
# Create a new project for the specified repo
42+
#
43+
# @param [Hash] params
44+
# @option params [String] :name
45+
# Required string - The name of the project.
46+
# @option params [String] :body
47+
# Optional string - The body of the project.
48+
#
49+
# @example
50+
# github = Github.new
51+
# github.repos.create 'owner-name', 'repo-name', name: 'project-name'
52+
# github.repos.create name: 'project-name', body: 'project-body', owner: 'owner-name', repo: 'repo-name'
53+
def create(*args)
54+
arguments(args, required: [:owner, :repo]) do
55+
permit %w[ body name ]
56+
assert_required %w[ name ]
57+
end
58+
params = arguments.params
59+
params['options'] = OPTIONS
60+
61+
post_request("/repos/#{arguments.owner}/#{arguments.repo}/projects", params)
62+
end
3863
end # Projects
3964
end # Github
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+
describe Github::Client::Repos::Projects, '#create' do
6+
let(:owner) { 'octocat' }
7+
let(:repo) { 'api-playground' }
8+
let(:inputs) do
9+
{
10+
:name => 'Projects Documentation',
11+
:body => 'Developer documentation project for the developer site.'
12+
}
13+
end
14+
15+
before {
16+
stub_post(request_path).with(body: inputs).
17+
to_return(:body => body, :status => status,
18+
:headers => {:content_type => "application/json; charset=utf-8"} )
19+
}
20+
21+
context "resource created successfully" do
22+
let(:body) { fixture('repos/repo.json') }
23+
let(:status) { 201 }
24+
25+
let(:request_path) { "/repos/#{owner}/#{repo}/projects" }
26+
27+
it "should fail to create resource if 'name' inputs is missing" do
28+
expect {
29+
subject.create owner, repo, inputs.except(:name)
30+
}.to raise_error(Github::Error::RequiredParams)
31+
end
32+
33+
it "should create resource" do
34+
subject.create owner, repo, inputs
35+
a_post(request_path).with(body: inputs).should have_been_made
36+
end
37+
38+
it "should return the resource" do
39+
repository = subject.create owner, repo, inputs
40+
repository.name.should == 'Hello-World'
41+
end
42+
43+
it "should return mash type" do
44+
repository = subject.create owner, repo, inputs
45+
repository.should be_a Github::ResponseWrapper
46+
end
47+
end
48+
end # create

0 commit comments

Comments
 (0)