From 7eb2617e48449080f1f50d754b5268dd8a440ca6 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 24 Nov 2015 15:50:38 +0100 Subject: [PATCH 1/6] Add branch_is_default info to commits --- lib/travis/api/v2/http/build.rb | 9 +++++++-- lib/travis/api/v2/http/job.rb | 9 +++++++-- spec/unit/api/v2/http/build_spec.rb | 1 + spec/unit/api/v2/http/job_spec.rb | 1 + 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/travis/api/v2/http/build.rb b/lib/travis/api/v2/http/build.rb index 9d8203b5..394c4ac8 100644 --- a/lib/travis/api/v2/http/build.rb +++ b/lib/travis/api/v2/http/build.rb @@ -17,7 +17,7 @@ module Travis def data { 'build' => build_data(build), - 'commit' => commit_data(build.commit), + 'commit' => commit_data(build.commit, build.repository), 'jobs' => options[:include_jobs] ? build.matrix.map { |job| job_data(job) } : [], 'annotations' => options[:include_jobs] ? Annotations.new(annotations(build), @options).data["annotations"] : [], } @@ -44,11 +44,12 @@ module Travis } end - def commit_data(commit) + def commit_data(commit, repository) { 'id' => commit.id, 'sha' => commit.commit, 'branch' => commit.branch, + 'branch_is_default' => branch_is_default(commit, repository), 'message' => commit.message, 'committed_at' => format_date(commit.committed_at), 'author_name' => commit.author_name, @@ -78,6 +79,10 @@ module Travis } end + def branch_is_default(commit, repository) + repository.default_branch == commit.branch + end + def annotations(build) build.matrix.map(&:annotations).flatten end diff --git a/lib/travis/api/v2/http/job.rb b/lib/travis/api/v2/http/job.rb index 4b712b40..92366474 100644 --- a/lib/travis/api/v2/http/job.rb +++ b/lib/travis/api/v2/http/job.rb @@ -15,7 +15,7 @@ module Travis def data { 'job' => job_data(job), - 'commit' => commit_data(job.commit), + 'commit' => commit_data(job.commit, job.repository), 'annotations' => Annotations.new(job.annotations, @options).data["annotations"], } end @@ -42,11 +42,12 @@ module Travis } end - def commit_data(commit) + def commit_data(commit, repository) { 'id' => commit.id, 'sha' => commit.commit, 'branch' => commit.branch, + 'branch_is_default' => branch_is_default(commit, repository), 'message' => commit.message, 'committed_at' => format_date(commit.committed_at), 'author_name' => commit.author_name, @@ -56,6 +57,10 @@ module Travis 'compare_url' => commit.compare_url, } end + + def branch_is_default(commit, repository) + repository.default_branch == commit.branch + end end end end diff --git a/spec/unit/api/v2/http/build_spec.rb b/spec/unit/api/v2/http/build_spec.rb index 11a6dbea..f276b2b8 100644 --- a/spec/unit/api/v2/http/build_spec.rb +++ b/spec/unit/api/v2/http/build_spec.rb @@ -29,6 +29,7 @@ describe Travis::Api::V2::Http::Build do 'id' => 1, 'sha' => '62aae5f70ceee39123ef', 'branch' => 'master', + 'branch_is_default' => true, 'message' => 'the commit message', 'compare_url' => 'https://github.com/svenfuchs/minimal/compare/master...develop', 'committed_at' => json_format_time(Time.now.utc - 1.hour), diff --git a/spec/unit/api/v2/http/job_spec.rb b/spec/unit/api/v2/http/job_spec.rb index a9211b6f..22fda7b6 100644 --- a/spec/unit/api/v2/http/job_spec.rb +++ b/spec/unit/api/v2/http/job_spec.rb @@ -31,6 +31,7 @@ describe Travis::Api::V2::Http::Job do 'sha' => '62aae5f70ceee39123ef', 'message' => 'the commit message', 'branch' => 'master', + 'branch_is_default' => true, 'message' => 'the commit message', 'committed_at' => json_format_time(Time.now.utc - 1.hour), 'committer_name' => 'Sven Fuchs', From ab1bfe0aeb4f2f91ac961512ba6445e7e5c05165 Mon Sep 17 00:00:00 2001 From: Lisa P Date: Thu, 25 Feb 2016 14:40:53 +0100 Subject: [PATCH 2/6] create MethodNotAllowed error --- lib/travis/api/v3/error.rb | 6 ++++++ lib/travis/api/v3/router.rb | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/travis/api/v3/error.rb b/lib/travis/api/v3/error.rb index fefd2b08..61d10882 100644 --- a/lib/travis/api/v3/error.rb +++ b/lib/travis/api/v3/error.rb @@ -35,4 +35,10 @@ module Travis::API::V3 super(message) end end + + class MethodNotAllowed < Error + def self.status + 405 + end + end end diff --git a/lib/travis/api/v3/router.rb b/lib/travis/api/v3/router.rb index 573c7c85..28085e81 100644 --- a/lib/travis/api/v3/router.rb +++ b/lib/travis/api/v3/router.rb @@ -15,8 +15,9 @@ module Travis::API::V3 return service_index(env) if env['PATH_INFO'.freeze] == ?/.freeze metrics = @metrics_processor.create access_control = AccessControl.new(env) - factory, params = routes.factory_for(env['REQUEST_METHOD'.freeze], env['PATH_INFO'.freeze]) env_params = params(env) + factory, params = routes.factory_for(env['REQUEST_METHOD'.freeze], env['PATH_INFO'.freeze]) + raise NotFound unless factory metrics.name_after(factory) From 04484271369dafac81fafbb2e1899a3e9f34bc6e Mon Sep 17 00:00:00 2001 From: Lisa P Date: Thu, 25 Feb 2016 15:06:45 +0100 Subject: [PATCH 3/6] create error in v3.rb --- lib/travis/api/v3.rb | 1 + lib/travis/api/v3/error.rb | 6 ------ spec/v3/error_handling_spec.rb | 15 +++++++++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 spec/v3/error_handling_spec.rb diff --git a/lib/travis/api/v3.rb b/lib/travis/api/v3.rb index 8c8be745..dd8c2af6 100644 --- a/lib/travis/api/v3.rb +++ b/lib/travis/api/v3.rb @@ -35,6 +35,7 @@ module Travis NotImplemented = ServerError .create('request not (yet) implemented', status: 501) RequestLimitReached = ClientError .create('request limit reached for resource', status: 429) AlreadySyncing = ClientError .create('sync already in progress', status: 409) + MethodNotAllowed = ClientError .create('method not allowed', status: 405) end end end diff --git a/lib/travis/api/v3/error.rb b/lib/travis/api/v3/error.rb index 61d10882..fefd2b08 100644 --- a/lib/travis/api/v3/error.rb +++ b/lib/travis/api/v3/error.rb @@ -35,10 +35,4 @@ module Travis::API::V3 super(message) end end - - class MethodNotAllowed < Error - def self.status - 405 - end - end end diff --git a/spec/v3/error_handling_spec.rb b/spec/v3/error_handling_spec.rb new file mode 100644 index 00000000..b86bf917 --- /dev/null +++ b/spec/v3/error_handling_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe Travis::API::V3::ServiceIndex do + let(:headers) {{ }} + let(:path) { "/v3/repo/1/enable" } + let(:json) { JSON.load(response.body) } + let(:response) { get(path, {}, headers) } + let(:resources) { json.fetch('resources') } + + it "handles wrong HTTP method with 405 status" do + + response.status.should == 405 + end + +end From f319dfbf65e2c5261d254ec1c9325a6778c3445e Mon Sep 17 00:00:00 2001 From: Hiro Asari Date: Thu, 25 Feb 2016 16:06:32 -1000 Subject: [PATCH 4/6] Update travis-yaml --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 09ee17b3..29745665 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -87,7 +87,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-yaml.git - revision: 9ebe328e7546c696dd374a8cf773d93276f98e4f + revision: 032caed23af8ed1ed55e9204bb91316f3ada2f74 specs: travis-yaml (0.2.0) From b6b1d12f48baee5bba259fcabc7e5cc46c4da54e Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 2 Mar 2016 15:14:27 +0100 Subject: [PATCH 5/6] Hardcode database pool size for sidekiq For some reason pool is set to 1 and I can't find the source of this setting, so for now, just to fix the immediate problem I'm setting it manually in sidekiq.rb --- lib/travis/sidekiq.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/travis/sidekiq.rb b/lib/travis/sidekiq.rb index ef5aa91c..4d228473 100644 --- a/lib/travis/sidekiq.rb +++ b/lib/travis/sidekiq.rb @@ -7,6 +7,7 @@ require 'travis/api/workers/job_cancellation' require 'travis/api/workers/job_restart' require 'travis/support/amqp' +Travis.config.database[:pool] = 5 Travis::Database.connect if Travis.config.logs_database From fa8520eb2520469a005930af67cd22a85964584b Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 2 Mar 2016 16:14:01 +0100 Subject: [PATCH 6/6] Revert "Hardcode database pool size for sidekiq" This reverts commit b6b1d12f48baee5bba259fcabc7e5cc46c4da54e. The pool size can be set with DATABASE_POOL_SIZE ENV var on heroku. I set it to 5, so it's ok, to revert this change. --- lib/travis/sidekiq.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/travis/sidekiq.rb b/lib/travis/sidekiq.rb index 4d228473..ef5aa91c 100644 --- a/lib/travis/sidekiq.rb +++ b/lib/travis/sidekiq.rb @@ -7,7 +7,6 @@ require 'travis/api/workers/job_cancellation' require 'travis/api/workers/job_restart' require 'travis/support/amqp' -Travis.config.database[:pool] = 5 Travis::Database.connect if Travis.config.logs_database