Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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,
Expand Down
40 changes: 38 additions & 2 deletions src/CodeGeneration/DocGenerator/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.IO;

namespace DocGenerator
Expand All @@ -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");
Expand All @@ -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; }
Expand All @@ -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
Expand All @@ -52,3 +86,5 @@ static int Main(string[] args)
}
}
}