Skip to content

Commit e4227ba

Browse files
Merge pull request #1385 from travis-ci/TBT-382-sync-org-and-repo
Sync only passed space and repository
2 parents 65a72ca + daaafb7 commit e4227ba

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed

lib/travis/api/app/endpoint/assembla.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Endpoint
1212
class Assembla < Endpoint
1313
include Travis::Api::App::JWTUtils
1414

15-
REQUIRED_JWT_FIELDS = %w[name email login space_id id refresh_token].freeze
15+
REQUIRED_JWT_FIELDS = %w[name email login space_id repository_id id refresh_token].freeze
1616
CLUSTER_HEADER = 'HTTP_X_ASSEMBLA_CLUSTER'.freeze
1717

1818
set prefix: '/assembla'

lib/travis/remote_vcs/user.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ def generate_token(provider: :github, token:, app_id: 1)
3535
end
3636
end
3737

38-
def sync(user_id:)
38+
def sync(user_id:, space_id: nil, repository_id: nil)
3939
request(:post, __method__) do |req|
4040
req.url "users/#{user_id}/sync_data"
41+
req.params['space_id'] = space_id if space_id
42+
req.params['repository_id'] = repository_id if repository_id
4143
end && true
4244
end
4345

lib/travis/services/assembla_user_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def create_org_subscription(user, organization_id)
4242
private
4343

4444
def sync_user(user_id)
45-
Travis::RemoteVCS::User.new.sync(user_id: user_id)
45+
Travis::RemoteVCS::User.new.sync(user_id: user_id, space_id: @payload['space_id'], repository_id: @payload['repository_id'])
4646
rescue => e
4747
raise SyncError, "Failed to sync user: #{e.message}"
4848
end

spec/travis/remote_vcs/user_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,32 @@
4949
end
5050
end
5151

52+
describe '#sync' do
53+
let(:user_id) { 123 }
54+
let(:space_id) { 456 }
55+
let(:repository_id) { 789 }
56+
let(:instance) { described_class.new }
57+
let(:req) { double(:request) }
58+
let(:params) { double(:params) }
59+
60+
subject { instance.sync(user_id: user_id, space_id: space_id, repository_id: repository_id) }
61+
62+
before do
63+
allow(req).to receive(:url)
64+
allow(req).to receive(:params).and_return(params)
65+
allow(params).to receive(:[]=)
66+
end
67+
68+
it 'performs POST to VCS with proper params' do
69+
expect(instance).to receive(:request).with(:post, :sync).and_yield(req)
70+
expect(req).to receive(:url).with("users/#{user_id}/sync_data")
71+
expect(params).to receive(:[]=).with('space_id', space_id)
72+
expect(params).to receive(:[]=).with('repository_id', repository_id)
73+
74+
expect(subject).to be true
75+
end
76+
end
77+
5278
describe '#authenticate' do
5379
let(:user) { described_class.new }
5480
let(:provider) { 'assembla' }

spec/unit/endpoint/assembla_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
'space_id' => 'space123',
1515
'id' => 'assembla_vcs_user_id',
1616
'access_token' => 'test_access_token',
17+
'repository_id' => 'repository123',
1718
'refresh_token' => 'test_refresh_token'
1819
}
1920
end

0 commit comments

Comments
 (0)