require 'projects/project_service' require 'helix_web_services_client/models/project/helix_sync_extension' require 'sync/errors/one_branch_only' module Sync # This service stores it's projects via the main project service, but # makes a few other adjustments. # # Settings used: # # - project_p4_url # - default_stream_depot # class SyncProjectService # Access to the p4 instance, typically initialized from the user's # connection attr_accessor :p4 attr_accessor :client_name attr_accessor :client_root attr_accessor :settings @@extension_model = HelixWebServicesClient::Models::Project::HelixSyncExtension def initialize(p4: nil, client_name: nil, client_root: nil, settings: nil) @p4 = p4 @client_name = client_name @client_root = client_root @settings = settings end # Use the members filter with the current user's login for a "my projects" # concept. def find(names: nil, owners: nil, members: nil) options = { extensions: @@extension_model.content_type } options[:members] = members if members options[:names] = names if names options[:owners] = owners if owners create_project_service.find(options) end def find_by_id(project_id) create_project_service.find_by_id(project_id) end def create(project, depot_dir) # This removes a lot of the work of choosing a single existing branch # from the client. if (depot_dir) unless project.branches project.branches = [] end project.branches << create_depot_branch(depot_dir) end project_service = create_project_service project_service.set_defaults(project) set_default_extension_model(project) set_default_branch(project) project_service.create(project) end def update(project) create_project_service.update(project) end def create_project_service Projects::ProjectService.new(p4: p4, client_name: client_name, client_root: client_root, settings: settings) end # This demands def default_p4_url settings.project_p4_url end private def set_default_extension_model(project) unless project.extensions.key?(@@extension_model.content_type) ext_model = @@extension_model.new ext_model.p4 = default_p4_url project.extensions[@@extension_model.content_type] = ext_model end end def set_default_branch(project) if project.branches.nil? || project.branches.empty? project.branches = [] unless project.branches project.branches << create_default_stream_branch(project) end end def create_depot_branch(depot_dir) HelixWebServicesClient::Models::Project::BranchRef.new( id: 'main', name: 'main', view: [ HelixWebServicesClient::Models::Project::ViewRef.new( depot_path: "#{depot_dir}/...", view_path: '...' ) ] ) end # Create a new stream for the new project, and assign it to a BranchRef. # We have to assume the user has write privileges to create the new stream # in our dedicated project stream depot. def create_default_stream_branch(project) stream_id = create_default_stream(project) HelixWebServicesClient::Models::Project::BranchRef.new( id: 'main', name: 'main', stream: stream_id ) end def create_default_stream(project) spec = p4.fetch_stream(default_stream(project)) spec._owner = project.owner spec._name = project.name spec._description = project.description spec._type = 'mainline' spec._parent = 'none' spec._paths = ['share ...'] p4.save_stream(spec) spec._stream end def default_stream(project) "#{settings.default_stream_depot}/#{project.id}" end end # TODO register a handler to validate projects with the HelixSyncExtension # -> 1 branch only! Projects::ProjectService.before_create << lambda do |project, options| if project.extensions.key?(HelixWebServicesClient::Models::Project::HelixSyncExtension.content_type) if !project.branches || project.branches.length != 1 raise Sync::Errors::OneBranchOnly end end end end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#7 | 15098 | tjuricek |
Revised project services to GET-only forms. With Helix Sync revising to integrate purely with Helix Cloud, this is the only thing we can reasonably define. |
||
#6 | 15078 | tjuricek |
clients spec method revisions Updated some other documentation. |
||
#5 | 14152 | tjuricek | Allow 'depot_dir' argument to be nil by default | ||
#4 | 14151 | tjuricek |
Add depot tree control and selection to the create projects page. Styling and error checking is kept to a minimum for the time being. Our goal is just internal workflow and feedback. |
||
#3 | 13939 | tjuricek |
First pass at sync project service. Includes a first pass at validating projects enabled for Sync. (There's only one branch check at the moment.) Does not include the HTTP layer. |
||
#2 | 13891 | tjuricek |
Added a 'member' concept to projects. members is the start of a basic project 'role' definition. In Helix sync, this is mostly just used to indicate this is a "my Project" in the UI and a project member can have the ability to leave the project or add someone else. Eventually, we expect "members" to mean more, like, is part of a group that has write access to the files of the project. But that sort of definition is very TBD. |
||
#1 | 13884 | tjuricek | Add Project extension classes models, and the ability for the Project to handle before- and after- create callbacks to other services. |