Permalink
Browse files

add ability to disable processing of not distinct commits

  • Loading branch information...
1 parent 3adc8da commit 4d24835efd3e560208c469e082fd6f7ee07abe5b anna.zhdan committed Feb 17, 2014
Showing with 65 additions and 7 deletions.
  1. +4 −1 docs/youtrack
  2. +5 −0 lib/services/you_track.rb
  3. +56 −6 test/youtrack_test.rb
View
5 docs/youtrack
@@ -3,7 +3,7 @@
- Requires YouTrack version 2.0 or above. YouTrack Energy EAP builds are
supported as well.
- - Your YouTrack server should be acessible from the internet.
+ - Your YouTrack server should be accessible from the internet.
- REST API must be enabled in your YouTrack server.
@@ -24,3 +24,6 @@
- Branch names to track separated by space. If branches are provided, only commits to those branches will trigger
YouTrack commands and commits to others will be ignored. If the branch field is left empty, commits on any branch will trigger commands.
+
+ - If only distinct commits should be processed. If this setting is false, same commit may be processed several times
+ (for example, when branches are merged)
View
5 lib/services/you_track.rb
@@ -1,5 +1,6 @@
class Service::YouTrack < Service
string :base_url, :committers, :username, :branch
+ boolean :process_distinct
password :password
white_list :base_url, :username, :committers, :branch
@@ -51,6 +52,10 @@ def login
def process_commit(commit)
author = nil
+
+ #If only distinct commits should be processed, check this
+ return unless commit['distinct'] or !(data['process_distinct'])
+
commit['message'].split("\n").each { |commit_line|
issue_id = commit_line[/( |^)#(\w+-\d+)\b/, 2]
next if issue_id.nil?
View
62 test/youtrack_test.rb
@@ -3,6 +3,8 @@
class YouTrackTest < Service::TestCase
def setup
@stubs = Faraday::Adapter::Test::Stubs.new
+ @data = {'base_url' => 'http://yt.com/abc', 'committers' => 'c',
+ 'username' => 'u', 'password' => 'p'}
end
def valid_process_stubs
@@ -29,7 +31,7 @@ def valid_process_stubs
end
end
- def test_push
+ def valid_process_stubs_case_1
valid_process_stubs
@stubs.post "/abc/rest/issue/case-1/execute" do |env|
@@ -39,12 +41,17 @@ def test_push
assert_equal 'mojombo', env[:params]['runAs']
[200, {}, '']
end
+ end
+
+
+
+ def test_push
+ valid_process_stubs_case_1
hash = payload
hash['commits'].first['message'].sub! /Case#1/, '#case-1 zomg omg'
- svc = service({'base_url' => 'http://yt.com/abc', 'committers' => 'c',
- 'username' => 'u', 'password' => 'p'}, hash)
+ svc = service(@data, hash)
svc.receive_push
@stubs.verify_stubbed_calls
@@ -65,15 +72,14 @@ def test_branch_match
hash['commits'].first['message'].sub! /Case#1/, '#case-2!! zomg omg'
hash['ref'] = 'refs/heads/master'
- svc = service({'base_url' => 'http://yt.com/abc', 'committers' => 'c',
- 'username' => 'u', 'password' => 'p', 'branch' => 'master dev'}, hash)
+ svc = service(@data.merge({'branch' => 'master dev' }), hash)
svc.receive_push
@stubs.verify_stubbed_calls
end
def test_branch_mismatch
- payload = { 'ref' => 'refs/heads/master' }
+ payload = {'ref' => 'refs/heads/master'}
svc = service({'base_url' => '', 'branch' => 'other'}, payload)
@@ -82,6 +88,50 @@ def test_branch_mismatch
assert_nothing_raised { svc.receive_push }
end
+ def test_process_not_distinct
+ valid_process_stubs_case_1
+
+ hash = payload
+ hash['commits'].each { |commit|
+ commit['distinct'] = false
+ }
+ hash['commits'].first['message'].sub! /Case#1/, '#case-1 zomg omg'
+
+ svc = service(@data.merge({'process_distinct' => false}), hash)
+
+ svc.receive_push
+
+ @stubs.verify_stubbed_calls
+ end
+
+ def test_process_distinct
+ valid_process_stubs_case_1
+
+ hash = payload
+ hash['commits'].first['message'].sub! /Case#1/, '#case-1 zomg omg'
+
+ svc = service(@data.merge({'process_distinct' => true}), hash)
+
+ svc.receive_push
+
+ @stubs.verify_stubbed_calls
+ end
+
+ def test_dont_process_not_distinct
+
+ hash = payload
+ hash['commits'].each { |commit|
+ commit['distinct'] = false
+ }
+ hash['commits'].first['message'].sub! /Case#1/, '#case-1 zomg omg'
+
+ svc = service(@data.merge({'process_distinct' => true}), hash)
+
+ svc.receive_push
+
+ @stubs.verify_stubbed_calls
+ end
+
def service(*args)
super Service::YouTrack, *args
end

0 comments on commit 4d24835

Please sign in to comment.