--[[ $Id: //depot/p19.1/p4-test/server/extensions/examples/swarm/main.lua#6 $ $DateTime: 2019/04/24 15:21:00 $ $Author: jgibson $ $Change: 1793556 $ ]]-- package.path = Helix.Core.Server.GetArchDirFileName( "?.lua" ) local utils = require "ExtUtils" local swarm = require "SwarmUtils" local data = require "DataUtils" function GlobalConfigFields() return { ["Swarm-URL"] = "http://swarm.example.com", ["Swarm-user"] = "Swarm user name", ["Swarm-pass"] = "Swarm user password or Helix Core Server ticket", } end function InstanceConfigFields() return { ["ext user"] = "The user for this extension to trigger on" } end function InstanceConfigEvents() return { ["command"] = "post-user-shelve", ["change-commit"] = "//..." } end local initDone = false function Command() if not initDone then Helix.Core.Server.log( { ["Command() init"] = 1 } ) utils.init() swarm.init( utils ) data.init() end -- This Extension is only for the CLI. if Helix.Core.Server.GetVar( "clientprog" ) ~= "p4" then return true end local args = Helix.Core.Server.GetVar( "argsQuoted" ) local _, _, change = string.find( args, "-c,(%d*)" ) if not change then local msg = "Error getting change number from '" .. args .. "'" Helix.Core.Server.SetClientMsg( utils.msgHeader() .. msg ) return false end local id, state, changes = data.select( change ) if id == nil then return true end local msg = "Review ID: " .. id .. ", state: " .. state .. "\nchanges: " for k, v in pairs( changes ) do msg = msg .. k .. ", " .. v .. ", " end -- Trim off the trailing ", " msg = msg:sub( 1, -3 ) Helix.Core.Server.SetClientMsg( utils.msgHeader() .. msg ) return true end function ChangeCommit() if not initDone then Helix.Core.Server.log( { ["ChangeCommit() init"] = 1 } ) utils.init() swarm.init( utils ) data.init() end if swarm.version == nil then Helix.Core.Server.SetClientMsg( utils.msgHeader() .. "Swarm API version '" .. swarm.SwarmAPI .. "' not found." ) return false end local gcfg = Helix.Core.Server.GetGlobalConfigData() local ok, url, sdata = swarm.getReviews( utils.gCfgData[ "Swarm-URL" ], Helix.Core.Server.GetVar( "user" ) ) if not ok then Helix.Core.Server.SetClientMsg( sdata ) return false end data.insert( sdata ) return true end