require 'helix_versioning_engine/change_service' require 'helix_versioning_engine/submit_service' module HelixVersioningEngine # Add methods related to changelist resources. class App < Sinatra::Base # Convenience method to list changelist metadata with some common filtering # options. # # parameters: # - `max` = number # - `status` = pending|submitted|shelved # - `user` = perforce login # - `files` = pattern get '/helix_versioning_engine/:api/changes' do |_| require_p4 max = params['max'] if params.key?('max') status = params['status'] if params.key?('status') user = params['user'] if params.key?('user') files = params['files'] if params.key?('files') p4 = env['p4'] args = ['changes'] args.push('-m', max) if max args.push('-s', status) if status args.push('-u', user) if user args.push(files) if files results = p4.run(*args) results.to_json end # Create a new changelist with edits to multiple files. post '/helix_versioning_engine/:api/changes' do |_| require_p4_with_temp_client description = params['Description'] || 'Edited files' files = params['Files'] depot_paths = files.map { |f| f['DepotFile'] } p4 = env['p4'] client_root = env['p4_root'] client_name = p4.client change_service = ChangeService.new(p4: p4, client_root: client_root, client_name: client_name) files = files.map{ |f| HelixVersioningEngine::ChangeService::File.from_json(f) } change_service.submit(files: files, description: description) '' end # Uses describe to produce the list of opened files regardless of client. # # There is a little bit of an open question regarding performance. The # p4ruby usage here does *not* generate diffs of changes, which the base # command line seems to want to do. If the output accumulates a lot of RAM # for large diffs, we could be in trouble. get '/helix_versioning_engine/:api/changes/:change' do |_, change| require_p4 results = env['p4'].run_describe('-S', change) results.to_json end # This will perform a submit -e for the indicated change. # # If the change happens to reference a stream client, this will have to # generate a different kind of temporary client. We defer the client # creation logic to the service layer. post '/helix_versioning_engine/:api/changes/:change' do |_, change| require_p4 submit_service = SubmitService.new(p4: env['p4'], env: env) submit_service.submit_shelf(change) '' end end end