From ba9b69792b868027423731ed629736808af00fcd Mon Sep 17 00:00:00 2001 From: jently Date: Wed, 15 Jan 2014 10:57:43 -0800 Subject: [PATCH 1/4] SugarCRM changes --- config/sample-config.yaml.erb | 25 +++++++++++++------------ lib/jenkins.rb | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/config/sample-config.yaml.erb b/config/sample-config.yaml.erb index 8f514e2..b711214 100644 --- a/config/sample-config.yaml.erb +++ b/config/sample-config.yaml.erb @@ -15,8 +15,8 @@ # For example, if you were to store your GitHub login as the GITHUB_LOGIN # environment variable, then you could specify your GitHub login like this: # :github_login: <%= ENV['GITHUB_LOGIN'] %> -:github_login: github_login -:github_password: github_password +:github_login: vood +:github_password: v99d999 #:github_oauth_token: github_oauth_token # To use Jently with GitHub Enterprise, you'll need to set the GitHub @@ -27,23 +27,23 @@ # The repository that contains the pull requests you want to run tests on. # For example, if you wanted to test the pull requests of the Jently repository, # you would put git@github.com:vaneyckt/Jently.git here. -:github_ssh_repository: git@github.com:vaneyckt/Jently.git +:github_ssh_repository: git@github.com:sugareps/Mango.git # The interval between successive communications with GitHub. # This makes sure we don't end up spamming GitHub's servers. -:github_polling_interval_seconds: 60 +:github_polling_interval_seconds: 10 # If access to your Jenkins CI is restricted with a login and password, # you can enther these here. Otherwise you should comment out or delete these lines. -:jenkins_login: jenkins_login -:jenkins_password: jenkins_password +:jenkins_login: avysotsky +:jenkins_password: changeme # The url that your Jenkins CI can be found at. -:jenkins_url: jenkins_url +:jenkins_url: http://10.8.7.59:8080 # The Jenkins build job for testing that you set up in step 1 of the installation # guide at https://github.com/vaneyckt/Jently/blob/master/README.rdoc. -:jenkins_job_name: test_job +:jenkins_job_name: Jently # The amount of time Jently will wait for a test job to complete before marking it # as timed out. A good number for this is twice the amount of time that the test job @@ -52,10 +52,11 @@ # The interval between successive polling requests that Jently makes to Jenkins in # order to query the state of the test job. -:jenkins_polling_interval_seconds: 60 +:jenkins_polling_interval_seconds: 10 # By default, Jently tests all pull requests. If you only want Jently to test pull requests that # are to be merged into specific branches, uncomment the following, and specify these branches, one per line. -#:whitelist_branches: -# - master -# - release +:whitelist_branches: + - ibm_r12_hotfix2 + - ibm_r13 + - ibm_sugar7_migration diff --git a/lib/jenkins.rb b/lib/jenkins.rb index edd80b3..b30023e 100644 --- a/lib/jenkins.rb +++ b/lib/jenkins.rb @@ -20,7 +20,7 @@ def Jenkins.get_nb_of_idle_executors req.params[:tree] = 'assignedLabels[idleExecutors]' req.params[:random] = Time.now.to_i end - response.body[:assignedLabels][0][:idleExecutors] + return 1 #response.body[:assignedLabels][0][:idleExecutors] rescue => e Logger.log('Error when getting nb of idle executors', e) sleep 5 From 3c903a74e36383e398040ccbe77a157df89c9e02 Mon Sep 17 00:00:00 2001 From: Artem Vysotsky Date: Thu, 16 Jan 2014 11:13:16 -0800 Subject: [PATCH 2/4] Make watching base branch changes optional Make waiting for idle jenkins job optional --- config/sample-config.yaml.erb | 29 +++++++++++-------- lib/core.rb | 5 ++-- lib/helpers/pull_requests_data.rb | 3 +- lib/jenkins.rb | 2 +- spec/core_spec.rb | 38 +++++++++++++++++++++++++ spec/helpers/pull_requests_data_spec.rb | 22 ++++++++++++++ 6 files changed, 83 insertions(+), 16 deletions(-) diff --git a/config/sample-config.yaml.erb b/config/sample-config.yaml.erb index b711214..e5eedba 100644 --- a/config/sample-config.yaml.erb +++ b/config/sample-config.yaml.erb @@ -15,8 +15,8 @@ # For example, if you were to store your GitHub login as the GITHUB_LOGIN # environment variable, then you could specify your GitHub login like this: # :github_login: <%= ENV['GITHUB_LOGIN'] %> -:github_login: vood -:github_password: v99d999 +:github_login: github_login +:github_password: github_password #:github_oauth_token: github_oauth_token # To use Jently with GitHub Enterprise, you'll need to set the GitHub @@ -27,23 +27,26 @@ # The repository that contains the pull requests you want to run tests on. # For example, if you wanted to test the pull requests of the Jently repository, # you would put git@github.com:vaneyckt/Jently.git here. -:github_ssh_repository: git@github.com:sugareps/Mango.git +:github_ssh_repository: git@github.com:vaneyckt/Jently.git # The interval between successive communications with GitHub. # This makes sure we don't end up spamming GitHub's servers. -:github_polling_interval_seconds: 10 +:github_polling_interval_seconds: 60 + +# By default Jently reschedules open pull request if base branch has been updated +:github_watch_base_branch_update: true # If access to your Jenkins CI is restricted with a login and password, # you can enther these here. Otherwise you should comment out or delete these lines. -:jenkins_login: avysotsky -:jenkins_password: changeme +:jenkins_login: jenkins_login +:jenkins_password: jenkins_password # The url that your Jenkins CI can be found at. -:jenkins_url: http://10.8.7.59:8080 +:jenkins_url: jenkins_url # The Jenkins build job for testing that you set up in step 1 of the installation # guide at https://github.com/vaneyckt/Jently/blob/master/README.rdoc. -:jenkins_job_name: Jently +:jenkins_job_name: test_job # The amount of time Jently will wait for a test job to complete before marking it # as timed out. A good number for this is twice the amount of time that the test job @@ -52,11 +55,13 @@ # The interval between successive polling requests that Jently makes to Jenkins in # order to query the state of the test job. -:jenkins_polling_interval_seconds: 10 +:jenkins_polling_interval_seconds: 60 + +# Wait while jenkins job becomes idle +:jenkins_wait_for_idle_executor: true # By default, Jently tests all pull requests. If you only want Jently to test pull requests that # are to be merged into specific branches, uncomment the following, and specify these branches, one per line. :whitelist_branches: - - ibm_r12_hotfix2 - - ibm_r13 - - ibm_sugar7_migration +# - master +# - release diff --git a/lib/core.rb b/lib/core.rb index 176aa6f..238b53c 100755 --- a/lib/core.rb +++ b/lib/core.rb @@ -9,7 +9,7 @@ def Core.test_pull_request(pull_request_id) end if pull_request[:mergeable] == true - Jenkins.wait_for_idle_executor + Jenkins.wait_for_idle_executor if config.fetch(:jenkins_wait_for_idle_executor, true) thr = Thread.new do Github.set_pull_request_status(pull_request_id, {:status => 'pending', :description => 'Started work on pull request.'}) @@ -28,12 +28,13 @@ def Core.test_pull_request(pull_request_id) end def Core.poll_pull_requests_and_queue_next_job + config = ConfigFile.read open_pull_requests_ids = Github.get_open_pull_requests_ids PullRequestsData.remove_dead_pull_requests(open_pull_requests_ids) open_pull_requests_ids.each do |pull_request_id| pull_request = Github.get_pull_request(pull_request_id) - if PullRequestsData.outdated_success_status?(pull_request) + if PullRequestsData.outdated_success_status?(pull_request) && config.fetch(:github_watch_base_branch_update, true) Github.set_pull_request_status(pull_request[:id], {:status => 'success', :description => "This has been rescheduled for testing as the '#{pull_request[:base_branch]}' branch has been updated."}) end PullRequestsData.update(pull_request) diff --git a/lib/helpers/pull_requests_data.rb b/lib/helpers/pull_requests_data.rb index a13ad20..69300dd 100755 --- a/lib/helpers/pull_requests_data.rb +++ b/lib/helpers/pull_requests_data.rb @@ -64,6 +64,7 @@ def PullRequestsData.get_new_priority(pull_request) def PullRequestsData.test_required?(pull_request) return false if pull_request[:merged] + config = ConfigFile.read data = read is_new = !data.has_key?(pull_request[:id]) @@ -74,7 +75,7 @@ def PullRequestsData.test_required?(pull_request) has_valid_status = ['success', 'failure'].include?(pull_request[:status]) was_updated = (is_new) ? false : (data[pull_request[:id]][:head_sha] != pull_request[:head_sha]) || - (data[pull_request[:id]][:base_sha] != pull_request[:base_sha]) + (data[pull_request[:id]][:base_sha] != pull_request[:base_sha] && config.fetch(:github_watch_base_branch_update, true)) is_test_required = is_new || is_waiting_to_be_tested || has_inconsistent_status || has_invalid_status || (has_valid_status && was_updated) end diff --git a/lib/jenkins.rb b/lib/jenkins.rb index b30023e..edd80b3 100644 --- a/lib/jenkins.rb +++ b/lib/jenkins.rb @@ -20,7 +20,7 @@ def Jenkins.get_nb_of_idle_executors req.params[:tree] = 'assignedLabels[idleExecutors]' req.params[:random] = Time.now.to_i end - return 1 #response.body[:assignedLabels][0][:idleExecutors] + response.body[:assignedLabels][0][:idleExecutors] rescue => e Logger.log('Error when getting nb of idle executors', e) sleep 5 diff --git a/spec/core_spec.rb b/spec/core_spec.rb index e85a394..5cb901b 100755 --- a/spec/core_spec.rb +++ b/spec/core_spec.rb @@ -15,6 +15,7 @@ PullRequestsData.stub(:update) PullRequestsData.stub(:get_pull_request_id_to_test).and_return(nil) Core.stub(:test_pull_request) + ConfigFile.stub(:read).and_return({}) end it 'retrieves a list of open pull request ids from Github' do @@ -69,6 +70,29 @@ Core.poll_pull_requests_and_queue_next_job end end + + context 'when base branch has been updated and github_watch_base_branch_update is false' do + it 'does not trigger any new pull request tests' do + PullRequestsData.stub(:outdated_success_status?).and_return(true) + ConfigFile.stub(:read).and_return(:github_watch_base_branch_update => false) + Github.should_not_receive(:set_pull_request_status) + + Core.poll_pull_requests_and_queue_next_job + end + end + + context 'when base branch has been updated and github_watch_base_branch_update is true' do + it 'triggers any new pull request tests' do + PullRequestsData.stub(:outdated_success_status?).and_return(true) + ConfigFile.stub(:read).and_return(:github_watch_base_branch_update => true) + Github.should_receive(:set_pull_request_status) + + Core.poll_pull_requests_and_queue_next_job + end + end + + + context end describe '.test_pull_request' do @@ -126,6 +150,20 @@ Core.test_pull_request(pull_request_id) end + it 'should not wait for an idle executor if jenkins_wait_for_idle_executor is false' do + Jenkins.should_not_receive(:wait_for_idle_executor) + ConfigFile.stub(:read).and_return(:jenkins_wait_for_idle_executor => false) + + Core.test_pull_request(pull_request_id) + end + + it 'should wait for an idle executor if jenkins_wait_for_idle_executor is false' do + Jenkins.should_not_receive(:wait_for_idle_executor) + ConfigFile.stub(:read).and_return(:jenkins_wait_for_idle_executor => false) + + Core.test_pull_request(pull_request_id) + end + context 'when the Jenkins job takes less time than the jenkins_job_timeout_seconds value' do it 'does not tell Github to mark the pull request status as timed out' do Jenkins.stub(:wait_on_job) do |job| diff --git a/spec/helpers/pull_requests_data_spec.rb b/spec/helpers/pull_requests_data_spec.rb index fc10b09..2d38f61 100644 --- a/spec/helpers/pull_requests_data_spec.rb +++ b/spec/helpers/pull_requests_data_spec.rb @@ -260,6 +260,7 @@ before do PullRequestsData.write( id => stored_pr ) + ConfigFile.stub(:read).and_return({}) end it 'is true if the stored pr and specified pr have different a head sha' do @@ -282,6 +283,7 @@ before do PullRequestsData.write( id => stored_pr ) + ConfigFile.stub(:read).and_return({}) end it 'is true if the stored pr and specified pr have different a head sha' do @@ -296,6 +298,26 @@ PullRequestsData.test_required?( stored_pr ).should be_false end end + + context 'when base sha has changed' do + let(:head_sha) { 'abc123' } + let(:base_sha) { 'def456' } + let(:stored_pr) { {:id => id, :merged => false, :status => 'success', :head_sha => head_sha, :base_sha => base_sha } } + + before do + PullRequestsData.write( id => stored_pr ) + end + + it 'is true when github_watch_base_branch_update set to true' do + ConfigFile.stub(:read).and_return(:github_watch_base_branch_update => true) + PullRequestsData.test_required?( stored_pr.merge(:base_sha => 'othersha') ).should be_true + end + + it 'is false when github_watch_base_branch_update set to false' do + ConfigFile.stub(:read).and_return(:github_watch_base_branch_update => false) + PullRequestsData.test_required?( stored_pr.merge(:base_sha => 'othersha') ).should be_false + end + end end end end From 07a4bc7cfbbf9ed932686408a08a765632ac9624 Mon Sep 17 00:00:00 2001 From: Artem Vysotsky Date: Thu, 16 Jan 2014 11:15:35 -0800 Subject: [PATCH 3/4] Update sample-config.yaml.erb --- config/sample-config.yaml.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/sample-config.yaml.erb b/config/sample-config.yaml.erb index e5eedba..c3c265e 100644 --- a/config/sample-config.yaml.erb +++ b/config/sample-config.yaml.erb @@ -62,6 +62,6 @@ # By default, Jently tests all pull requests. If you only want Jently to test pull requests that # are to be merged into specific branches, uncomment the following, and specify these branches, one per line. -:whitelist_branches: +#:whitelist_branches: # - master # - release From 5d819cc8062e0799ff56df5a3747a578b7d080bd Mon Sep 17 00:00:00 2001 From: Artem Vysotsky Date: Thu, 16 Jan 2014 12:39:30 -0800 Subject: [PATCH 4/4] Add pull request id to the jenkins job --- lib/jenkins.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/jenkins.rb b/lib/jenkins.rb index edd80b3..a9a73b2 100644 --- a/lib/jenkins.rb +++ b/lib/jenkins.rb @@ -42,6 +42,7 @@ def Jenkins.start_job(pull_request_id) req.params[:id] = job_id req.params[:branch] = "origin/pr/#{pull_request_id}/merge" req.params[:repository] = config[:github_ssh_repository] + req.params[:pull_request_id] = pull_request_id req.params[:random] = Time.now.to_i end job_id