Skip to content

Commit b4f058f

Browse files
committed
Use branch name in documentation (#3082)
Conflicts: src/CodeGeneration/DocGenerator/AsciiDoc/GeneratedAsciidocVisitor.cs src/CodeGeneration/DocGenerator/Program.cs (cherry picked from commit 75391fa)
1 parent 46acd2a commit b4f058f

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

src/CodeGeneration/DocGenerator/AsciiDoc/GeneratedAsciidocVisitor.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ namespace DocGenerator.AsciiDoc
3030
public class GeneratedAsciidocVisitor : NoopVisitor
3131
{
3232
private static readonly Dictionary<string,string> Ids = new Dictionary<string, string>();
33-
3433
private readonly FileInfo _destination;
34+
3535
private readonly FileInfo _source;
3636
private readonly Dictionary<string, Project> _projects;
3737
private int _topSectionTitleLevel;
@@ -76,12 +76,13 @@ public override void VisitDocument(Document document)
7676

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

8283
if (document.Attributes.All(a => a.Name != "xpack_current"))
8384
{
84-
_newDocument.Attributes.Add(new AttributeEntry("xpack_current", "https://www.elastic.co/guide/en/x-pack/2.4"));
85+
_newDocument.Attributes.Add(new AttributeEntry("xpack_current", "https://www.elastic.co/guide/en/x-pack/{Program.DocVersion}"));
8586
}
8687

8788
var github = "https://github.com/elastic/elasticsearch-net";
@@ -96,7 +97,9 @@ public override void VisitDocument(Document document)
9697
_newDocument.Attributes.Add(new AttributeEntry("nuget", "https://www.nuget.org/packages"));
9798
}
9899

99-
var originalFile = Regex.Replace(_source.FullName.Replace("\\", "/"), @"^(.*Tests/)", $"{github}/tree/2.x/src/Tests/");
100+
var originalFile = Regex.Replace(_source.FullName.Replace("\\", "/"), @"^(.*Tests/)",
101+
$"{github}/tree/{Program.BranchName}/src/Tests/");
102+
100103
_newDocument.Insert(0, new Comment
101104
{
102105
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)