diff --git a/src/CodeGeneration/DocGenerator/AsciiDoc/GeneratedAsciidocVisitor.cs b/src/CodeGeneration/DocGenerator/AsciiDoc/GeneratedAsciidocVisitor.cs index 2cc4289ba43..498bdd24991 100644 --- a/src/CodeGeneration/DocGenerator/AsciiDoc/GeneratedAsciidocVisitor.cs +++ b/src/CodeGeneration/DocGenerator/AsciiDoc/GeneratedAsciidocVisitor.cs @@ -77,7 +77,7 @@ public override void VisitDocument(Document document) if (document.Attributes.All(a => a.Name != "ref_current")) { _newDocument.Attributes.Add(new AttributeEntry("ref_current", - "https://www.elastic.co/guide/en/elasticsearch/reference/6.1")); + $"https://www.elastic.co/guide/en/elasticsearch/reference/{Program.DocVersion}")); } var github = "https://github.com/elastic/elasticsearch-net"; @@ -92,7 +92,8 @@ public override void VisitDocument(Document document) } var originalFile = Regex.Replace(_source.FullName.Replace("\\", "/"), @"^(.*Tests/)", - $"{github}/tree/master/src/Tests/"); + $"{github}/tree/{Program.BranchName}/src/Tests/"); + _newDocument.Insert(0, new Comment { Style = CommentStyle.MultiLine, diff --git a/src/CodeGeneration/DocGenerator/Program.cs b/src/CodeGeneration/DocGenerator/Program.cs index 6ebd026e913..2783c5f753a 100644 --- a/src/CodeGeneration/DocGenerator/Program.cs +++ b/src/CodeGeneration/DocGenerator/Program.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.IO; namespace DocGenerator @@ -11,12 +12,11 @@ string P(string path) { return path.Replace(@"\", Path.DirectorySeparatorChar.ToString()); } - + var currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory()); if (currentDirectory.Name == "DocGenerator" && currentDirectory.Parent.Name == "CodeGeneration") { Console.WriteLine("IDE: " + currentDirectory); - InputDirPath = P(@"..\..\"); OutputDirPath = P(@"..\..\..\docs"); BuildOutputPath = P(@"..\..\..\src"); @@ -28,6 +28,36 @@ string P(string path) OutputDirPath = P(@"..\..\..\..\docs"); BuildOutputPath = P(@"..\..\..\..\build\output"); } + + var process = new Process + { + StartInfo = new ProcessStartInfo + { + UseShellExecute = false, + RedirectStandardOutput = true, + FileName = "git.exe", + CreateNoWindow = true, + WorkingDirectory = Environment.CurrentDirectory, + Arguments = "rev-parse --abbrev-ref HEAD" + } + }; + + try + { + process.Start(); + BranchName = process.StandardOutput.ReadToEnd().Trim(); + Console.WriteLine($"Using branch name {BranchName} in documentation"); + process.WaitForExit(); + } + catch (Exception) + { + BranchName = "master"; + Console.WriteLine($"Could not get the git branch name. Assuming {BranchName}"); + } + finally + { + process.Dispose(); + } } public static string BuildOutputPath { get; } @@ -36,6 +66,10 @@ string P(string path) public static string OutputDirPath { get; } + public static string BranchName { get; } + + public static string DocVersion => "6.1"; + static int Main(string[] args) { try @@ -52,3 +86,5 @@ static int Main(string[] args) } } } + +