Example #1
0
        public async Task <CMSBranchListModel> GetBranches(string projectId, string repositoryId, CMSAuthCredentialModel authCredential)
        {
            CMSBranchListModel result = new CMSBranchListModel();

            string repositoryUrl = $"{authCredential.Url}/{projectId}/_apis/git/repositories/{repositoryId}/refs?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 <CMSVSTSBranchListModel>();

            result.Items = serviceResult.Items.Select(c => new CMSBranchListItemModel {
                Id   = c.Name,
                Name = c.Name
            }).ToList();

            return(result);
        }
Example #2
0
        public async Task <CMSBranchListModel> GetBranches(string projectId, string repositoryId, 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/{repositoryId}/branches";
            }
            else
            {
                urlRepo = $"/repos/{defaultTeam.Name}/{repositoryId}/branches";
            }

            var response = await _httpProxyService.GetAsync(urlRepo, authCredential, Headers);

            var serviceResult = await response.MapTo <List <CMSGitHubBranchModel> >();

            var model = new CMSBranchListModel();

            model.Items = serviceResult.Select(c => new CMSBranchListItemModel
            {
                Id   = c.Name,
                Name = c.Name
            }).ToList();

            return(model);
        }