Skip to content

Commit 75391fa

Browse files
russcamMpdreamz
authored andcommitted
Use branch name in documentation (#3082)
Conflicts: src/CodeGeneration/DocGenerator/AsciiDoc/GeneratedAsciidocVisitor.cs src/CodeGeneration/DocGenerator/Program.cs
1 parent 1183fdf commit 75391fa

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/CodeGeneration/DocGenerator/AsciiDoc/GeneratedAsciidocVisitor.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public override void Visit(Document document)
7676

7777
if (document.Attributes.All(a => a.Name != "ref_current"))
7878
{
79-
_newDocument.Attributes.Add(new AttributeEntry("ref_current", "https://www.elastic.co/guide/en/elasticsearch/reference/6.1"));
79+
_newDocument.Attributes.Add(new AttributeEntry("ref_current",
80+
$"https://www.elastic.co/guide/en/elasticsearch/reference/{Program.DocVersion}"));
8081
}
8182

8283
var github = "https://github.com/elastic/elasticsearch-net";
@@ -90,7 +91,9 @@ public override void Visit(Document document)
9091
_newDocument.Attributes.Add(new AttributeEntry("nuget", "https://www.nuget.org/packages"));
9192
}
9293

93-
var originalFile = Regex.Replace(_source.FullName.Replace("\\", "/"), @"^(.*Tests/)", $"{github}/tree/master/src/Tests/");
94+
var originalFile = Regex.Replace(_source.FullName.Replace("\\", "/"), @"^(.*Tests/)",
95+
$"{github}/tree/{Program.BranchName}/src/Tests/");
96+
9497
_newDocument.Insert(0, new Comment
9598
{
9699
Style = CommentStyle.MultiLine,

src/CodeGeneration/DocGenerator/Program.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using System.IO;
34

45
namespace DocGenerator
@@ -20,6 +21,36 @@ static Program()
2021
OutputDirPath = @"..\..\..\..\..\docs";
2122
BuildOutputPath = @"..\..\..\..\..\build\output";
2223
}
24+
25+
var process = new Process
26+
{
27+
StartInfo = new ProcessStartInfo
28+
{
29+
UseShellExecute = false,
30+
RedirectStandardOutput = true,
31+
FileName = "git.exe",
32+
CreateNoWindow = true,
33+
WorkingDirectory = Environment.CurrentDirectory,
34+
Arguments = "rev-parse --abbrev-ref HEAD"
35+
}
36+
};
37+
38+
try
39+
{
40+
process.Start();
41+
BranchName = process.StandardOutput.ReadToEnd().Trim();
42+
Console.WriteLine($"Using branch name {BranchName} in documentation");
43+
process.WaitForExit();
44+
}
45+
catch (Exception)
46+
{
47+
BranchName = "master";
48+
Console.WriteLine($"Could not get the git branch name. Assuming {BranchName}");
49+
}
50+
finally
51+
{
52+
process.Dispose();
53+
}
2354
}
2455

2556
public static string BuildOutputPath { get; }
@@ -28,6 +59,10 @@ static Program()
2859

2960
public static string OutputDirPath { get; }
3061

62+
public static string BranchName { get; }
63+
64+
public static string DocVersion => "6.1";
65+
3166
static int Main(string[] args)
3267
{
3368
try
@@ -44,3 +79,5 @@ static int Main(string[] args)
4479
}
4580
}
4681
}
82+
83+

0 commit comments

Comments
 (0)