require 'p4_project_services_data' require 'p4_web_api_client' module P4PhoenixServices # Core logic to create Phoenix projects in the system class CreateProject attr_accessor :project_client attr_accessor :settings attr_accessor :web_api_client def initialize(project_client: nil, settings: nil, web_api_client: nil) @project_client = project_client @settings = settings @web_api_client = web_api_client @created_stream = nil end def run(project) set_default_stream_definition(project) set_default_phoenix_extension(project) update_change(project) updated = project_client.create_project(project) cache_stream_definitions(updated) updated end def set_default_phoenix_extension(project) unless project.extension_keys.include?(Extensions::Phoenix.content_type) project.extensions = {} unless project.extensions project.extensions[Extensions::Phoenix.content_type] = Extensions::Phoenix.new(p4: "p4://#{settings.p4['port']}/") end end # If there is no stream definition on the project instance, we'll create # a new stream, based on some basic conventions. def set_default_stream_definition(project) return unless project.branches.nil? or project.branches.empty? stream = P4WebApiClient::Models::Stream.new stream.stream = "//#{settings.phoenix_project_depot}/#{project.id}" stream.name = project.id stream.description = "Phoenix Project '#{project.name}'" stream.type = :mainline stream.parent = 'none' stream.paths = ['share ...'] web_api_client.create_stream(stream) @created_stream = stream branch = P4ProjectServicesData::Branch.new branch.id = 'main' branch.name = 'main' branch.stream = stream.stream project.branches = [branch] end # We store a simple definition of each include path in the stream, in order # to detect changes to the project done via notifications. def cache_stream_definitions(project) stream = web_api_client.stream(project.branches.first.stream) cache_project = P4PhoenixServices::Project.new cache_project.id = project.id cache_project.version = project.version cache_project.change = project.extensions[Extensions::Phoenix.content_type].change cache_project.save cache_stream = P4PhoenixServices::Stream.new cache_stream.stream = stream.stream cache_project.add_stream(cache_stream) cache_project.save stream.paths.each do |path_def| cache_path = P4PhoenixServices::Path.new parts = split_path_definition(path_def) cache_path.path_type = parts[0] cache_path.view_path = parts[1] cache_path.depot_path = parts[2] if 2 < parts.length case cache_path.path_type when 'share' cache_path.compare_path = cache_stream.stream when 'include' cache_path.compare_path = cache_path.depot_path.gsub(/(.*)\/.../, $1) when 'include+' cache_path.compare_path = cache_path.depot_path.gsub(/(.*)\/.../, $1) else # Do nothing end cache_stream.add_path(cache_path) end cache_stream.save end # The stream path definition is generally # # path_type view_path [depot_path] # # The view_path and depot_path *can be quoted*. I'm assuming quotes inside # of quoted strings are also potentially backslash escaped. We'll see. def split_path_definition(path_def) in_quote = false parts = [] next_part = '' is_escaped = false (0..(path_def.length - 1)).each do |idx| if path_def[idx] == '\\' and !is_escaped is_escaped = true else if path_def[idx] == '"' and !is_escaped in_quote = !in_quote elsif path_def[idx] =~ /^\s$/ and !in_quote unless next_part.empty? parts << next_part next_part = '' end else next_part += path_def[idx] end is_escaped = false end end parts << next_part unless next_part.empty? parts end # Determine the latest change based on any project branch definitions. # # This assumes we'll mostly just have a single stream. def update_change(project) search_path = "#{project.branches.first.stream}/..." changes = web_api_client.changes(max: 1, files: search_path) unless changes.empty? change_num = changes.first.change.to_i project.extensions[Extensions::Phoenix.content_type].change = change_num end end end end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 13972 | tjuricek |
Removing old microservice implementations. The system is now mostly a monolith. Eventually there will be a websocket service. |
||
#2 | 13482 | tjuricek |
Fix issues with running the Phoenix test suite against basic CRUD operations. Does *not* test the notifications mechanism, but we have preliminary phoenix project caching on create, and does generate a simple stream for each phoenix project. |
||
#1 | 13472 | tjuricek |
Implementation of the phoenix services side of notification handling. This is just implementation and work-in-progress. Phoenix projects will now have paths cached in the phoenix services process, which we'll use to "guess" what file changes affect which Phoenix project. We basically see a changed path, then see that it might be relevant to one of the Phoenix project stream views, and then issue a "p4 changes -m1 //stream..." to see what the last change number is. If the change number goes up, we trigger an update. Note that how this all gets configured is with an account from notification services to phoenix services, which ideally is some kind of system account that sees all relevant files. Otherwise, you'll likely get changes filtered by protections, and thus, updates may not get sent out. |