require 'helix_web_services_client/open_model' require 'open-uri' class HelixWebServicesClient # List changelists in the system # # options: # - :max - cap the number of results # - :status - :pending, :submitted, or :shelved (see Change) # - :user - The perforce login to check out # - :files - Depot path pattern to restrict changes to def changes(options = nil) arr = execute_method_no_body(:get, hve_path('changes'), options) arr.map { |obj| OpenModel.new(obj) } end # Returns the Change indicated by the change number or model. # # If there are files submitted with the change, the change.files field # should be filled out. def change(change) change_id = change.is_a?(OpenModel) ? change.change : change arr = execute_method_no_body(:get, hve_path("changes/#{change_id}")) OpenModel.new(arr.first) end # Creates a new changelist, that can be used for a few different tasks. # # The change should be a hash with the following top-level keys: # # - `Description`: The change description (optional) # # - `Files`: An array of Hashes # # Each hash in the `Files` array can contain these keys: # # - `DepotFile`: The depot path # # - `Action`: One of 'upload', 'move', or 'branch' # # - `FromDepotFile`: if action is 'move' or 'branch', the source file # # - `Content`: Base64-encoded file content for 'upload' actions # # - `RequireVersion`: Optional value for 'upload' actions, if set, will # fail the upload if the current file version is not # this version. # # @param change [Hash] See method description def create_change(change) change = OpenModel.new(change) unless change.is_a?(OpenModel) execute_method_with_body(:post, hve_path('changes'), nil, change.marshal_dump) end # Submits the shelved changelist. # # This changelist should be pending, with no open files, and list of shelved # changes. If you require resolves, this method will fail. # # @param change [String] The changelist number def commit_change(change) change_id = change.is_a?(OpenModel) ? change.change : URI.encode(change) execute_method_no_body(:post, hve_path("changes/#{change_id}")) end end