Merge pull request #122 from travis-ci/ha-feature-remove_log_endpoint
Add RemoveLog service API endpoint
This commit is contained in:
commit
25f135774c
|
@ -8,7 +8,13 @@ rvm:
|
|||
addons:
|
||||
postgresql: 9.3
|
||||
before_script:
|
||||
# create 'logs' table matching 'travis-logs'
|
||||
- ./set_up_travis_logs.sh
|
||||
- 'RAILS_ENV=test bundle exec rake db:create db:structure:load --trace'
|
||||
# replace 'logs' table in travis_test DB with that in travis_logs_test
|
||||
- psql -c "DROP TABLE IF EXISTS logs CASCADE" -U postgres travis_test
|
||||
- pg_dump -t logs travis_logs_test | psql -U postgres travis_test
|
||||
|
||||
notifications:
|
||||
irc: "irc.freenode.org#travis"
|
||||
services:
|
||||
|
|
|
@ -45,7 +45,7 @@ GIT
|
|||
|
||||
GIT
|
||||
remote: git://github.com/travis-ci/travis-core.git
|
||||
revision: 111ae389e611157d48177ed732c1822d98fe3059
|
||||
revision: ef8fb67bd56569eb55d176f824bb62bc602c8f80
|
||||
specs:
|
||||
travis-core (0.0.1)
|
||||
actionmailer (~> 3.2.12)
|
||||
|
@ -210,7 +210,7 @@ GEM
|
|||
net-http-persistent (2.9.4)
|
||||
net-http-pipeline (1.0.1)
|
||||
pg (0.13.2)
|
||||
polyglot (0.3.4)
|
||||
polyglot (0.3.5)
|
||||
proxies (0.2.1)
|
||||
pry (0.9.12.4)
|
||||
coderay (~> 1.0)
|
||||
|
@ -293,7 +293,7 @@ GEM
|
|||
eventmachine (>= 1.0.0)
|
||||
rack (>= 1.0.0)
|
||||
thor (0.14.6)
|
||||
thread_safe (0.3.3)
|
||||
thread_safe (0.3.4)
|
||||
tilt (1.4.1)
|
||||
timers (1.1.0)
|
||||
treetop (1.4.15)
|
||||
|
|
38
README.md
38
README.md
|
@ -2,20 +2,48 @@
|
|||
|
||||
This is the app running on https://api.travis-ci.org/
|
||||
|
||||
## Requirements
|
||||
|
||||
1. PostgreSQL 9.3 or higher
|
||||
1. Redis
|
||||
1. RabbitMQ
|
||||
|
||||
## Installation
|
||||
|
||||
Setup:
|
||||
### Setup
|
||||
|
||||
$ bundle install
|
||||
|
||||
Run tests:
|
||||
### Database setup
|
||||
|
||||
1. `rake db:create db:structure:load`
|
||||
1. Clone `travis-logs` and copy the `logs` database (assume the PostgreSQL user is `postgres`):
|
||||
```sh-session
|
||||
cd ..
|
||||
git clone https://github.com/travis-ci/travis-logs.git
|
||||
cd travis-logs
|
||||
rvm jruby do bundle exec rake db:migrate # `travis-logs` requires JRuby
|
||||
psql -c "DROP TABLE IF EXISTS logs CASCADE" -U postgres travis_development
|
||||
pg_dump -t logs travis_logs_development | psql -U postgres travis_development
|
||||
```
|
||||
|
||||
Repeat the database steps for `RAILS_ENV=test`.
|
||||
```sh-session
|
||||
RAILS_ENV=test rake db:create db:structure:load
|
||||
pushd ../travis-logs
|
||||
RAILS_ENV=test rvm jruby do bundle exec rake db:migrate
|
||||
psql -c "DROP TABLE IF EXISTS logs CASCADE" -U postgres travis_test
|
||||
pg_dump -t logs travis_logs_test | psql -U postgres travis_test
|
||||
popd
|
||||
```
|
||||
|
||||
|
||||
### Run tests
|
||||
|
||||
$ RAILS_ENV=test rake db:create db:structure:load
|
||||
$ rake spec
|
||||
|
||||
Run the server:
|
||||
### Run the server
|
||||
|
||||
$ rake db:create db:structure:load
|
||||
$ script/server
|
||||
|
||||
## Contributing
|
||||
|
|
|
@ -64,6 +64,21 @@ class Travis::Api::App
|
|||
end
|
||||
end
|
||||
|
||||
patch '/:id/log', scope: :private do |id|
|
||||
begin
|
||||
self.service(:remove_log, params).run
|
||||
rescue Travis::AuthorizationDenied => ade
|
||||
status 401
|
||||
{ error: { message: ade.message } }
|
||||
rescue Travis::JobUnfinished, Travis::LogAlreadyRemoved => e
|
||||
status 409
|
||||
{ error: { message: e.message } }
|
||||
rescue => e
|
||||
status 500
|
||||
{ error: { message: "Unexpected error occurred: #{e.message}" } }
|
||||
end
|
||||
end
|
||||
|
||||
get "/:job_id/annotations" do
|
||||
respond_with service(:find_annotations, params)
|
||||
end
|
||||
|
|
38
set_up_travis_logs.sh
Executable file
38
set_up_travis_logs.sh
Executable file
|
@ -0,0 +1,38 @@
|
|||
#!/bin/bash
|
||||
|
||||
travis_retry() {
|
||||
local result=0
|
||||
local count=1
|
||||
while [ $count -le 3 ]; do
|
||||
[ $result -ne 0 ] && {
|
||||
echo -e "\n${RED}The command \"$@\" failed. Retrying, $count of 3.${RESET}\n" >&2
|
||||
}
|
||||
"$@"
|
||||
result=$?
|
||||
[ $result -eq 0 ] && break
|
||||
count=$(($count + 1))
|
||||
sleep 1
|
||||
done
|
||||
|
||||
[ $count -eq 3 ] && {
|
||||
echo "\n${RED}The command \"$@\" failed 3 times.${RESET}\n" >&2
|
||||
}
|
||||
|
||||
return $result
|
||||
}
|
||||
|
||||
# clone travis-logs
|
||||
pushd $HOME
|
||||
git clone --depth=1 https://github.com/travis-ci/travis-logs.git
|
||||
cd travis-logs
|
||||
|
||||
# install ruby runtime which travis-logs wants
|
||||
RUBY_RUNTIME=$(cat .ruby-version)
|
||||
rvm install $RUBY_RUNTIME
|
||||
# using JRuby, migrate the 'logs' table in 'travis_test' database
|
||||
BUNDLE_GEMFILE=$PWD/Gemfile
|
||||
travis_retry rvm $RUBY_RUNTIME do bundle install
|
||||
psql -c "CREATE DATABASE travis_logs_test;" -U postgres
|
||||
cp $TRAVIS_BUILD_DIR/config/database.yml config/travis.yml
|
||||
rvm $RUBY_RUNTIME do bundle exec rake db:migrate
|
||||
popd
|
|
@ -76,6 +76,58 @@ describe 'Jobs' do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'PATCH /jobs/:job_id/log' do
|
||||
let(:user) { User.where(login: 'svenfuchs').first }
|
||||
let(:token) { Travis::Api::App::AccessToken.create(user: user, app_id: -1) }
|
||||
|
||||
before :each do
|
||||
headers.merge! 'HTTP_AUTHORIZATION' => "token #{token}"
|
||||
end
|
||||
|
||||
context 'when user does not have push permissions' do
|
||||
before :each do
|
||||
user.permissions.create!(repository_id: job.repository.id, :push => false)
|
||||
end
|
||||
|
||||
it 'returns status 401' do
|
||||
response = patch "/jobs/#{job.id}/log", { reason: 'Because reason!' }, headers
|
||||
response.status.should == 401
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user has push permission' do
|
||||
context 'when job is not finished' do
|
||||
before :each do
|
||||
job.stubs(:finished?).returns false
|
||||
user.permissions.create!(repository_id: job.repository.id, :push => true)
|
||||
end
|
||||
|
||||
it 'returns status 409' do
|
||||
response = patch "/jobs/#{job.id}/log", { reason: 'Because reason!' }, headers
|
||||
response.status.should == 409
|
||||
end
|
||||
end
|
||||
|
||||
context 'when job is finished' do
|
||||
let(:finished_job) { Factory(:test, state: 'passed') }
|
||||
|
||||
before :each do
|
||||
user.permissions.create!(repository_id: finished_job.repository.id, :push => true)
|
||||
end
|
||||
|
||||
it 'returns status 200' do
|
||||
response = patch "/jobs/#{finished_job.id}/log", { reason: 'Because reason!' }, headers
|
||||
response.status.should == 200
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
context 'when job is not found' do
|
||||
# TODO
|
||||
end
|
||||
end
|
||||
|
||||
it "GET /jobs/:id/annotations" do
|
||||
annotation_provider = Factory(:annotation_provider)
|
||||
annotation = annotation_provider.annotations.create(job_id: job.id, status: "passed", description: "Foobar")
|
||||
|
|
11
spec/unit/endpoint/logs_spec.rb
Normal file
11
spec/unit/endpoint/logs_spec.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Travis::Api::App::Endpoint::Logs do
|
||||
let(:job) { Factory(:test) }
|
||||
|
||||
describe "GET /logs/:id/" do
|
||||
it "finds log successfully" do
|
||||
get("/logs/#{job.log.id}", {}, "HTTP_ACCEPT" => "application/vnd.travis-ci.2+json, */*; q=0.01").should be_ok
|
||||
end
|
||||
end
|
||||
end
|
|
@ -13,9 +13,9 @@ Gem::Specification.new do |s|
|
|||
"Konstantin Haase",
|
||||
"Sven Fuchs",
|
||||
"Mathias Meyer",
|
||||
"Hiro Asari",
|
||||
"Josh Kalderimis",
|
||||
"Henrik Hodne",
|
||||
"Hiro Asari",
|
||||
"Andre Arko",
|
||||
"Erik Michaels-Ober",
|
||||
"Brian Ford",
|
||||
|
@ -35,8 +35,8 @@ Gem::Specification.new do |s|
|
|||
"konstantin.mailinglists@googlemail.com",
|
||||
"me@svenfuchs.com",
|
||||
"meyer@paperplanes.de",
|
||||
"josh.kalderimis@gmail.com",
|
||||
"asari.ruby@gmail.com",
|
||||
"josh.kalderimis@gmail.com",
|
||||
"me@henrikhodne.com",
|
||||
"henrik@hodne.io",
|
||||
"konstantin.haase@gmail.com",
|
||||
|
@ -84,6 +84,7 @@ Gem::Specification.new do |s|
|
|||
"lib/travis/api/app/endpoint/home.rb",
|
||||
"lib/travis/api/app/endpoint/hooks.rb",
|
||||
"lib/travis/api/app/endpoint/jobs.rb",
|
||||
"lib/travis/api/app/endpoint/lint.rb",
|
||||
"lib/travis/api/app/endpoint/logs.rb",
|
||||
"lib/travis/api/app/endpoint/repos.rb",
|
||||
"lib/travis/api/app/endpoint/requests.rb",
|
||||
|
@ -158,6 +159,7 @@ Gem::Specification.new do |s|
|
|||
"public/images/result/unknown.svg",
|
||||
"script/console",
|
||||
"script/server",
|
||||
"set_up_travis_logs.sh",
|
||||
"spec/integration/formats_handling_spec.rb",
|
||||
"spec/integration/responders_spec.rb",
|
||||
"spec/integration/routes.backup.rb",
|
||||
|
@ -213,6 +215,8 @@ Gem::Specification.new do |s|
|
|||
"spec/unit/endpoint/endpoints_spec.rb",
|
||||
"spec/unit/endpoint/hooks_spec.rb",
|
||||
"spec/unit/endpoint/jobs_spec.rb",
|
||||
"spec/unit/endpoint/lint_spec.rb",
|
||||
"spec/unit/endpoint/logs_spec.rb",
|
||||
"spec/unit/endpoint/repos_spec.rb",
|
||||
"spec/unit/endpoint/users_spec.rb",
|
||||
"spec/unit/endpoint_spec.rb",
|
||||
|
|
Loading…
Reference in New Issue
Block a user