diff --git a/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Localization/Resources/Docs/ApplicationContracts/cs.json b/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Localization/Resources/Docs/ApplicationContracts/cs.json index 081a5f2cd4..f02fa96f50 100644 --- a/modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Localization/Resources/Docs/ApplicationContracts/cs.json +++ b/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", 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..ee27a2dc15 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,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; } } } -} \ No newline at end of file +} diff --git a/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs b/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs index 6cacf9d3e3..6df4c6179e 100644 --- a/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs +++ b/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 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 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; + } } } diff --git a/modules/docs/src/Volo.Docs.Application/Volo/Docs/Projects/ProjectAppService.cs b/modules/docs/src/Volo.Docs.Application/Volo/Docs/Projects/ProjectAppService.cs index 2284804143..728840135e 100644 --- a/modules/docs/src/Volo.Docs.Application/Volo/Docs/Projects/ProjectAppService.cs +++ b/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 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; + } } } 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..3a79227934 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,45 @@ namespace Volo.Docs.GitHub.Documents versions = new List(); } - 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 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> 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/BranchGithubVersionProvider.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/BranchGithubVersionProvider.cs new file mode 100644 index 0000000000..524eecb33c --- /dev/null +++ b/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> 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/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..d3c7ba9a72 --- /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(BranchGithubVersionProvider); + break; + case GithubVersionProviderSource.Releases: + default: + serviceType = typeof(ReleaseGithubVersionProvider); + 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.Domain/Volo/Docs/GitHub/Documents/Version/ReleaseGithubVersionProvider.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/ReleaseGithubVersionProvider.cs new file mode 100644 index 0000000000..f4b9fee2b2 --- /dev/null +++ b/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> 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.Web/Version/SemanticVersionHelper.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/SemanticVersionHelper.cs similarity index 67% 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..fbd315f834 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(); } @@ -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 { 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 @@