38#pragma warning disable CA1506
85 authenticationContext,
112 if (
model.Origin ==
null)
113 return BadRequest(
ErrorCode.ModelValidationFailure);
115 if (
model.AccessUser ==
null ^
model.AccessToken ==
null)
116 return BadRequest(
ErrorCode.RepoMismatchUserAndAccessToken);
166 "Clone{1} repository {0}",
169 ?
$"\"{cloneBranch}\" branch of"
195 await databaseContextFactory.UseContext(
196 async databaseContext =>
198 databaseContext.Instances.Attach(instance);
200 await databaseContext.Save(
ct);
209 return this.Created(api);
249 return Accepted(api);
285 return Accepted(api);
330 return this.Created(api);
360#pragma warning disable CA1502
362#pragma warning restore CA1502
366 if (
model.AccessUser ==
null ^
model.AccessToken ==
null)
369 if (
model.CheckoutSha !=
null &&
model.Reference !=
null)
372 if (
model.CheckoutSha !=
null &&
model.UpdateFromOrigin ==
true)
375 if (
model.NewTestMerges?.Any(
x =>
model.NewTestMerges.Any(
y =>
x !=
y &&
x.Number ==
y.Number)) ==
true)
378 if (
model.CommitterName?.Length == 0)
381 if (
model.CommitterEmail?.Length == 0)
429 if (
model.AccessToken?.Length == 0 &&
model.AccessUser?.Length == 0)
473 if (
model.UpdateFromOrigin ==
true)
474 if (
model.Reference !=
null)
476 else if (
model.CheckoutSha !=
null)
480 else if (
model.Reference !=
null ||
model.CheckoutSha !=
null)
486 "{0}est merge(s) {1}{2}",
492 model.NewTestMerges!.Select(
497 x.TargetCommitSha !=
null
501 x.TargetCommitSha[..7])
522 return Accepted(api);
538 Models.Instance instance,
584 Logger.LogDebug(
"Repository access token updated, performing auth check...");
596 if (gitHubClient ==
null)
600 AdditionalData =
"GitHub authentication failed!",
607 if (!
model.AccessToken.StartsWith(
Api.Models.RepositorySettings.TgsAppPrivateKeyPrefix))
609 var user =
await gitHubClient.User.Current();
627 AdditionalData = $
"GitHub Authentication Failure: {ex.Message}",
645 if (user ==
null || user.Username !=
model.AccessUser)
654 AdditionalData = $
"GitLab Authentication Failure: {ex.Message}",
664 Logger.LogWarning(
"RemoteGitProvider is {provider}, no auth check implemented!",
remoteFeatures.RemoteGitProvider.Value);
virtual ? long Id
The ID of the entity.
Metadata about a server instance.
Represents a request to clone the repository.
Represents a request to change the repository.
Represents an error message returned by the server.
Represents a git repository.
Routes to a server actions.
const string Repository
The git repository controller.
async ValueTask DeleteRepository(CancellationToken cancellationToken)
Delete the current repository.A ValueTask representing the running operation.
StatusCodeResult StatusCode(HttpStatusCode statusCode)
Strongly type calls to ControllerBase.StatusCode(int).
ILogger< ApiController > Logger
The ILogger for the ApiController.
async ValueTask< IActionResult?> WithComponentInstanceNullable(Func< IInstanceCore, ValueTask< IActionResult?> > action, Models.Instance? instance=null)
Run a given action with the relevant IInstance.
readonly IInstanceManager instanceManager
The IInstanceManager for the ComponentInterfacingController.
async ValueTask< IActionResult > WithComponentInstance(Func< IInstanceCore, ValueTask< IActionResult > > action, Models.Instance? instance=null)
Run a given action with the relevant IInstance.
ComponentInterfacingController for operations that require an instance.
ApiController for managing the git repository.
async ValueTask< bool > PopulateApi(RepositoryResponse apiResponse, IRepository repository, IDatabaseContext databaseContext, Models.Instance instance, CancellationToken cancellationToken)
Populate a given apiResponse with the current state of a given repository .
async ValueTask< IActionResult > Read(CancellationToken cancellationToken)
Get the repository's status.
async ValueTask< IActionResult > Reclone(CancellationToken cancellationToken)
Delete the repository.
readonly IGitHubClientFactory gitHubClientFactory
The IGitHubClientFactory for the RepositoryController.
async ValueTask< IActionResult?> ValidateCredentials(Api.Models.RepositorySettings model, Uri origin, CancellationToken cancellationToken)
Validates the Api.Models.RepositorySettings.AccessToken of a given model if it is set.
readonly ILoggerFactory loggerFactory
The ILoggerFactory for the RepositoryController.
async ValueTask< IActionResult > Update([FromBody] RepositoryUpdateRequest model, CancellationToken cancellationToken)
Perform updates to the repository.
RepositoryUpdateService CreateRepositoryUpdateService(Models.RepositorySettings currentModel)
Creates a RepositoryUpdateService.
async ValueTask< IActionResult > Create([FromBody] RepositoryCreateRequest model, CancellationToken cancellationToken)
Begin cloning the repository if it doesn't exist.
readonly IJobManager jobManager
The IJobManager for the RepositoryController.
async ValueTask< IActionResult > Delete(CancellationToken cancellationToken)
Delete the repository.
RepositoryController(IDatabaseContext databaseContext, IAuthenticationContext authenticationContext, ILogger< RepositoryController > logger, IInstanceManager instanceManager, ILoggerFactory loggerFactory, IJobManager jobManager, IGitRemoteFeaturesFactory gitRemoteFeaturesFactory, IGitHubClientFactory gitHubClientFactory, IApiHeadersProvider apiHeaders)
Initializes a new instance of the RepositoryController class.
readonly IGitRemoteFeaturesFactory gitRemoteFeaturesFactory
The IGitRemoteFeaturesFactory for the RepositoryController.
Backend abstract implementation of IDatabaseContext.
DbSet< RepositorySettings > RepositorySettings
The Models.RepositorySettings in the DatabaseContext.
Task Save(CancellationToken cancellationToken)
Saves changes made to the IDatabaseContext.A Task representing the running operation.
Operation exceptions thrown from the context of a Models.Job.
Represents an Api.Models.Instance in the database.
static Job Create(JobCode code, User? startedBy, Api.Models.Instance instance)
Creates a new job for registering in the Jobs.IJobService.
User User
The authenticated user.
ulong GetRight(RightsType rightsType)
Get the value of a given rightsType .The value of rightsType . Note that if InstancePermissionSet is ...
Identifies a repository either by its RepositoryId or Owner and Name.
Factory for creating IGraphQLGitLabClients.
static async ValueTask< IGraphQLGitLabClient > CreateClient(string? bearerToken=null)
Sets up a IGraphQLGitLabClient.
Factory for creating IGitRemoteFeatures.
IGitRemoteFeatures CreateGitRemoteFeatures(IRepository repository)
Create the IGitRemoteFeatures for a given repository .
Represents an on-disk git repository.
string Reference
The current reference the IRepository HEAD is using. This can be a branch or tag.
Uri Origin
The current origin remote the IRepository is using.
Manages the runtime of Jobs.
ValueTask RegisterOperation(Job job, JobEntrypoint operation, CancellationToken cancellationToken)
Registers a given Job and begins running it.
For creating and accessing authentication contexts.
For creating IGitHubClients.
ValueTask< IGitHubClient?> CreateClientForRepository(string accessString, RepositoryIdentifier repositoryIdentifier, CancellationToken cancellationToken)
Creates a GitHub client that will only be used for a given repositoryIdentifier .
IGitHubClient? CreateAppClient(string tgsEncodedAppPrivateKey)
Create an App (not installation) authenticated IGitHubClient.
ErrorCode
Types of Response.ErrorMessageResponses that the API may return.
JobCode
The different types of Response.JobResponse.
RemoteGitProvider
Indicates the remote git host.
@ List
User may list files if the Models.Instance allows it.
RightsType
The type of rights a model uses.
RepositoryRights
Rights for the git repository.
@ Api
The ApiHeaders.ApiVersionHeader header is missing or invalid.