public async Task <CMSRepositoryListModel> GetRepositories(string projectId, CMSAuthCredentialModel authCredential) { var accountList = await GetAccounts(authCredential); var defaultTeam = accountList.Items.FirstOrDefault(c => c.AccountId.Equals(authCredential.AccountId)); var urlRepo = ""; if (defaultTeam != null && defaultTeam.IsOrganization) { urlRepo = $"/orgs/{defaultTeam.Name}/repos"; } else { urlRepo = $"/user/repos"; } var response = await _httpProxyService.GetAsync(urlRepo, authCredential, Headers); var serviceResult = await response.MapTo <List <CMSGitHubRepositoryModel> >(); var model = new CMSRepositoryListModel(); model.Items = serviceResult.Select(c => new CMSRepositoryListItemModel { ServiceId = c.Name, Name = c.FullName, Description = c.FullName, Link = c.CloneUrl }).ToList(); return(model); }
public async Task <CMSRepositoryListModel> GetRepositories(string projectId, CMSAuthCredentialModel authCredential) { CMSRepositoryListModel result = new CMSRepositoryListModel(); string repositoryUrl = $"{authCredential.Url}/{projectId}/_apis/git/repositories?api-version=4.1&api-version={_vstsOptions.Value.ApiVersion}"; var response = await _httpProxyService.GetAsync(repositoryUrl, authCredential); if (!response.IsSuccessStatusCode || response.StatusCode == System.Net.HttpStatusCode.NonAuthoritativeInformation) { if (response.StatusCode == System.Net.HttpStatusCode.NonAuthoritativeInformation) { result.Fail($"Code: {response.StatusCode}, Reason: The credentials are not correct"); return(result); } result.Fail($"Code: {response.StatusCode}, Reason: {await response.Content.ReadAsStringAsync()}"); return(result); } var serviceResult = await response.MapTo <CMSVSTSRepositoryListModel>(); result.Items = serviceResult.Items.Select(c => new CMSRepositoryListItemModel { AccountId = authCredential.AccountId, Name = c.Name, Link = c.RemoteUrl, Description = c.Name, ServiceId = c.Id }).ToList(); return(result); }
public async Task <CMSRepositoryListModel> GetRepositories(string projectId, CMSAuthCredentialModel authCredential) { var httpClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, $"{authCredential.Url}/projects/{projectId}"); request.Headers.Add("Private-Token", authCredential.AccessToken); var response = await httpClient.SendAsync(request); var serviceResult = await response.MapTo <List <CMSGitLabRepositoryModel> >(); var model = new CMSRepositoryListModel(); model.Items = serviceResult.Select(c => new CMSRepositoryListItemModel { ServiceId = c.Name, Name = c.FullName, Description = c.FullName, Link = c.CloneUrl }).ToList(); return(model); }