示例#1
0
        internal static bool CheckArguments(
            TrunkBotArguments botArgs,
            out string errorMessage)
        {
            if (!CheckValidArguments(botArgs, out errorMessage))
            {
                errorMessage = string.Format(
                    "trunkbot can't start without specifying the following arguments:\n{0}",
                    errorMessage);
                return(false);
            }

            if (!File.Exists(botArgs.ConfigFilePath))
            {
                errorMessage = string.Format(
                    "trunkbot can't start without the JSON config file [{0}]",
                    botArgs.ConfigFilePath);
                return(false);
            }

            if (!TryParseConfigFile(botArgs.ConfigFilePath, out errorMessage))
            {
                errorMessage = string.Format(
                    "trunkbot can't start without specifying a valid JSON config file [{0}]:\n{1}",
                    botArgs.ConfigFilePath, errorMessage);
                return(false);
            }

            return(true);
        }
示例#2
0
        static bool CheckValidArguments(
            TrunkBotArguments botArgs,
            out string errorMessage)
        {
            errorMessage = string.Empty;

            if (string.IsNullOrEmpty(botArgs.WebSocketUrl))
            {
                errorMessage += BuildArgumentError(
                    "Plastic web socket url endpoint", "--websocket wss://blackmore:7111/plug");
            }

            if (string.IsNullOrEmpty(botArgs.RestApiUrl))
            {
                errorMessage += BuildArgumentError(
                    "Plastic REST API url", "--restapi https://blackmore:7178");
            }

            if (string.IsNullOrEmpty(botArgs.BotName))
            {
                errorMessage += BuildArgumentError(
                    "Name for this bot", "--name trunk-dev-bot");
            }

            if (string.IsNullOrEmpty(botArgs.ApiKey))
            {
                errorMessage += BuildArgumentError(
                    "Connection API key", "--apikey x2fjk28fda");
            }

            if (string.IsNullOrEmpty(botArgs.ConfigFilePath))
            {
                errorMessage += BuildArgumentError(
                    "JSON config file", "--config tunk-dev-bot-config.conf");
            }

            return(string.IsNullOrEmpty(errorMessage));
        }
示例#3
0
        static int Main(string[] args)
        {
            string botName = null;

            try
            {
                TrunkBotArguments botArgs = new TrunkBotArguments(args);

                bool bValidArgs = botArgs.Parse();
                botName = botArgs.BotName;

                ConfigureLogging(botName);

                mLog.InfoFormat("TrunkBot [{0}] started. Version [{1}]",
                                botName,
                                System.Reflection.Assembly.GetExecutingAssembly().GetName().Version);

                string argsStr = args == null ? string.Empty : string.Join(" ", args);
                mLog.DebugFormat("Args: [{0}]. Are valid args?: [{1}]", argsStr, bValidArgs);

                if (!bValidArgs || botArgs.ShowUsage)
                {
                    PrintUsage();
                    if (botArgs.ShowUsage)
                    {
                        mLog.InfoFormat(
                            "TrunkBot [{0}] is going to finish: " +
                            "user explicitly requested to show usage.",
                            botName);
                        return(0);
                    }

                    mLog.ErrorFormat(
                        "TrunkBot [{0}] is going to finish: " +
                        "invalid arguments found in command line.",
                        botName);
                    return(0);
                }

                string errorMessage = null;
                if (!TrunkBotArgumentsChecker.CheckArguments(
                        botArgs, out errorMessage))
                {
                    Console.WriteLine(errorMessage);
                    mLog.ErrorFormat(
                        "TrunkBot [{0}] is going to finish: error found on argument check",
                        botName);
                    mLog.Error(errorMessage);
                    return(1);
                }

                TrunkBotConfiguration botConfig = TrunkBotConfiguration.
                                                  BuidFromConfigFile(botArgs.ConfigFilePath);

                errorMessage = null;
                if (!TrunkBotConfigurationChecker.CheckConfiguration(
                        botConfig, out errorMessage))
                {
                    Console.WriteLine(errorMessage);
                    mLog.ErrorFormat(
                        "TrunkBot [{0}] is going to finish: error found on argument check",
                        botName);
                    mLog.Error(errorMessage);
                    return(1);
                }

                ConfigureServicePoint();

                string escapedBotName = GetEscapedBotName(botName);

                LaunchTrunkMergebot(
                    botArgs.WebSocketUrl,
                    botArgs.RestApiUrl,
                    botConfig,
                    ToolConfig.GetBranchesFile(escapedBotName),
                    ToolConfig.GetCodeReviewsFile(escapedBotName),
                    botName,
                    botArgs.ApiKey);

                mLog.InfoFormat(
                    "TrunkBot [{0}] is going to finish: orderly shutdown.",
                    botName);

                return(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                mLog.FatalFormat(
                    "TrunkBot [{0}] is going to finish: uncaught exception " +
                    "thrown during execution. Message: {1}", botName, e.Message);
                mLog.DebugFormat("StackTrace: {0}", e.StackTrace);
                return(1);
            }
        }