Exemple #1
0
        private void GenerateOutputVariables(Results result, Dictionary <string, string> paramMatch, BranchConfiguration branchConfig)
        {
            // Handle output variables
            var gitInfo   = new Dictionary <string, string>();
            var paramHead = new Dictionary <string, string>();
            var paramVS   = new Dictionary <string, string>();

            gitInfo.Add("BranchName", result.GitInfo.BranchName);
            gitInfo.Add("ShortBranchName", result.GitInfo.ShortBranchName);
            gitInfo.Add("Path", result.GitInfo.Path);

            paramHead.Add("Author", result.GitInfo.LastAuthor);
            paramHead.Add("Date", result.GitInfo.LastCommitDate.ToString(CultureInfo.InvariantCulture));
            paramHead.Add("Sha", result.GitInfo.Head.Sha);
            paramHead.Add("Message", result.GitInfo.Head.Message);
            paramHead.Add("MessageShort", result.GitInfo.Head.MessageShort);

            paramVS.Add("CommitAuthor", result.VersionSource.Commit.Author);
            paramVS.Add("CommitDateTime", result.VersionSource.Commit.CommitDate.ToString(CultureInfo.InvariantCulture));
            paramVS.Add("CommitSha", result.VersionSource.Commit.Sha);
            paramVS.Add("CommitMessage", result.VersionSource.Commit.Message);
            paramVS.Add("CommitMessageShort", result.VersionSource.Commit.MessageShort);
            paramVS.Add("Message", result.VersionSource.Message);
            paramVS.Add("MessageShort", result.VersionSource.MessageShort);

            foreach (var output in branchConfig.Output)
            {
                var inputStream       = new AntlrInputStream(output.Value);
                var lexer             = new OutputLexer(inputStream);
                var commonTokenStream = new CommonTokenStream(lexer);
                var parser            = new OutputParser(commonTokenStream);

                parser.RemoveErrorListeners();
                parser.AddErrorListener(new OutputErrorListener()); // add ours

                var visitor     = new OutputVisitor(output.Key, output.Value, _paramArgs, gitInfo, paramHead, paramMatch, result.Output, paramVS);
                var parseOutput = visitor.Visit(parser.start());

                result.Output.Add(output.Key, parseOutput);
            }

            // Strip away temporary items, unless we are in diagnostic mode
            var res = new Dictionary <string, string>();

            foreach (var output in result.Output)
            {
                if (output.Key.StartsWith("~"))
                {
                    Logger.Debug($"Stripping temporary variable: {output.Key}='{output.Value}'");
                    continue;
                }
                res.Add(output.Key, output.Value);
            }

            result.Output = res;
        }