-
Notifications
You must be signed in to change notification settings - Fork 878
feat: Support DOCFX_SOURCE_REPOSITORY_URL #9759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yufeih
merged 7 commits into
dotnet:main
from
filzrev:chore-add-support-for-forked-repository
Apr 1, 2024
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b2c3b61
chore: Add snapshot tests support that are executed on forked repository
filzrev 6900aa6
Merge branch 'main' into chore-add-support-for-forked-repository
filzrev 214e2b8
chore: Add docs for DOCFX_SOURCE_REPOSITORY
filzrev fa41fed
chore: change env variable name from DOCFX_SOURCE_REPOSITORY to DOCFX…
filzrev ac2a6a9
Merge branch 'main' into chore-add-support-for-forked-repository
filzrev f822029
Merge branch 'main' into chore-add-support-for-forked-repository
filzrev 446fcdf
Merge branch 'main' into chore-add-support-for-forked-repository
yufeih File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
test/Docfx.Common.Tests/GitUtilityWithSourceRepoUrlTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Docfx.Common.Git; | ||
| using Xunit; | ||
|
|
||
| namespace Docfx.Common.Tests; | ||
|
|
||
| [Collection("docfx STA")] | ||
| public class GitUtilityWithSourceRepoUrlTest : IDisposable | ||
| { | ||
| private readonly string _originalBranchName; | ||
| private readonly string _originalSourceRepoUrl; | ||
|
|
||
| private const string ORG_NAME = "dotnet"; | ||
| private const string REPO_NAME = "docfx"; | ||
|
|
||
| private const string BRANCH_NAME = "special-branch"; | ||
| private const string DOCFX_SOURCE_BRANCH_NAME = nameof(DOCFX_SOURCE_BRANCH_NAME); | ||
| private const string DOCFX_SOURCE_REPOSITORY = nameof(DOCFX_SOURCE_REPOSITORY); | ||
|
|
||
| public GitUtilityWithSourceRepoUrlTest() | ||
| { | ||
| _originalBranchName = Environment.GetEnvironmentVariable(DOCFX_SOURCE_BRANCH_NAME); | ||
| _originalSourceRepoUrl = Environment.GetEnvironmentVariable(DOCFX_SOURCE_REPOSITORY); | ||
|
|
||
| Environment.SetEnvironmentVariable(DOCFX_SOURCE_BRANCH_NAME, BRANCH_NAME); | ||
| Environment.SetEnvironmentVariable(DOCFX_SOURCE_REPOSITORY, $"{ORG_NAME}/{REPO_NAME}"); | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| Environment.SetEnvironmentVariable(DOCFX_SOURCE_BRANCH_NAME, _originalBranchName); | ||
| Environment.SetEnvironmentVariable(DOCFX_SOURCE_REPOSITORY, _originalSourceRepoUrl); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TryGetFileDetailTest() | ||
| { | ||
| var info = GitUtility.TryGetFileDetail(Directory.GetCurrentDirectory()); | ||
| Assert.Equal(BRANCH_NAME, info.Branch); | ||
| Assert.Equal("https://github.com/dotnet/docfx", info.Repo); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void RawContentUrlToContentUrlTest() | ||
| { | ||
| string rawUrl = "https://raw.githubusercontent.com/dotnet/docfx/main/README.md"; | ||
| string expected = "https://github.com/dotnet/docfx/blob/special-branch/README.md"; | ||
|
|
||
| var result = GitUtility.RawContentUrlToContentUrl(rawUrl); | ||
|
|
||
| Assert.Equal(expected, result); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("https://github.com/user/repo.git", "main", "path/to/file.cs", 0, $"https://github.com/{ORG_NAME}/{REPO_NAME}/blob/main/path/to/file.cs")] | ||
| [InlineData("https://github.com/user/repo.git", "main", "path/to/file.cs", 10, $"https://github.com/{ORG_NAME}/{REPO_NAME}/blob/main/path/to/file.cs#L10")] | ||
| [InlineData("https://bitbucket.org/user/repo.git", "main", "path/to/file.cs", 0, $"https://bitbucket.org/{ORG_NAME}/{REPO_NAME}/src/main/path/to/file.cs")] | ||
| [InlineData("https://bitbucket.org/user/repo.git", "main", "path/to/file.cs", 10, $"https://bitbucket.org/{ORG_NAME}/{REPO_NAME}/src/main/path/to/file.cs#lines-10")] | ||
| [InlineData("https://dev.azure.com/user/repo/_git/repo", "main", "path/to/file.cs", 0, $"https://dev.azure.com/{ORG_NAME}/{REPO_NAME}/_git/repo?path=path/to/file.cs&version=GBmain")] | ||
| [InlineData("https://dev.azure.com/user/repo/_git/repo", "0123456789abcdef0123456789abcdef01234567", "path/to/file.cs", 10, $"https://dev.azure.com/{ORG_NAME}/{REPO_NAME}/_git/repo?path=path/to/file.cs&version=GC0123456789abcdef0123456789abcdef01234567&line=10")] | ||
| [InlineData("https://user.visualstudio.com/repo/_git/repo", "main", "path/to/file.cs", 0, $"https://{ORG_NAME}.visualstudio.com/{REPO_NAME}/_git/repo?path=path/to/file.cs&version=GBmain")] | ||
| [InlineData("https://user.visualstudio.com/repo/_git/repo", "0123456789abcdef0123456789abcdef01234567", "path/to/file.cs", 10, $"https://{ORG_NAME}.visualstudio.com/{REPO_NAME}/_git/repo?path=path/to/file.cs&version=GC0123456789abcdef0123456789abcdef01234567&line=10")] | ||
| [InlineData("[email protected]:user/repo.git", "main", "path/to/file.cs", 0, $"https://github.com/{ORG_NAME}/{REPO_NAME}/blob/main/path/to/file.cs")] | ||
| [InlineData("ssh://[email protected]:22/FakeProject/_ssh/Docfx", "main", "path/to/file.cs", 0, $"https://{ORG_NAME}.visualstudio.com/{REPO_NAME}/_ssh/Docfx?path=path/to/file.cs&version=GBmain")] | ||
| public void GetSourceUrlTest(string repo, string branch, string path, int line, string result) | ||
| { | ||
| Assert.Equal(result, GitUtility.GetSourceUrl(new(repo, branch, path, line))); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.