Skip to content

Sync only passed space and repository #1385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
2 changes: 1 addition & 1 deletion lib/travis/api/app/endpoint/assembla.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Endpoint
class Assembla < Endpoint
include Travis::Api::App::JWTUtils

REQUIRED_JWT_FIELDS = %w[name email login space_id id refresh_token].freeze
REQUIRED_JWT_FIELDS = %w[name email login space_id repository_id id refresh_token].freeze
CLUSTER_HEADER = 'HTTP_X_ASSEMBLA_CLUSTER'.freeze

set prefix: '/assembla'
Expand Down
4 changes: 3 additions & 1 deletion lib/travis/remote_vcs/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ def generate_token(provider: :github, token:, app_id: 1)
end
end

def sync(user_id:)
def sync(user_id:, space_id: nil, repository_id: nil)
request(:post, __method__) do |req|
req.url "users/#{user_id}/sync_data"
req.params['space_id'] = space_id if space_id
req.params['repository_id'] = repository_id if repository_id
end && true
end

Expand Down
2 changes: 1 addition & 1 deletion lib/travis/services/assembla_user_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def create_org_subscription(user, organization_id)
private

def sync_user(user_id)
Travis::RemoteVCS::User.new.sync(user_id: user_id)
Travis::RemoteVCS::User.new.sync(user_id: user_id, space_id: @payload['space_id'], repository_id: @payload['repository_id'])
rescue => e
raise SyncError, "Failed to sync user: #{e.message}"
end
Expand Down
26 changes: 26 additions & 0 deletions spec/travis/remote_vcs/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,32 @@
end
end

describe '#sync' do
let(:user_id) { 123 }
let(:space_id) { 456 }
let(:repository_id) { 789 }
let(:instance) { described_class.new }
let(:req) { double(:request) }
let(:params) { double(:params) }

subject { instance.sync(user_id: user_id, space_id: space_id, repository_id: repository_id) }

before do
allow(req).to receive(:url)
allow(req).to receive(:params).and_return(params)
allow(params).to receive(:[]=)
end

it 'performs POST to VCS with proper params' do
expect(instance).to receive(:request).with(:post, :sync).and_yield(req)
expect(req).to receive(:url).with("users/#{user_id}/sync_data")
expect(params).to receive(:[]=).with('space_id', space_id)
expect(params).to receive(:[]=).with('repository_id', repository_id)

expect(subject).to be true
end
end

describe '#authenticate' do
let(:user) { described_class.new }
let(:provider) { 'assembla' }
Expand Down
1 change: 1 addition & 0 deletions spec/unit/endpoint/assembla_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'space_id' => 'space123',
'id' => 'assembla_vcs_user_id',
'access_token' => 'test_access_token',
'repository_id' => 'repository123',
'refresh_token' => 'test_refresh_token'
}
end
Expand Down