Esempio n. 1
0
        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);
        }