Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 31, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/services/kanbanize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ def receive_event
issues_board_id = data['project_issues_board_id'].to_s

# check the branch restriction is poplulated and branch is not included
branch = payload['ref'].split('/').last
if branch_restriction.length > 0 && branch_restriction.index(branch) == nil
return
if event.to_s == 'push'
branch = payload['ref'].split('/').last
if branch_restriction.length > 0 && branch_restriction.index(branch) == nil
return
end
end

http_post "http://#{domain_name}/index.php/api/kanbanize/git_hub_event",
Expand Down
4 changes: 2 additions & 2 deletions test/kanbanize_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_push_with_issue_tracking
@stubs.post url do |env|
assert_equal 'testdomain.kanbanize.com', env[:url].host
assert_equal '/index.php/api/kanbanize/git_hub_event', env[:url].request_uri
assert_equal %({"ref":"refs/heads/mybranch2"}), env[:body]
assert_equal %({"action":"created"}), env[:body]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you be testing both of these in a separate test? One for the push event and one for the issue event?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created two tests because the cases are different.
For the push case, we check that when a branch filter is applied the test will pass for the provided repo ref.
For the issue event we don't provide a "ref" property in the payload(which was the reason the service was failing) and I check this in a separate test case.

assert_equal 'a1b2c3==', env[:request_headers]['apikey']
assert_equal '', env[:request_headers]['branch-filter']
assert_equal false, env[:request_headers]['last-commit']
Expand All @@ -55,7 +55,7 @@ def test_push_with_issue_tracking
[200, {}, '']
end

svc = service({'kanbanize_domain_name' => 'testdomain.kanbanize.com', 'kanbanize_api_key' => 'a1b2c3==', 'track_project_issues_in_kanbanize' => '1', 'project_issues_board_id' => '131'}, {'ref' => 'refs/heads/mybranch2'})
svc = service(:issues, {'kanbanize_domain_name' => 'testdomain.kanbanize.com', 'kanbanize_api_key' => 'a1b2c3==', 'track_project_issues_in_kanbanize' => '1', 'project_issues_board_id' => '131'}, {'action' => 'created'})
svc.receive_event
end

Expand Down