Skip to content

Commit 2d2f3fb

Browse files
author
Sam Davies
committed
Create an organization project
1 parent 03f8d50 commit 2d2f3fb

3 files changed

Lines changed: 76 additions & 6 deletions

File tree

lib/github_api/client/orgs/projects.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,29 @@ def list(*args)
3434
response.each { |el| yield el }
3535
end
3636
alias_method :all, :list
37+
38+
# Create a new project for the specified repo
39+
#
40+
# @param [Hash] params
41+
# @option params [String] :name
42+
# Required string - The name of the project.
43+
# @option params [String] :body
44+
# Optional string - The body of the project.
45+
#
46+
# @example
47+
# github = Github.new
48+
# github.repos.create 'owner-name', 'repo-name', name: 'project-name'
49+
# github.repos.create name: 'project-name', body: 'project-body', owner: 'owner-name', repo: 'repo-name'
50+
def create(*args)
51+
arguments(args, required: [:org_name]) do
52+
permit %w[ body name ]
53+
assert_required %w[ name ]
54+
end
55+
params = arguments.params
56+
57+
params['options'] = OPTIONS
58+
59+
post_request("/orgs/#{arguments.org_name}/projects", params)
60+
end
3761
end # Projects
3862
end # Github

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# encoding: utf-8
1+
# frozen_string_literal: true
22

33
require 'spec_helper'
44

@@ -19,7 +19,7 @@
1919
}
2020

2121
context "resource created successfully" do
22-
let(:body) { fixture('repos/repo.json') }
22+
let(:body) { fixture('projects/project.json') }
2323
let(:status) { 201 }
2424

2525
let(:request_path) { "/repos/#{owner}/#{repo}/projects" }
@@ -36,13 +36,13 @@
3636
end
3737

3838
it "should return the resource" do
39-
repository = subject.create owner, repo, inputs
40-
repository.name.should == 'Hello-World'
39+
project = subject.create owner, repo, inputs
40+
project.name.should == 'Projects Documentation'
4141
end
4242

4343
it "should return mash type" do
44-
repository = subject.create owner, repo, inputs
45-
repository.should be_a Github::ResponseWrapper
44+
project = subject.create owner, repo, inputs
45+
project.should be_a Github::ResponseWrapper
4646
end
4747
end
4848
end # create
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe Github::Client::Orgs::Projects, '#create' do
6+
let(:org) { 'API-sampler' }
7+
let(:request_path) { "/orgs/#{org}/projects" }
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('projects/project.json') }
23+
let(:status) { 201 }
24+
25+
it "should fail to create resource if 'name' inputs is missing" do
26+
expect {
27+
subject.create org, inputs.except(:name)
28+
}.to raise_error(Github::Error::RequiredParams)
29+
end
30+
31+
it "should create resource" do
32+
subject.create org, inputs
33+
a_post(request_path).with(body: inputs).should have_been_made
34+
end
35+
36+
it "should return the resource" do
37+
project = subject.create org, inputs
38+
project.name.should == 'Projects Documentation'
39+
end
40+
41+
it "should return mash type" do
42+
project = subject.create org, inputs
43+
project.should be_a Github::ResponseWrapper
44+
end
45+
end
46+
end # create

0 commit comments

Comments
 (0)