/// <summary> /// Create repository /// </summary> /// <param name="giteaSession"></param> /// <param name="org"></param> /// <param name="createRepoOption"></param> /// <returns></returns> public async Task <Repository> CreateRepositoryForOrg(string giteaSession, string org, CreateRepoOption createRepoOption) { AltinnCore.RepositoryClient.Model.Repository repository = null; DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(AltinnCore.RepositoryClient.Model.Repository)); Uri giteaUrl = new Uri(_settings.ApiEndPoint + "/org/" + org + "/repos"); Cookie cookie = new Cookie(_settings.GiteaCookieName, giteaSession, "/", _settings.ApiEndPointHost); if (Environment.GetEnvironmentVariable("GiteaApiEndpoint") != null && Environment.GetEnvironmentVariable("GiteaEndpoint") != null) { giteaUrl = new Uri(Environment.GetEnvironmentVariable("GiteaApiEndpoint") + "/org/" + org + "/repos"); new Cookie(_settings.GiteaCookieName, giteaSession, "/", Environment.GetEnvironmentVariable("GiteaEndpoint")); } CookieContainer cookieContainer = new CookieContainer(); cookieContainer.Add(cookie); HttpClientHandler handler = new HttpClientHandler() { CookieContainer = cookieContainer }; using (HttpClient client = new HttpClient(handler)) { var response = client.PostAsJsonAsync <CreateRepoOption>(giteaUrl, createRepoOption); if (response.Result.StatusCode == System.Net.HttpStatusCode.Created) { Stream stream = await response.Result.Content.ReadAsStreamAsync(); repository = serializer.ReadObject(stream) as AltinnCore.RepositoryClient.Model.Repository; } else if (response.Result.StatusCode == System.Net.HttpStatusCode.Forbidden || response.Result.StatusCode == System.Net.HttpStatusCode.Unauthorized) { // User is not logged in. return(null); } else { // Will cause an exception Temporary workaround Stream stream = await response.Result.Content.ReadAsStreamAsync(); repository = serializer.ReadObject(stream) as AltinnCore.RepositoryClient.Model.Repository; } } return(repository); }
public RepositoryModel GetRepository(string org, string repository) { RepositoryModel returnRepository = _giteaApi.GetRepository(org, repository).Result; return(returnRepository); }