Skip to content

Commit 8c89215

Browse files
committed
Fallback to GITHUB_REPOSITORY as repo name instead of starting with it in order of preference
1 parent 56910a7 commit 8c89215

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

src/Elastic.Documentation/GitCheckoutInformation.cs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,32 @@ public static GitCheckoutInformation Create(IDirectoryInfo? source, IFileSystem
7474
using var streamReader = new StreamReader(stream);
7575
ini.Load(streamReader);
7676

77-
var remote = Environment.GetEnvironmentVariable("GITHUB_REPOSITORY");
77+
var remote = BranchTrackingRemote(branch, ini);
78+
logger?.LogInformation("Remote from branch: {GitRemote}", remote);
7879
if (string.IsNullOrEmpty(remote))
7980
{
80-
remote = BranchTrackingRemote(branch, ini);
81-
logger?.LogInformation("Remote from branch: {GitRemote}", remote);
82-
if (string.IsNullOrEmpty(remote))
83-
{
84-
remote = BranchTrackingRemote("main", ini);
85-
logger?.LogInformation("Remote from main branch: {GitRemote}", remote);
86-
}
81+
remote = BranchTrackingRemote("main", ini);
82+
logger?.LogInformation("Remote from main branch: {GitRemote}", remote);
83+
}
8784

88-
if (string.IsNullOrEmpty(remote))
89-
{
90-
remote = BranchTrackingRemote("master", ini);
91-
logger?.LogInformation("Remote from master branch: {GitRemote}", remote);
92-
}
85+
if (string.IsNullOrEmpty(remote))
86+
{
87+
remote = BranchTrackingRemote("master", ini);
88+
logger?.LogInformation("Remote from master branch: {GitRemote}", remote);
89+
}
9390

94-
if (string.IsNullOrEmpty(remote))
95-
{
96-
remote = "elastic/docs-builder-unknown";
97-
logger?.LogInformation("Remote from fallback: {GitRemote}", remote);
98-
}
99-
remote = remote.AsSpan().TrimEnd("git").TrimEnd('.').ToString();
91+
if (string.IsNullOrEmpty(remote))
92+
{
93+
remote = Environment.GetEnvironmentVariable("GITHUB_REPOSITORY");
94+
logger?.LogInformation("Remote from GITHUB_REPOSITORY: {GitRemote}", remote);
95+
}
96+
97+
if (string.IsNullOrEmpty(remote))
98+
{
99+
remote = "elastic/docs-builder-unknown";
100+
logger?.LogInformation("Remote from fallback: {GitRemote}", remote);
100101
}
102+
remote = remote.AsSpan().TrimEnd("git").TrimEnd('.').ToString();
101103

102104
var info = new GitCheckoutInformation
103105
{

src/tooling/docs-assembler/Cli/InboundLinkCommands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public async Task<int> ValidateLocalLinkReference(string? file = null, string? p
7373
file ??= ".artifacts/docs/html/links.json";
7474
var fs = new FileSystem();
7575
var root = !string.IsNullOrEmpty(path) ? fs.DirectoryInfo.New(path) : fs.DirectoryInfo.New(Paths.WorkingDirectoryRoot.FullName);
76-
var repository = GitCheckoutInformation.Create(root, new FileSystem(), logger.CreateLogger(nameof(GitCheckoutInformation))).RepositoryName
76+
var repository = GitCheckoutInformation.Create(root, fs, logger.CreateLogger(nameof(GitCheckoutInformation))).RepositoryName
7777
?? throw new Exception("Unable to determine repository name");
7878

7979
var resolvedFile = fs.FileInfo.New(Path.Combine(root.FullName, file));

0 commit comments

Comments
 (0)