37#pragma warning disable CA1506
84 authenticationContext,
111 if (
model.Origin ==
null)
112 return BadRequest(
ErrorCode.ModelValidationFailure);
114 if (
model.AccessUser ==
null ^
model.AccessToken ==
null)
115 return BadRequest(
ErrorCode.RepoMismatchUserAndAccessToken);
165 "Clone{1} repository {0}",
168 ?
$"\"{cloneBranch}\" branch of"
194 await databaseContextFactory.UseContext(
195 async databaseContext =>
197 databaseContext.Instances.Attach(instance);
199 await databaseContext.Save(
ct);
208 return this.Created(api);
248 return Accepted(api);
284 return Accepted(api);
329 return this.Created(api);
359#pragma warning disable CA1502
361#pragma warning restore CA1502
365 if (
model.AccessUser ==
null ^
model.AccessToken ==
null)
368 if (
model.CheckoutSha !=
null &&
model.Reference !=
null)
371 if (
model.CheckoutSha !=
null &&
model.UpdateFromOrigin ==
true)
374 if (
model.NewTestMerges?.Any(
x =>
model.NewTestMerges.Any(
y =>
x !=
y &&
x.Number ==
y.Number)) ==
true)
377 if (
model.CommitterName?.Length == 0)
380 if (
model.CommitterEmail?.Length == 0)
428 if (
model.AccessToken?.Length == 0 &&
model.AccessUser?.Length == 0)
472 if (
model.UpdateFromOrigin ==
true)
473 if (
model.Reference !=
null)
475 else if (
model.CheckoutSha !=
null)
479 else if (
model.Reference !=
null ||
model.CheckoutSha !=
null)
485 "{0}est merge(s) {1}{2}",
491 model.NewTestMerges!.Select(
496 x.TargetCommitSha !=
null
500 x.TargetCommitSha[..7])
521 return Accepted(api);
537 Models.Instance instance,
583 Logger.LogDebug(
"Repository access token updated, performing auth check...");
594 if (gitHubClient ==
null)
598 AdditionalData =
"GitHub authentication failed!",
605 if (!
model.AccessToken.StartsWith(
Api.Models.RepositorySettings.TgsAppPrivateKeyPrefix))
607 var user =
await gitHubClient.User.Current();
625 AdditionalData = $
"GitHub Authentication Failure: {ex.Message}",
636 if (user.Username !=
model.AccessUser)
643 AdditionalData = $
"GitLab Authentication Failure: {ex.Message}",
650 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.
GitLab IGitRemoteFeatures.
const string GitLabUrl
Url for main GitLab site.
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 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.