Browse Source

Merge pull request #4860 from abpframework/Docs-module-Alternative-way-(using-branches)-to-get-versions

Docs module: added alternative way (using branches) to get versions
pull/4968/head
Halil İbrahim Kalkan 6 years ago
committed by GitHub
parent
commit
4e1a982b99
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Localization/Resources/Docs/ApplicationContracts/cs.json
  2. 3
      modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/CreateProjectDto.cs
  3. 3
      modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/ProjectDto.cs
  4. 3
      modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/UpdateProjectDto.cs
  5. 6
      modules/docs/src/Volo.Docs.Admin.Web/DocsAdminWebAutoMapperProfile.cs
  6. 13
      modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Create.cshtml.cs
  7. 23
      modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Edit.cshtml.cs
  8. 34
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs
  9. 19
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Projects/ProjectAppService.cs
  10. 8
      modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Projects/GithubVersionProviderSource.cs
  11. 3
      modules/docs/src/Volo.Docs.Domain/Volo.Docs.Domain.csproj
  12. 62
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs
  13. 15
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubRepositoryManager.cs
  14. 4
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/IGithubRepositoryManager.cs
  15. 28
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/BranchGithubVersionProvider.cs
  16. 7
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubVersion.cs
  17. 34
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubVersionProviderFactory.cs
  18. 10
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IGithubVersionProvider.cs
  19. 9
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IGithubVersionProviderFactory.cs
  20. 4
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IVersionHelper.cs
  21. 28
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/ReleaseGithubVersionProvider.cs
  22. 18
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/SemanticVersionHelper.cs
  23. 6
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml
  24. 60
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs
  25. 33
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml.cs
  26. 1
      modules/docs/src/Volo.Docs.Web/Volo.Docs.Web.csproj
  27. 30
      modules/docs/test/Volo.Docs.TestBase/Volo/Docs/DocsTestBase.cs

2
modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Localization/Resources/Docs/ApplicationContracts/cs.json

@ -31,6 +31,8 @@
"DisplayName:GitHubRootUrl": "GitHub kořenové URL",
"DisplayName:GitHubAccessToken": "GitHub přístupový token",
"DisplayName:GitHubUserAgent": "GitHub user agent",
"DisplayName:GithubVersionProviderSource": "GitHub version provider source",
"DisplayName:VersionBranchPrefix": "Version branch prefix",
"DisplayName:All": "Pull všeho",
"DisplayName:LanguageCode": "Kód jazyka",
"DisplayName:Version": "Verze",

3
modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/CreateProjectDto.cs

@ -1,4 +1,5 @@
using System.Collections.Generic;
using Volo.Docs.Projects;
namespace Volo.Docs.Admin.Projects
{
@ -26,4 +27,4 @@ namespace Volo.Docs.Admin.Projects
public Dictionary<string, object> ExtraProperties { get; set; }
}
}
}

3
modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/ProjectDto.cs

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Application.Dtos;
using Volo.Docs.Projects;
namespace Volo.Docs.Admin.Projects
{
@ -29,4 +30,4 @@ namespace Volo.Docs.Admin.Projects
public Dictionary<string, object> ExtraProperties { get; set; }
}
}
}

3
modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/UpdateProjectDto.cs

@ -1,4 +1,5 @@
using System.Collections.Generic;
using Volo.Docs.Projects;
namespace Volo.Docs.Admin.Projects
{
@ -22,4 +23,4 @@ namespace Volo.Docs.Admin.Projects
public Dictionary<string, object> ExtraProperties { get; set; }
}
}
}

6
modules/docs/src/Volo.Docs.Admin.Web/DocsAdminWebAutoMapperProfile.cs

@ -15,7 +15,11 @@ namespace Volo.Docs.Admin
CreateMap<EditModel.EditGithubProjectViewModel, UpdateProjectDto>().Ignore(x => x.ExtraProperties);
CreateMap<ProjectDto, EditModel.EditGithubProjectViewModel > ()
.Ignore(x => x.GitHubAccessToken).Ignore(x => x.GitHubRootUrl).Ignore(x => x.GitHubUserAgent);
.Ignore(x => x.GitHubAccessToken)
.Ignore(x => x.GitHubRootUrl)
.Ignore(x => x.GitHubUserAgent)
.Ignore(x => x.GithubVersionProviderSource)
.Ignore(x => x.VersionBranchPrefix);
CreateMap<PullModel.PullDocumentViewModel, PullAllDocumentInput>();
CreateMap<PullModel.PullDocumentViewModel, PullDocumentInput>();

13
modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Create.cshtml.cs

@ -62,7 +62,9 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects
{
{nameof(GithubProject.GitHubRootUrl), GithubProject.GitHubRootUrl},
{nameof(GithubProject.GitHubUserAgent), GithubProject.GitHubUserAgent},
{nameof(GithubProject.GitHubAccessToken), GithubProject.GitHubAccessToken}
{nameof(GithubProject.GitHubAccessToken), GithubProject.GitHubAccessToken},
{nameof(GithubProject.GithubVersionProviderSource), GithubProject.GithubVersionProviderSource},
{nameof(GithubProject.VersionBranchPrefix), GithubProject.VersionBranchPrefix}
};
return dto;
@ -118,6 +120,13 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects
[DisplayOrder(10002)]
[StringLength(64)]
public string GitHubUserAgent { get; set; }
[DisplayOrder(10003)]
public GithubVersionProviderSource GithubVersionProviderSource { get; set; } = GithubVersionProviderSource.Releases;
[DisplayOrder(10004)]
[StringLength(64)]
public string VersionBranchPrefix { get; set; }
}
}
}
}

23
modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Edit.cshtml.cs

@ -62,7 +62,9 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects
{
{nameof(GithubProject.GitHubRootUrl), GithubProject.GitHubRootUrl},
{nameof(GithubProject.GitHubUserAgent), GithubProject.GitHubUserAgent},
{nameof(GithubProject.GitHubAccessToken), GithubProject.GitHubAccessToken}
{nameof(GithubProject.GitHubAccessToken), GithubProject.GitHubAccessToken},
{nameof(GithubProject.GithubVersionProviderSource), GithubProject.GithubVersionProviderSource},
{nameof(GithubProject.VersionBranchPrefix), GithubProject.VersionBranchPrefix}
};
return dto;
@ -75,6 +77,16 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects
GithubProject.GitHubAccessToken = (string) dto.ExtraProperties[nameof(GithubProject.GitHubAccessToken)];
GithubProject.GitHubRootUrl = (string) dto.ExtraProperties[nameof(GithubProject.GitHubRootUrl)];
GithubProject.GitHubUserAgent = (string) dto.ExtraProperties[nameof(GithubProject.GitHubUserAgent)];
if (dto.ExtraProperties.ContainsKey(nameof(GithubProject.GithubVersionProviderSource)))
{
GithubProject.GithubVersionProviderSource = (GithubVersionProviderSource) (long) dto.ExtraProperties[nameof(GithubProject.GithubVersionProviderSource)];
}
if (dto.ExtraProperties.ContainsKey(nameof(GithubProject.VersionBranchPrefix)))
{
GithubProject.VersionBranchPrefix = (string) dto.ExtraProperties[nameof(GithubProject.VersionBranchPrefix)];
}
}
public abstract class EditProjectViewModelBase
@ -125,6 +137,13 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects
[DisplayOrder(10002)]
[StringLength(64)]
public string GitHubUserAgent { get; set; }
[DisplayOrder(10003)]
public GithubVersionProviderSource GithubVersionProviderSource { get; set; } = GithubVersionProviderSource.Releases;
[DisplayOrder(10004)]
[StringLength(64)]
public string VersionBranchPrefix { get; set; }
}
}
}
}

34
modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs

@ -64,6 +64,8 @@ namespace Volo.Docs.Documents
{
var project = await _projectRepository.GetAsync(input.ProjectId);
input.Version = GetProjectVersionPrefixIfExist(project) + input.Version;
return await GetDocumentWithDetailsDtoAsync(
project,
input.Name,
@ -76,6 +78,8 @@ namespace Volo.Docs.Documents
{
var project = await _projectRepository.GetAsync(input.ProjectId);
input.Version = GetProjectVersionPrefixIfExist(project) + input.Version;
return await GetDocumentWithDetailsDtoAsync(
project,
project.DefaultDocumentName + "." + project.Format,
@ -88,6 +92,8 @@ namespace Volo.Docs.Documents
{
var project = await _projectRepository.GetAsync(input.ProjectId);
input.Version = GetProjectVersionPrefixIfExist(project) + input.Version;
var navigationDocument = await GetDocumentWithDetailsDtoAsync(
project,
project.NavigationDocumentName,
@ -133,10 +139,11 @@ namespace Volo.Docs.Documents
public async Task<DocumentResourceDto> GetResourceAsync(GetDocumentResourceInput input)
{
var project = await _projectRepository.GetAsync(input.ProjectId);
var cacheKey =
CacheKeyGenerator.GenerateDocumentResourceCacheKey(project, input.Name, input.LanguageCode,
input.Version);
input.Version = string.IsNullOrWhiteSpace(input.Version) ? project.LatestVersionBranchName : input.Version;
input.Version = GetProjectVersionPrefixIfExist(project) + input.Version;
var cacheKey = CacheKeyGenerator.GenerateDocumentResourceCacheKey(project, input.Name, input.LanguageCode,input.Version);
async Task<DocumentResource> GetResourceAsync()
{
@ -166,6 +173,8 @@ namespace Volo.Docs.Documents
{
var project = await _projectRepository.GetAsync(input.ProjectId);
input.Version = GetProjectVersionPrefixIfExist(project) + input.Version;
var esDocs =
await _documentFullSearch.SearchAsync(input.Context, project.Id, input.LanguageCode, input.Version);
@ -188,6 +197,8 @@ namespace Volo.Docs.Documents
{
var project = await _projectRepository.GetAsync(input.ProjectId);
input.Version = GetProjectVersionPrefixIfExist(project) + input.Version;
try
{
if (string.IsNullOrWhiteSpace(project.ParametersDocumentName))
@ -337,5 +348,22 @@ namespace Volo.Docs.Documents
return TimeSpan.Parse(value);
}
private string GetProjectVersionPrefixIfExist(Project project)
{
if (GetGithubVersionProviderSource(project) == GithubVersionProviderSource.Branches)
{
return project.ExtraProperties["VersionBranchPrefix"].ToString();
}
return "";
}
private GithubVersionProviderSource GetGithubVersionProviderSource(Project project)
{
return project.ExtraProperties.ContainsKey("GithubVersionProviderSource")
? (GithubVersionProviderSource) (long) project.ExtraProperties["GithubVersionProviderSource"]
: GithubVersionProviderSource.Releases;
}
}
}

19
modules/docs/src/Volo.Docs.Application/Volo/Docs/Projects/ProjectAppService.cs

@ -106,6 +106,8 @@ namespace Volo.Docs.Projects
var project = await _projectRepository.GetByShortNameAsync(shortName);
var store = _documentSource.Create(project.DocumentStoreType);
version = GetProjectVersionPrefixIfExist(project) + version;
async Task<LanguageConfig> GetLanguagesAsync()
{
return await store.GetLanguageListAsync(project, version);
@ -120,5 +122,22 @@ namespace Volo.Docs.Projects
}
);
}
private string GetProjectVersionPrefixIfExist(Project project)
{
if (GetGithubVersionProviderSource(project) == GithubVersionProviderSource.Branches)
{
return project.ExtraProperties["VersionBranchPrefix"].ToString();
}
return "";
}
private GithubVersionProviderSource GetGithubVersionProviderSource(Project project)
{
return project.ExtraProperties.ContainsKey("GithubVersionProviderSource")
? (GithubVersionProviderSource) (long) project.ExtraProperties["GithubVersionProviderSource"]
: GithubVersionProviderSource.Releases;
}
}
}

8
modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Projects/GithubVersionProviderSource.cs

@ -0,0 +1,8 @@
namespace Volo.Docs.Projects
{
public enum GithubVersionProviderSource
{
Releases,
Branches
}
}

3
modules/docs/src/Volo.Docs.Domain/Volo.Docs.Domain.csproj

@ -21,8 +21,9 @@
<PackageReference Include="Octokit" Version="0.48.0" />
<PackageReference Include="NEST" Version="7.7.1" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="3.1.5" />
<PackageReference Include="NuGet.Versioning" Version="5.6.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Docs.Domain.Shared\Volo.Docs.Domain.Shared.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Ddd.Domain\Volo.Abp.Ddd.Domain.csproj" />

62
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs

@ -9,6 +9,7 @@ using Volo.Docs.GitHub.Projects;
using Volo.Docs.Projects;
using Octokit;
using Volo.Abp;
using Volo.Docs.GitHub.Documents.Version;
using Volo.Extensions;
using Project = Volo.Docs.Projects.Project;
@ -22,11 +23,13 @@ namespace Volo.Docs.GitHub.Documents
private readonly IGithubRepositoryManager _githubRepositoryManager;
private readonly IGithubPatchAnalyzer _githubPatchAnalyzer;
private readonly IVersionHelper _versionHelper;
public GithubDocumentSource(IGithubRepositoryManager githubRepositoryManager, IGithubPatchAnalyzer githubPatchAnalyzer)
public GithubDocumentSource(IGithubRepositoryManager githubRepositoryManager, IGithubPatchAnalyzer githubPatchAnalyzer, IVersionHelper versionHelper)
{
_githubRepositoryManager = githubRepositoryManager;
_githubPatchAnalyzer = githubPatchAnalyzer;
_versionHelper = versionHelper;
}
public virtual async Task<Document> GetDocumentAsync(Project project, string documentName, string languageCode, string version, DateTime? lastKnownSignificantUpdateTime = null)
@ -172,7 +175,7 @@ namespace Volo.Docs.GitHub.Documents
* Getting file commits usually throws "Resource temporarily unavailable" or "Network is unreachable"
* This is a trival information and running this inside try-catch is safer.
*/
try
{
return await GetFileCommitsAsync(project, version, project.GetGitHubInnerUrl(languageCode, documentName));
@ -221,15 +224,19 @@ namespace Volo.Docs.GitHub.Documents
public async Task<List<VersionInfo>> GetVersionsAsync(Project project)
{
var url = project.GetGitHubUrl();
var ownerName = GetOwnerNameFromUrl(url);
var repositoryName = GetRepositoryNameFromUrl(url);
var githubVersionProviderSource = GetGithubVersionProviderSource(project);
List<VersionInfo> versions;
try
{
versions = (await GetReleasesAsync(project))
.OrderByDescending(r => r.PublishedAt)
versions = (await _githubRepositoryManager.GetVersionsAsync(ownerName, repositoryName, project.GetGitHubAccessTokenOrNull(), githubVersionProviderSource))
.Select(r => new VersionInfo
{
Name = r.TagName,
DisplayName = r.TagName
Name = r.Name,
DisplayName = r.Name
}).ToList();
}
catch (Exception ex)
@ -239,14 +246,45 @@ namespace Volo.Docs.GitHub.Documents
versions = new List<VersionInfo>();
}
if (!versions.Any() && !string.IsNullOrEmpty(project.LatestVersionBranchName))
if (githubVersionProviderSource == GithubVersionProviderSource.Branches && project.ExtraProperties.ContainsKey("VersionBranchPrefix"))
{
var prefix = (string) project.ExtraProperties["VersionBranchPrefix"];
if (!string.IsNullOrEmpty(prefix))
{
versions = versions.Where(v => v.Name.StartsWith(prefix)).ToList();
foreach (var v in versions)
{
v.Name = v.Name.Substring(prefix.Length);
v.DisplayName = v.DisplayName.Substring(prefix.Length);
}
}
versions = _versionHelper.OrderByDescending(versions);
}
if(githubVersionProviderSource == GithubVersionProviderSource.Releases)
{
versions.Add(new VersionInfo { DisplayName = "1.0.0", Name = project.LatestVersionBranchName });
if (!versions.Any() && !string.IsNullOrEmpty(project.LatestVersionBranchName))
{
versions.Add(new VersionInfo { DisplayName = "1.0.0", Name = project.LatestVersionBranchName });
}
else
{
versions = _versionHelper.OrderByDescending(versions);
}
}
return versions;
}
private GithubVersionProviderSource GetGithubVersionProviderSource(Project project)
{
return project.ExtraProperties.ContainsKey("GithubVersionProviderSource")
? (GithubVersionProviderSource) (long) project.ExtraProperties["GithubVersionProviderSource"]
: GithubVersionProviderSource.Releases;
}
public async Task<DocumentResource> GetResource(Project project, string resourceName, string languageCode, string version)
{
var rawRootUrl = CalculateRawRootUrlWithLanguageCode(project.GetGitHubUrl(version), languageCode);
@ -277,14 +315,6 @@ namespace Volo.Docs.GitHub.Documents
return languageConfig;
}
private async Task<IReadOnlyList<Release>> GetReleasesAsync(Project project)
{
var url = project.GetGitHubUrl();
var ownerName = GetOwnerNameFromUrl(url);
var repositoryName = GetRepositoryNameFromUrl(url);
return await _githubRepositoryManager.GetReleasesAsync(ownerName, repositoryName, project.GetGitHubAccessTokenOrNull());
}
private async Task<IReadOnlyList<GitHubCommit>> GetFileCommitsAsync(Project project, string version, string filename)
{
var url = project.GetGitHubUrl();

15
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubRepositoryManager.cs

@ -6,6 +6,8 @@ using System.Net.Http.Headers;
using System.Threading.Tasks;
using Octokit;
using Octokit.Internal;
using Volo.Docs.GitHub.Documents.Version;
using Volo.Docs.Projects;
using ProductHeaderValue = Octokit.ProductHeaderValue;
namespace Volo.Docs.GitHub.Documents
@ -15,10 +17,12 @@ namespace Volo.Docs.GitHub.Documents
public const string HttpClientName = "GithubRepositoryManagerHttpClientName";
private readonly IHttpClientFactory _clientFactory;
private readonly IGithubVersionProviderFactory _githubVersionProviderFactory;
public GithubRepositoryManager(IHttpClientFactory clientFactory)
public GithubRepositoryManager(IHttpClientFactory clientFactory, IGithubVersionProviderFactory githubVersionProviderFactory)
{
_clientFactory = clientFactory;
_githubVersionProviderFactory = githubVersionProviderFactory;
}
public async Task<string> GetFileRawStringContentAsync(string rawUrl, string token, string userAgent)
@ -32,11 +36,12 @@ namespace Volo.Docs.GitHub.Documents
using var httpClient = CreateHttpClient(token, userAgent);
return await httpClient.GetByteArrayAsync(new Uri(rawUrl));
}
public async Task<IReadOnlyList<Release>> GetReleasesAsync(string name, string repositoryName, string token)
public async Task<IReadOnlyList<GithubVersion>> GetVersionsAsync(string name, string repositoryName, string token, GithubVersionProviderSource githubVersionProviderSource)
{
var client = GetGitHubClient(name, token);
return await client.Repository.Release.GetAll(name, repositoryName);
var _provider = _githubVersionProviderFactory.Create(githubVersionProviderSource);
return await _provider.GetVersions(name, repositoryName, token);
}
public async Task<IReadOnlyList<GitHubCommit>> GetFileCommitsAsync(string name, string repositoryName, string version, string filename, string token)

4
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/IGithubRepositoryManager.cs

@ -4,6 +4,8 @@ using System.Text;
using System.Threading.Tasks;
using Octokit;
using Volo.Abp.DependencyInjection;
using Volo.Docs.GitHub.Documents.Version;
using Volo.Docs.Projects;
namespace Volo.Docs.GitHub.Documents
{
@ -13,7 +15,7 @@ namespace Volo.Docs.GitHub.Documents
Task<byte[]> GetFileRawByteArrayContentAsync(string rawUrl, string token, string userAgent);
Task<IReadOnlyList<Release>> GetReleasesAsync(string name, string repositoryName, string token);
Task<IReadOnlyList<GithubVersion>> GetVersionsAsync(string name, string repositoryName, string token, GithubVersionProviderSource githubVersionProviderSource);
Task<IReadOnlyList<GitHubCommit>> GetFileCommitsAsync(string name, string repositoryName, string version, string filename, string token);

28
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/BranchGithubVersionProvider.cs

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Octokit;
using Octokit.Internal;
using Volo.Abp.DependencyInjection;
namespace Volo.Docs.GitHub.Documents.Version
{
public class BranchGithubVersionProvider : IGithubVersionProvider, ITransientDependency
{
public async Task<List<GithubVersion>> GetVersions(string name, string repositoryName, string token)
{
var client = GetGitHubClient(name, token);
var branches = await client.Repository.Branch.GetAll(name, repositoryName);
return branches.Select(b => new GithubVersion {Name = b.Name}).ToList();
}
private static GitHubClient GetGitHubClient(string name, string token)
{
return token.IsNullOrWhiteSpace()
? new GitHubClient(new ProductHeaderValue(name))
: new GitHubClient(new ProductHeaderValue(name), new InMemoryCredentialStore(new Credentials(token)));
}
}
}

7
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubVersion.cs

@ -0,0 +1,7 @@
namespace Volo.Docs.GitHub.Documents.Version
{
public class GithubVersion
{
public string Name { get; set; }
}
}

34
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubVersionProviderFactory.cs

@ -0,0 +1,34 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.DependencyInjection;
using Volo.Docs.Projects;
namespace Volo.Docs.GitHub.Documents.Version
{
public class GithubVersionProviderFactory : IGithubVersionProviderFactory, ITransientDependency
{
public IServiceProvider ServiceProvider { get; }
public GithubVersionProviderFactory(IServiceProvider serviceProvider)
{
ServiceProvider = serviceProvider;
}
public IGithubVersionProvider Create(GithubVersionProviderSource source)
{
Type serviceType;
switch (source)
{
case GithubVersionProviderSource.Branches:
serviceType = typeof(BranchGithubVersionProvider);
break;
case GithubVersionProviderSource.Releases:
default:
serviceType = typeof(ReleaseGithubVersionProvider);
break;
}
return (IGithubVersionProvider)ServiceProvider.GetRequiredService(serviceType);
}
}
}

10
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IGithubVersionProvider.cs

@ -0,0 +1,10 @@
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Volo.Docs.GitHub.Documents.Version
{
public interface IGithubVersionProvider
{
Task<List<GithubVersion>> GetVersions(string name, string repositoryName, string token);
}
}

9
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IGithubVersionProviderFactory.cs

@ -0,0 +1,9 @@
using Volo.Docs.Projects;
namespace Volo.Docs.GitHub.Documents.Version
{
public interface IGithubVersionProviderFactory
{
IGithubVersionProvider Create(GithubVersionProviderSource source);
}
}

4
modules/docs/src/Volo.Docs.Web/Version/IVersionHelper.cs → modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IVersionHelper.cs

@ -1,13 +1,13 @@
using System.Collections.Generic;
using Volo.Docs.Projects;
namespace Volo.Docs.Version
namespace Volo.Docs.GitHub.Documents.Version
{
public interface IVersionHelper
{
List<string> OrderByDescending(List<string> versions);
List<VersionInfoDto> OrderByDescending(List<VersionInfoDto> versions);
List<VersionInfo> OrderByDescending(List<VersionInfo> versions);
bool IsPreRelease(string version);
}

28
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/ReleaseGithubVersionProvider.cs

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Octokit;
using Octokit.Internal;
using Volo.Abp.DependencyInjection;
namespace Volo.Docs.GitHub.Documents.Version
{
public class ReleaseGithubVersionProvider : IGithubVersionProvider, ITransientDependency
{
public async Task<List<GithubVersion>> GetVersions(string name, string repositoryName, string token)
{
var client = GetGitHubClient(name, token);
var releases = await client.Repository.Release.GetAll(name, repositoryName);
return releases.Select(r => new GithubVersion {Name = r.TagName}).ToList();
}
private static GitHubClient GetGitHubClient(string name, string token)
{
return token.IsNullOrWhiteSpace()
? new GitHubClient(new ProductHeaderValue(name))
: new GitHubClient(new ProductHeaderValue(name), new InMemoryCredentialStore(new Credentials(token)));
}
}
}

18
modules/docs/src/Volo.Docs.Web/Version/SemanticVersionHelper.cs → modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/SemanticVersionHelper.cs

@ -5,7 +5,7 @@ using NuGet.Versioning;
using Volo.Abp.DependencyInjection;
using Volo.Docs.Projects;
namespace Volo.Docs.Version
namespace Volo.Docs.GitHub.Documents.Version
{
public class SemanticVersionHelper : IVersionHelper, ITransientDependency
{
@ -14,7 +14,7 @@ namespace Volo.Docs.Version
return versions.OrderByDescending(v=> SemanticVersion.Parse(NormalizeVersion(v)), new VersionComparer()).ToList();
}
public List<VersionInfoDto> OrderByDescending(List<VersionInfoDto> versions)
public List<VersionInfo> OrderByDescending(List<VersionInfo> versions)
{
return versions.OrderByDescending(v => SemanticVersion.Parse(NormalizeVersion(v.Name)), new VersionComparer()).ToList();
}
@ -32,9 +32,19 @@ namespace Volo.Docs.Version
var versionParts = version.Split("-");
if (versionParts[0].Split(".").Length > 3)
var firstVersionPartSplitted = versionParts[0].Split(".");
if (firstVersionPartSplitted.Length > 3)
{
normalizedVersion = string.Join(".",firstVersionPartSplitted.Take(3));
}
else if (firstVersionPartSplitted.Length < 3)
{
normalizedVersion = string.Join(".",versionParts[0].Split(".").Take(3));
normalizedVersion = versionParts[0];
for (int i = firstVersionPartSplitted.Length; i < 3; i++)
{
normalizedVersion += ".0";
}
}
else
{

6
modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml

@ -53,7 +53,7 @@
<nav class="navbar navbar-logo">
@if (!Model.Project.Name.IsNullOrWhiteSpace())
{
<a class="navbar-brand w-100" href="@Model.CreateVersionLink(Model.LatestStableVersionInfo, Model.GetSpecificVersionOrLatest())">
<a class="navbar-brand w-100" href="@Model.CreateVersionLink(Model.LatestVersionInfo, Model.GetSpecificVersionOrLatest())">
<span id="ProjectName">@Model.Project.Name</span><br>
<strong class="display-block">
@L["Documents"]
@ -173,7 +173,7 @@
else
{
<ul root-node="@Model.Navigation"
version="@(Model.LatestStableVersionInfo == null || Model.LatestStableVersionInfo.IsSelected ? DocsAppConsts.Latest : Model.Version)"
version="@(Model.LatestVersionInfo == null || Model.LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Model.Version)"
project-name="@Model.ProjectName"
project-format="@Model.Project.Format"
selected-document-name="@Model.DocumentNameWithExtension"
@ -374,7 +374,7 @@ else
model = new ErrorPageModel
{
RedirectUrl = Model.DocumentsUrlPrefix + Model.LanguageCode + "/" + Model.ProjectName + "/"
+ (Model.LatestStableVersionInfo.IsSelected ? DocsAppConsts.Latest : Model.Version),
+ (Model.LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Model.Version),
ErrorCode = "404",
ErrorMessage = L.GetString("DocumentNotFound"),
AutoRedirect = !Model.DocumentName.IsNullOrWhiteSpace()

60
modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs

@ -16,9 +16,7 @@ using Volo.Docs.Documents;
using Volo.Docs.HtmlConverting;
using Volo.Docs.Models;
using Volo.Docs.Projects;
using Volo.Docs.Utils;
using NuGet.Versioning;
using Volo.Docs.Version;
using Volo.Docs.GitHub.Documents.Version;
namespace Volo.Docs.Pages.Documents.Project
{
@ -60,7 +58,7 @@ namespace Volo.Docs.Pages.Documents.Project
public NavigationNode Navigation { get; private set; }
public VersionInfoViewModel LatestStableVersionInfo { get; private set; }
public VersionInfoViewModel LatestVersionInfo { get; private set; }
public string DocumentsUrlPrefix { get; set; }
@ -207,7 +205,7 @@ namespace Volo.Docs.Pages.Documents.Project
private IActionResult ReloadPageWithCulture()
{
var returnUrl = DocumentsUrlPrefix + LanguageCode + "/" + ProjectName + "/"
+ (LatestStableVersionInfo.IsSelected ? DocsAppConsts.Latest : Version) + "/" +
+ (LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Version) + "/" +
DocumentName;
return Redirect("/Abp/Languages/Switch?culture=" + LanguageCode + "&uiCulture=" + LanguageCode + "&returnUrl=" + returnUrl);
@ -218,7 +216,7 @@ namespace Volo.Docs.Pages.Documents.Project
return RedirectToPage(new
{
projectName = ProjectName,
version = (LatestStableVersionInfo.IsSelected ? DocsAppConsts.Latest : Version),
version = (LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Version),
languageCode = DefaultLanguageCode,
documentName = DocumentName
});
@ -229,7 +227,7 @@ namespace Volo.Docs.Pages.Documents.Project
return RedirectToPage(new
{
projectName = ProjectName,
version = (LatestStableVersionInfo.IsSelected ? DocsAppConsts.Latest : Version),
version = (LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Version),
documentName = "",
languageCode = DefaultLanguageCode
});
@ -256,22 +254,22 @@ namespace Volo.Docs.Pages.Documents.Project
}
var output = await _projectAppService.GetVersionsAsync(Project.ShortName);
var versions = _versionHelper.OrderByDescending(output.Items.ToList())
var versions = output.Items.ToList()
.Select(v => new VersionInfoViewModel(v.DisplayName, v.Name))
.ToList();
if (versions.Any())
{
LatestStableVersionInfo = versions.FirstOrDefault(v => !_versionHelper.IsPreRelease(v.Version)) ?? versions.First();
LatestVersionInfo = GetLatestVersionInfo(versions);
SetLatestVersionBranchName(versions);
LatestStableVersionInfo.DisplayText = $"{LatestStableVersionInfo.DisplayText} ({DocsAppConsts.Latest})";
LatestVersionInfo.DisplayText = $"{LatestVersionInfo.DisplayText} ({DocsAppConsts.Latest})";
if (string.Equals(Version, DocsAppConsts.Latest, StringComparison.OrdinalIgnoreCase))
{
LatestStableVersionInfo.IsSelected = true;
Version = LatestStableVersionInfo.Version;
LatestVersionInfo.IsSelected = true;
Version = LatestVersionInfo.Version;
}
else
{
@ -283,8 +281,8 @@ namespace Volo.Docs.Pages.Documents.Project
}
else
{
LatestStableVersionInfo.IsSelected = true;
Version = LatestStableVersionInfo.Version;
LatestVersionInfo.IsSelected = true;
Version = LatestVersionInfo.Version;
}
}
}
@ -292,7 +290,7 @@ namespace Volo.Docs.Pages.Documents.Project
{
SetLatestVersionBranchName(versions);
LatestStableVersionInfo = new VersionInfoViewModel(
LatestVersionInfo = new VersionInfoViewModel(
$"{DocsAppConsts.Latest}",
DocsAppConsts.Latest,
true);
@ -301,14 +299,38 @@ namespace Volo.Docs.Pages.Documents.Project
VersionSelectItems = versions.Select(v => new SelectListItem
{
Text = v.DisplayText,
Value = CreateVersionLink(LatestStableVersionInfo, v.Version, DocumentName),
Value = CreateVersionLink(LatestVersionInfo, v.Version, DocumentName),
Selected = v.IsSelected
}).ToList();
}
private VersionInfoViewModel GetLatestVersionInfo(List<VersionInfoViewModel> versions)
{
if (Project.ExtraProperties.ContainsKey("GithubVersionProviderSource")
&& (GithubVersionProviderSource) (long) Project.ExtraProperties["GithubVersionProviderSource"] == GithubVersionProviderSource.Branches)
{
var prefix = Project.ExtraProperties["VersionBranchPrefix"].ToString();
var LatestVersionBranchNameWithoutPrefix =
!string.IsNullOrWhiteSpace(Project.LatestVersionBranchName) &&
Project.LatestVersionBranchName.StartsWith(prefix) && Project.LatestVersionBranchName.Length > prefix.Length
? Project.LatestVersionBranchName.Substring(prefix.Length)
: Project.LatestVersionBranchName;
var latest = versions.FirstOrDefault(v=> v.Version == LatestVersionBranchNameWithoutPrefix);
if (latest != null)
{
return latest;
}
}
return versions.FirstOrDefault(v => !_versionHelper.IsPreRelease(v.Version)) ?? versions.First();
}
private void SetLatestVersionBranchName(List<VersionInfoViewModel> versions)
{
if (versions.Any() && !string.IsNullOrEmpty(Project.LatestVersionBranchName))
if (!Project.ExtraProperties.ContainsKey("GithubVersionProviderSource")
|| (GithubVersionProviderSource) (long) Project.ExtraProperties["GithubVersionProviderSource"] == GithubVersionProviderSource.Releases)
{
versions.First(v=> !_versionHelper.IsPreRelease(v.Version)).Version = Project.LatestVersionBranchName;
}
@ -357,7 +379,7 @@ namespace Volo.Docs.Pages.Documents.Project
return DocsAppConsts.Latest;
}
return Document.Version == LatestStableVersionInfo.Version ?
return Document.Version == LatestVersionInfo.Version ?
DocsAppConsts.Latest :
Document.Version;
}
@ -396,7 +418,7 @@ namespace Volo.Docs.Pages.Documents.Project
LanguageSelectListItems.Add(
new SelectListItem(
language.DisplayName,
DocumentsUrlPrefix + language.Code + "/" + Project.ShortName + "/" + (LatestStableVersionInfo.IsSelected ? DocsAppConsts.Latest : Version) + "/" + DocumentName,
DocumentsUrlPrefix + language.Code + "/" + Project.ShortName + "/" + (LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Version) + "/" + DocumentName,
language.Code == LanguageCode
)
);

33
modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml.cs

@ -7,27 +7,23 @@ using System.Web;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Volo.Docs.Documents;
using Volo.Docs.GitHub.Documents.Version;
using Volo.Docs.HtmlConverting;
using Volo.Docs.Models;
using Volo.Docs.Projects;
using Volo.Docs.Utils;
using Volo.Docs.Version;
namespace Volo.Docs.Pages.Documents
{
public class SearchModel : PageModel
{
[BindProperty(SupportsGet = true)]
public string ProjectName { get; set; }
[BindProperty(SupportsGet = true)] public string ProjectName { get; set; }
[BindProperty(SupportsGet = true)]
public string Version { get; set; }
[BindProperty(SupportsGet = true)] public string Version { get; set; }
[BindProperty(SupportsGet = true)]
public string LanguageCode { get; set; }
[BindProperty(SupportsGet = true)] public string LanguageCode { get; set; }
[BindProperty(SupportsGet = true)]
public string KeyWord { get; set; }
[BindProperty(SupportsGet = true)] public string KeyWord { get; set; }
public ProjectDto Project { get; set; }
@ -64,11 +60,19 @@ namespace Volo.Docs.Pages.Documents
var versions = output.Items.ToList();
if (versions.Any() && string.Equals(Version, DocsAppConsts.Latest, StringComparison.OrdinalIgnoreCase))
if (versions.Any() &&
string.Equals(Version, DocsAppConsts.Latest, StringComparison.OrdinalIgnoreCase))
{
Version = string.IsNullOrEmpty(Project.LatestVersionBranchName) ?
(versions.FirstOrDefault(v=> !_versionHelper.IsPreRelease(v.Name)) ?? versions.First()).Name :
Project.LatestVersionBranchName;
if ((!Project.ExtraProperties.ContainsKey("GithubVersionProviderSource") ||
(GithubVersionProviderSource) (long) Project.ExtraProperties["GithubVersionProviderSource"] ==GithubVersionProviderSource.Releases) &&
!string.IsNullOrEmpty(Project.LatestVersionBranchName))
{
Version = Project.LatestVersionBranchName;
}
else
{
Version = (versions.FirstOrDefault(v => !_versionHelper.IsPreRelease(v.Name)) ?? versions.First()).Name;
}
}
SearchOutputs = await _documentAppService.SearchAsync(new DocumentSearchInput
@ -86,7 +90,8 @@ namespace Volo.Docs.Pages.Documents
for (var i = 0; i < searchOutput.Highlight.Count; i++)
{
searchOutput.Highlight[i] = _encoder
.Encode(searchOutput.Highlight[i].Replace("<highlight>", highlightTag1).Replace("</highlight>", highlightTag2))
.Encode(searchOutput.Highlight[i].Replace("<highlight>", highlightTag1)
.Replace("</highlight>", highlightTag2))
.Replace(highlightTag1, "<highlight>").Replace(highlightTag2, "</highlight>");
}
}

1
modules/docs/src/Volo.Docs.Web/Volo.Docs.Web.csproj

@ -25,7 +25,6 @@
<PackageReference Include="Markdig.Signed" Version="0.20.0" />
<PackageReference Include="Scriban" Version="2.1.3" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="3.1.5" />
<PackageReference Include="NuGet.Versioning" Version="5.6.0" />
</ItemGroup>

30
modules/docs/test/Volo.Docs.TestBase/Volo/Docs/DocsTestBase.cs

@ -7,10 +7,12 @@ using Volo.Abp;
using Volo.Abp.Modularity;
using Volo.Docs.GitHub.Documents;
using Volo.Abp.Testing;
using Volo.Docs.GitHub.Documents.Version;
using Volo.Docs.Projects;
namespace Volo.Docs
{
public abstract class DocsTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule>
public abstract class DocsTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule>
where TStartupModule : IAbpModule
{
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
@ -30,27 +32,13 @@ namespace Volo.Docs
repositoryManager.GetFileRawByteArrayContentAsync(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>())
.Returns(new byte[] { 0x01, 0x02, 0x03 });
repositoryManager.GetReleasesAsync(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>())
.Returns(new List<Release>
repositoryManager.GetVersionsAsync(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), GithubVersionProviderSource.Releases)
.Returns(new List<GithubVersion>
{
new Release("https://api.github.com/repos/abpframework/abp/releases/16293679",
"https://github.com/abpframework/abp/releases/tag/0.15.0",
"https://api.github.com/repos/abpframework/abp/releases/16293679/assets",
"https://uploads.github.com/repos/abpframework/abp/releases/16293679/assets{?name,label}",
16293679,
"",
"0.15.0",
"master",
"0.15.0",
"0.15.0 already release",
false,
false,
DateTimeOffset.Parse("2019-03-22T18:43:58Z"),
DateTimeOffset.Parse("2019-03-22T19:44:25Z"),
null,
"https://api.github.com/repos/abpframework/abp/tarball/0.15.0",
"https://api.github.com/repos/abpframework/abp/zipball/0.15.0",
null)
new GithubVersion()
{
Name = "0.15.0"
}
});
repositoryManager.GetFileCommitsAsync(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(),
Arg.Any<string>(), Arg.Any<string>())

Loading…
Cancel
Save