-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding In Basic GitLab Support (#34)
* basic template for gitlab * readme update * Pull request and pipelines for gitlab * GitLab repository feature * global json serialiser convert for enums * Vulnerability checking and caching in pipeline * retrigger for cache test * name change
- Loading branch information
Showing
30 changed files
with
567 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/backend/CodeHub.Platform.GitLab/CodeHub.Platform.GitLab.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<ItemGroup> | ||
<PackageReference Include="NGitLab"/> | ||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions"/> | ||
<PackageReference Include="Microsoft.Extensions.Caching.Memory"/> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\CodeHub.Shared\CodeHub.Shared.csproj"/> | ||
</ItemGroup> | ||
</Project> |
8 changes: 8 additions & 0 deletions
8
src/backend/CodeHub.Platform.GitLab/Constants/CacheConstants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace CodeHub.Platform.GitLab.Constants; | ||
|
||
internal static class CacheConstants | ||
{ | ||
internal const string PipelineCacheKey = "gitlab-pipelines"; | ||
internal const string PullRequestCacheKey = "gitlab-pullrequests"; | ||
internal const string RepositoryCacheKey = "gitlab-repositories"; | ||
} |
48 changes: 48 additions & 0 deletions
48
src/backend/CodeHub.Platform.GitLab/Extensions/GitLabExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using CodeHub.Platform.GitLab.Models; | ||
using CodeHub.Platform.GitLab.Services; | ||
using CodeHub.Platform.GitLab.Validator; | ||
using CodeHub.Shared.Query; | ||
using CodeHub.Shared.Services; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
|
||
namespace CodeHub.Platform.GitLab.Extensions; | ||
|
||
public static class GitLabExtensions | ||
{ | ||
public static IServiceCollection RegisterGitLab(this IServiceCollection services, | ||
IConfiguration configuration) | ||
{ | ||
var settings = GitLabSettingsValidator.GetValidSettings(configuration); | ||
|
||
if (!settings.IsEnabled) | ||
{ | ||
return services; | ||
} | ||
|
||
services.RegisterCache(); | ||
services.RegisterServices(); | ||
services.RegisterOptions(configuration); | ||
return services; | ||
} | ||
|
||
private static void RegisterCache(this IServiceCollection services) | ||
{ | ||
services.AddMemoryCache(options => options.TrackStatistics = true); | ||
} | ||
|
||
private static void RegisterServices(this IServiceCollection services) | ||
{ | ||
services.TryAddSingleton<IGitLabConnectionService, GitLabConnectionService>(); | ||
services.TryAddSingleton<IGitLabService, GitLabService>(); | ||
services.AddScoped<IQueryService, GitLabQueryService>(); | ||
services.AddSingleton<IDiscoveryService, GitLabDiscoveryService>(); | ||
} | ||
|
||
private static void RegisterOptions(this IServiceCollection services, IConfiguration configuration) | ||
{ | ||
services.AddOptions<GitLabSettings>() | ||
.Bind(configuration.GetRequiredSection(nameof(GitLabSettings))); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/backend/CodeHub.Platform.GitLab/Extensions/GitLabMapperExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System.Collections.Immutable; | ||
using CodeHub.Platform.GitLab.Models; | ||
using CodeHub.Shared.Models; | ||
using NGitLab.Models; | ||
using Commit = CodeHub.Shared.Models.Commit; | ||
|
||
namespace CodeHub.Platform.GitLab.Extensions; | ||
|
||
internal static class GitLabMapperExtensions | ||
{ | ||
internal static GitLabPullRequest MapToGitLabPullRequest(this MergeRequest mergeRequest) | ||
{ | ||
return new GitLabPullRequest | ||
{ | ||
Id = new PullRequestId(mergeRequest.Id.ToString()), | ||
Name = mergeRequest.Title, | ||
Description = mergeRequest.Description, | ||
Url = new Uri(mergeRequest.WebUrl), | ||
Labels = mergeRequest.Labels.ToImmutableHashSet(), | ||
Reviewers = mergeRequest.Reviewers.Select(r => r.Name).ToImmutableHashSet(), | ||
Status = PullRequestStatus.Draft, | ||
Platform = PullRequestPlatform.GitLab, | ||
LastCommit = new Commit | ||
{ | ||
Id = new CommitId(""), | ||
Url = new Uri(mergeRequest.WebUrl), | ||
Committer = string.Empty, | ||
Comment = string.Empty, | ||
ChangeCount = 0 | ||
}, | ||
RepositoryUrl = new Uri(mergeRequest.WebUrl), | ||
RepositoryName = string.Empty, | ||
CreatedOnDate = DateOnly.FromDateTime(mergeRequest.CreatedAt) | ||
}; | ||
} | ||
|
||
internal static GitLabPipeline MapToGitLabPipeline(this PipelineBasic pipeline) | ||
{ | ||
return new GitLabPipeline | ||
{ | ||
Id = new PipelineId(pipeline.Id.ToString()), | ||
Name = pipeline.Name, | ||
Url = new Uri(pipeline.WebUrl), | ||
Owner = Owner.CreateEmptyOwner(), | ||
Platform = PipelinePlatform.GitLab | ||
}; | ||
} | ||
|
||
internal static GitLabRepository MapToGitLabRepository(this Project project) | ||
{ | ||
return new GitLabRepository | ||
{ | ||
Id = new RepositoryId(project.Id.ToString()), | ||
Name = project.Name, | ||
Url = new Uri(project.WebUrl), | ||
DefaultBranch = project.DefaultBranch, | ||
Owner = new Owner | ||
{ | ||
Id = new OwnerId(project.Owner.Id.ToString()), | ||
Name = project.Owner.Name, | ||
Description = project.Owner.Bio, | ||
Url = new Uri(project.Owner.WebURL), | ||
Platform = OwnerPlatform.AzureDevOps | ||
}, | ||
Platform = RepositoryPlatform.GitLab | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using CodeHub.Shared.Models; | ||
|
||
namespace CodeHub.Platform.GitLab.Models; | ||
|
||
public sealed record GitLabPipeline : Pipeline | ||
{ | ||
} |
Oops, something went wrong.