From 8d87d539d7c701831a27d4667df9f11c66a38803 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 23 Jul 2020 15:41:44 +0300 Subject: [PATCH 1/5] Docs module: added alternative way (using branches) to get versions resolves https://github.com/abpframework/abp/issues/4845 --- .../Docs/Admin/Projects/CreateProjectDto.cs | 3 +- .../Volo/Docs/Admin/Projects/ProjectDto.cs | 3 +- .../Docs/Admin/Projects/UpdateProjectDto.cs | 3 +- .../DocsAdminWebAutoMapperProfile.cs | 6 +- .../Docs/Admin/Projects/Create.cshtml.cs | 13 +++- .../Pages/Docs/Admin/Projects/Edit.cshtml.cs | 15 ++++- .../Projects/GithubVersionProviderSource.cs | 8 +++ .../Volo.Docs.Domain/Volo.Docs.Domain.csproj | 3 +- .../GitHub/Documents/GithubDocumentSource.cs | 59 ++++++++++++++----- .../Documents/GithubRepositoryManager.cs | 15 +++-- .../Documents/IGithubRepositoryManager.cs | 4 +- .../Documents/Version/GithubBranchProvider.cs | 28 +++++++++ .../Version/GithubReleaseProvider.cs | 28 +++++++++ .../GitHub/Documents/Version/GithubVersion.cs | 7 +++ .../Version/GithubVersionProviderFactory.cs | 34 +++++++++++ .../Version/IGithubVersionProvider.cs | 10 ++++ .../Version/IGithubVersionProviderFactory.cs | 9 +++ .../Documents}/Version/IVersionHelper.cs | 4 +- .../Version/SemanticVersionHelper.cs | 4 +- .../Pages/Documents/Project/Index.cshtml | 6 +- .../Pages/Documents/Project/Index.cshtml.cs | 37 ++++++------ .../Pages/Documents/Search.cshtml.cs | 33 ++++++----- .../src/Volo.Docs.Web/Volo.Docs.Web.csproj | 1 - .../Volo/Docs/DocsTestBase.cs | 30 +++------- 24 files changed, 270 insertions(+), 93 deletions(-) create mode 100644 modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Projects/GithubVersionProviderSource.cs create mode 100644 modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubBranchProvider.cs create mode 100644 modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubReleaseProvider.cs create mode 100644 modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubVersion.cs create mode 100644 modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubVersionProviderFactory.cs create mode 100644 modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IGithubVersionProvider.cs create mode 100644 modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IGithubVersionProviderFactory.cs rename modules/docs/src/{Volo.Docs.Web => Volo.Docs.Domain/Volo/Docs/GitHub/Documents}/Version/IVersionHelper.cs (65%) rename modules/docs/src/{Volo.Docs.Web => Volo.Docs.Domain/Volo/Docs/GitHub/Documents}/Version/SemanticVersionHelper.cs (92%) diff --git a/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/CreateProjectDto.cs b/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/CreateProjectDto.cs index eb603b334c..0918e19d8e 100644 --- a/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/CreateProjectDto.cs +++ b/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 ExtraProperties { get; set; } } -} \ No newline at end of file +} diff --git a/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/ProjectDto.cs b/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/ProjectDto.cs index c71f34e357..b624a1f187 100644 --- a/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/ProjectDto.cs +++ b/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 ExtraProperties { get; set; } } -} \ No newline at end of file +} diff --git a/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/UpdateProjectDto.cs b/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/UpdateProjectDto.cs index 9e94cec66e..f2d3c218c8 100644 --- a/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/UpdateProjectDto.cs +++ b/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 ExtraProperties { get; set; } } -} \ No newline at end of file +} diff --git a/modules/docs/src/Volo.Docs.Admin.Web/DocsAdminWebAutoMapperProfile.cs b/modules/docs/src/Volo.Docs.Admin.Web/DocsAdminWebAutoMapperProfile.cs index ca430cdaad..83f993d1e8 100644 --- a/modules/docs/src/Volo.Docs.Admin.Web/DocsAdminWebAutoMapperProfile.cs +++ b/modules/docs/src/Volo.Docs.Admin.Web/DocsAdminWebAutoMapperProfile.cs @@ -15,7 +15,11 @@ namespace Volo.Docs.Admin CreateMap().Ignore(x => x.ExtraProperties); CreateMap () - .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(); CreateMap(); diff --git a/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Create.cshtml.cs b/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Create.cshtml.cs index 506b674ba5..3f5b847538 100644 --- a/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Create.cshtml.cs +++ b/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; } } } -} \ No newline at end of file +} diff --git a/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Edit.cshtml.cs b/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Edit.cshtml.cs index ef1762c460..6530c7ec66 100644 --- a/modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Edit.cshtml.cs +++ b/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,8 @@ 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)]; + GithubProject.GithubVersionProviderSource = (GithubVersionProviderSource) dto.ExtraProperties[nameof(GithubProject.GithubVersionProviderSource)]; + GithubProject.VersionBranchPrefix = (string) dto.ExtraProperties[nameof(GithubProject.VersionBranchPrefix)]; } public abstract class EditProjectViewModelBase @@ -125,6 +129,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; } } } -} \ No newline at end of file +} diff --git a/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Projects/GithubVersionProviderSource.cs b/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Projects/GithubVersionProviderSource.cs new file mode 100644 index 0000000000..4773ecf74d --- /dev/null +++ b/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 + } +} diff --git a/modules/docs/src/Volo.Docs.Domain/Volo.Docs.Domain.csproj b/modules/docs/src/Volo.Docs.Domain/Volo.Docs.Domain.csproj index 1042aeec0e..a0da321cae 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo.Docs.Domain.csproj +++ b/modules/docs/src/Volo.Docs.Domain/Volo.Docs.Domain.csproj @@ -21,8 +21,9 @@ + - + diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs index 1da1ab1f9d..b15e85bd8b 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs +++ b/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 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> GetVersionsAsync(Project project) { + var url = project.GetGitHubUrl(); + var ownerName = GetOwnerNameFromUrl(url); + var repositoryName = GetRepositoryNameFromUrl(url); + var githubVersionProviderSource = GetGithubVersionProviderSource(project); + List 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,42 @@ namespace Volo.Docs.GitHub.Documents versions = new List(); } - if (!versions.Any() && !string.IsNullOrEmpty(project.LatestVersionBranchName)) + if (githubVersionProviderSource == GithubVersionProviderSource.Branches && project.ExtraProperties.ContainsKey("VersionBranchPrefix")) { - versions.Add(new VersionInfo { DisplayName = "1.0.0", Name = project.LatestVersionBranchName }); + var prefix = (string) project.ExtraProperties["VersionBranchPrefix"]; + + if (!string.IsNullOrEmpty(prefix)) + { + versions = versions.Where(v => v.Name.StartsWith(prefix)).ToList(); + versions.ForEach(v=> v.Name.Substring(prefix.Length)); + versions.ForEach(v=> v.DisplayName.Substring(prefix.Length)); + } + + versions = _versionHelper.OrderByDescending(versions); + } + + if(githubVersionProviderSource == GithubVersionProviderSource.Releases) + { + 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) project.ExtraProperties["GithubVersionProviderSource"] + : GithubVersionProviderSource.Releases; + } + public async Task GetResource(Project project, string resourceName, string languageCode, string version) { var rawRootUrl = CalculateRawRootUrlWithLanguageCode(project.GetGitHubUrl(version), languageCode); @@ -277,14 +312,6 @@ namespace Volo.Docs.GitHub.Documents return languageConfig; } - private async Task> 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> GetFileCommitsAsync(Project project, string version, string filename) { var url = project.GetGitHubUrl(); diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubRepositoryManager.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubRepositoryManager.cs index ef21353236..8d99e360ef 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubRepositoryManager.cs +++ b/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 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> GetReleasesAsync(string name, string repositoryName, string token) + + public async Task> 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> GetFileCommitsAsync(string name, string repositoryName, string version, string filename, string token) diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/IGithubRepositoryManager.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/IGithubRepositoryManager.cs index 67536fc559..12f3bc4ef2 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/IGithubRepositoryManager.cs +++ b/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 GetFileRawByteArrayContentAsync(string rawUrl, string token, string userAgent); - Task> GetReleasesAsync(string name, string repositoryName, string token); + Task> GetVersionsAsync(string name, string repositoryName, string token, GithubVersionProviderSource githubVersionProviderSource); Task> GetFileCommitsAsync(string name, string repositoryName, string version, string filename, string token); diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubBranchProvider.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubBranchProvider.cs new file mode 100644 index 0000000000..06a02b96a6 --- /dev/null +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubBranchProvider.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 GithubBranchProvider : IGithubVersionProvider, ITransientDependency + { + public async Task> 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))); + } + } +} diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubReleaseProvider.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubReleaseProvider.cs new file mode 100644 index 0000000000..0425a3cb28 --- /dev/null +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubReleaseProvider.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 GithubReleaseProvider : IGithubVersionProvider, ITransientDependency + { + public async Task> 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))); + } + } +} diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubVersion.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubVersion.cs new file mode 100644 index 0000000000..5c3e98aac0 --- /dev/null +++ b/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; } + } +} \ No newline at end of file diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubVersionProviderFactory.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubVersionProviderFactory.cs new file mode 100644 index 0000000000..48bc2fe678 --- /dev/null +++ b/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(GithubBranchProvider); + break; + case GithubVersionProviderSource.Releases: + default: + serviceType = typeof(GithubReleaseProvider); + break; + } + + return (IGithubVersionProvider)ServiceProvider.GetRequiredService(serviceType); + } + } +} diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IGithubVersionProvider.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IGithubVersionProvider.cs new file mode 100644 index 0000000000..429e2ec34b --- /dev/null +++ b/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> GetVersions(string name, string repositoryName, string token); + } +} diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IGithubVersionProviderFactory.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IGithubVersionProviderFactory.cs new file mode 100644 index 0000000000..5236e52fbd --- /dev/null +++ b/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); + } +} diff --git a/modules/docs/src/Volo.Docs.Web/Version/IVersionHelper.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IVersionHelper.cs similarity index 65% rename from modules/docs/src/Volo.Docs.Web/Version/IVersionHelper.cs rename to modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IVersionHelper.cs index f3fd202155..67bed57093 100644 --- a/modules/docs/src/Volo.Docs.Web/Version/IVersionHelper.cs +++ b/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 OrderByDescending(List versions); - List OrderByDescending(List versions); + List OrderByDescending(List versions); bool IsPreRelease(string version); } diff --git a/modules/docs/src/Volo.Docs.Web/Version/SemanticVersionHelper.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/SemanticVersionHelper.cs similarity index 92% rename from modules/docs/src/Volo.Docs.Web/Version/SemanticVersionHelper.cs rename to modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/SemanticVersionHelper.cs index c60abaccea..cad8c3c180 100644 --- a/modules/docs/src/Volo.Docs.Web/Version/SemanticVersionHelper.cs +++ b/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 OrderByDescending(List versions) + public List OrderByDescending(List versions) { return versions.OrderByDescending(v => SemanticVersion.Parse(NormalizeVersion(v.Name)), new VersionComparer()).ToList(); } diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml index 71c7d4790c..bd76814461 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml @@ -53,7 +53,7 @@