Implement simple repository settings API

This commit is contained in:
Piotr Sarnacki 2013-09-27 13:50:43 +02:00
parent f40573bd10
commit 62a5e602c5
4 changed files with 37 additions and 3 deletions

View File

@ -3,7 +3,7 @@ ruby '2.0.0'
source 'https://rubygems.org'
gemspec
gem 'travis-core', github: 'travis-ci/travis-core'
gem 'travis-core', github: 'travis-ci/travis-core', branch: 'repository-settings'
gem 'travis-support', github: 'travis-ci/travis-support'
gem 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs', require: nil, ref: 'cde9741'
gem 'sinatra'

View File

@ -23,7 +23,8 @@ GIT
GIT
remote: git://github.com/travis-ci/travis-core.git
revision: bf2520962f9445db529313b2ac8d8589a9d150b4
revision: 6a5b230b06e927cf953a1b7bb20dcf7fd45ee978
branch: repository-settings
specs:
travis-core (0.0.1)
actionmailer (~> 3.2.12)

View File

@ -41,6 +41,30 @@ class Travis::Api::App
respond_with service(:find_repo, params.merge(schema: 'cc'))
end
# Get settings for a given repository
#
get '/:id/settings' do
settings = service(:find_repo_settings, params).run
if settings
respond_with({ settings: settings.obfuscated }, version: :v2)
else
status 404
end
end
put '/:id/settings' do
settings = service(:find_repo_settings, params).run
if settings
settings.merge(params[:settings])
# TODO: I would like to have better API here, but leaving this
# for testing to not waste too much time before I can play with it
settings.repository.save
respond_with({ settings: settings.obfuscated }, version: :v2)
else
status 404
end
end
# Get the public key for the repository with the given id.
#
# This can be used to encrypt secure variables in the build configuration. See

View File

@ -1,3 +1,4 @@
# encoding: utf-8
require 'spec_helper'
describe 'Repos' do
@ -9,7 +10,7 @@ describe 'Repos' do
let(:token) { Travis::Api::App::AccessToken.create(user: user, app_id: -1) }
let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json', 'HTTP_AUTHORIZATION' => "token #{token}" } }
before { user.permissions.create!(:repository_id => repo.id, :admin => true) }
before { user.permissions.create!(:repository_id => repo.id, :admin => true, :push => true) }
it 'POST /repos/:id/key' do
expect {
@ -22,6 +23,14 @@ describe 'Repos' do
response = post "/repos/#{repo.slug}/key", {}, headers
}.to change { repo.reload.key.private_key }
end
it 'allows to get settings' do
repo.settings.replace('foo' => { 'type' => 'password', 'value' => 'abc123' })
repo.save
response = get "repos/#{repo.id}/settings", {}, headers
JSON.parse(response.body).should == { 'settings' => { 'foo' => { 'type' => 'password', 'value' => '' } } }
end
end
describe 'without authenticated user' do