/// <inheritdoc /> public async Task <Altinn.Studio.Designer.RepositoryClient.Model.Repository> CreateRepository(string org, CreateRepoOption options) { var repository = new Altinn.Studio.Designer.RepositoryClient.Model.Repository(); string developerUserName = AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext); string urlEnd = developerUserName == org ? "user/repos" : $"org/{org}/repos"; HttpResponseMessage response = await _httpClient.PostAsJsonAsync(urlEnd, options); if (response.StatusCode == HttpStatusCode.Created) { repository = await response.Content.ReadAsAsync <Altinn.Studio.Designer.RepositoryClient.Model.Repository>(); repository.RepositoryCreatedStatus = HttpStatusCode.Created; } else if (response.StatusCode == HttpStatusCode.Conflict) { // The repository with the same name already exists, 409 from Gitea API repository.RepositoryCreatedStatus = HttpStatusCode.Conflict; } else { _logger.LogError("User " + AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext) + " Create repository failed with statuscode " + response.StatusCode + " for " + org + " and repo-name " + options.Name); } return(repository); }
public async Task <ActionResult <RepositoryModel> > CopyApp([FromQuery] string org, [FromQuery] string sourceRepository, [FromQuery] string targetRepository) { try { Guard.AssertValidAppRepoName(targetRepository); } catch (ArgumentException) { return(BadRequest($"{targetRepository} is an invalid repository name.")); } try { Guard.AssertValidAppRepoName(sourceRepository); } catch (ArgumentException) { return(BadRequest($"{sourceRepository} is an invalid repository name.")); } var existingRepo = await _giteaApi.GetRepository(org, targetRepository); if (existingRepo != null) { return(StatusCode(409)); } string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext); try { RepositoryModel repo = await _repository.CopyRepository(org, sourceRepository, targetRepository, developer); if (repo.RepositoryCreatedStatus == HttpStatusCode.Created) { return(Created(repo.CloneUrl, repo)); } await _repository.DeleteRepository(org, targetRepository); return(StatusCode((int)repo.RepositoryCreatedStatus)); } catch (Exception e) { await _repository.DeleteRepository(org, targetRepository); return(StatusCode(500, e)); } }
/// <inheritdoc/> public async Task <Altinn.Studio.Designer.RepositoryClient.Model.Repository> GetRepository(string org, string repository) { Altinn.Studio.Designer.RepositoryClient.Model.Repository returnRepository = null; string giteaUrl = $"repos/{org}/{repository}"; HttpResponseMessage response = await _httpClient.GetAsync(giteaUrl); if (response.StatusCode == HttpStatusCode.OK) { returnRepository = await response.Content.ReadAsAsync <Altinn.Studio.Designer.RepositoryClient.Model.Repository>(); } else { _logger.LogError($"User {AuthenticationHelper.GetDeveloperUserName(_httpContextAccessor.HttpContext)} fetching app {org}/{repository} failed with reponsecode {response.StatusCode}"); } Stopwatch watchOwnerType = Stopwatch.StartNew(); if (!string.IsNullOrEmpty(returnRepository?.Owner?.Login)) { Stopwatch watch = Stopwatch.StartNew(); returnRepository.IsClonedToLocal = IsLocalRepo(returnRepository.Owner.Login, returnRepository.Name); watch.Stop(); _logger.Log(LogLevel.Information, "Islocalrepo - {0} ", watch.ElapsedMilliseconds); watch = Stopwatch.StartNew(); Organization organisation = await GetCachedOrg(returnRepository.Owner.Login); watch.Stop(); _logger.Log(LogLevel.Information, "Getcachedorg - {0} ", watch.ElapsedMilliseconds); if (organisation.Id != -1) { returnRepository.Owner.UserType = UserType.Org; } } watchOwnerType.Stop(); _logger.Log(LogLevel.Information, "To find if local repo and owner type - {0} ", watchOwnerType.ElapsedMilliseconds); return(returnRepository); }
public async Task <RepositoryModel> GetRepository(string org, string repository) { RepositoryModel returnRepository = await _giteaApi.GetRepository(org, repository); return(returnRepository); }
public RepositoryModel GetRepository(string org, string repository) { RepositoryModel returnRepository = _giteaApi.GetRepository(org, repository).Result; return(returnRepository); }