Example #1
0
        public static List <PullRequestCommentResponse> GetPullRequestCommentResponse(string query, string token)
        {
            var response = VSOApiUtil.GetResponse(query, token);

            //Get list of PR
            var pullReqeustCommentListResponse = JsonConvert.DeserializeObject <PullRequestCommentListResponse>(response);

            return(pullReqeustCommentListResponse.value);
        }
        public static bool GetReleaseStatus(string vso, string project, int id, string token)
        {
            var query = string.Format(RELEASE_DETAIL_QUERY_TEMPLATE, vso, project, id);

            var rawResponse = VSOApiUtil.GetResponse(query, token);
            var release     = JsonConvert.DeserializeObject <ReleaseResponse>(rawResponse);

            var failureCount = release.environments.Count(env => env.status != "succeeded");

            return(failureCount <= 0);
        }
        public static int GetMaxBuildId(DateTime begin, DateTime end, string vso, string project, string buildId, string token)
        {
            var url       = string.Format(OFFICIAL_BUILD_QUERY_WITH_PAGING_TEMPLATE, vso, project, buildId, begin.ToString("yyyy-MM-dd"), end.ToString("yyyy-MM-dd"), 1);
            var response  = VSOApiUtil.GetResponse(url, token);
            var buildList = JsonConvert.DeserializeObject <OfficialBuildListResponse>(response);

            if (buildList.value != null && buildList.value.Count > 0)
            {
                return(buildList.value[0].id);
            }
            return(-1);
        }
        public static List <ReleaseModel> GetReleaseDBModel(string vso, string project, string releaseQuery, string token)
        {
            var result = new List <ReleaseModel>();

            //Get list of PR;
            var rawResponse = VSOApiUtil.GetResponse(releaseQuery, token);
            var response    = JsonConvert.DeserializeObject <ReleaseListResponse>(rawResponse);

            //For each PR, we get comment
            foreach (var release in response.value)
            {
                result.Add(new ReleaseModel(vso, project, release.id, GetReleaseStatus(vso, project, release.id, token), release.createdOn));
            }
            return(result);
        }
        /// <summary>
        /// Get Test Result from for a release
        /// </summary>
        public static TestRunModel GetReleaseTestRunDataModel(string vso, string project, string releaseEnvId, int releaseId, DateTime creationTime, string token)
        {
            var url         = string.Format(RELEASE_TEST_RUN_QUERY_TEMPLATE, vso, project, releaseEnvId, releaseId);
            var rawResponse = VSOApiUtil.GetResponse(url, token);
            var response    = JsonConvert.DeserializeObject <ResultSummaryResponse>(rawResponse);

            TestRunModel result = null;

            if (response != null && response.aggregatedResultsAnalysis != null && response.aggregatedResultsAnalysis.resultsByOutcome != null)
            {
                var outcome = response.aggregatedResultsAnalysis.resultsByOutcome;
                var failed  = (outcome.Failed != null) ? outcome.Failed.count : 0;
                var passed  = (outcome.Passed != null) ? outcome.Passed.count : 0;
                result = new TestRunModel(vso, project, releaseId, releaseId, passed, failed + passed, creationTime);
            }
            return(result);
        }
        /// <summary>
        /// Get Test Result from for a build
        /// </summary>
        public static List <TestRunModel> GetBuildTestRunDataModel(string vso, string project, int buildId, string token)
        {
            var url         = string.Format(BUILD_TEST_RUN_QUERY_TEMPLATE, vso, project, buildId);
            var result      = new List <TestRunModel>();
            var rawResponse = VSOApiUtil.GetResponse(url, token);
            var response    = JsonConvert.DeserializeObject <TestRunListResponse>(rawResponse);

            if (response.value.Count > 0)
            {
                foreach (var item in response.value)
                {
                    var model = new TestRunModel(vso, project, buildId, item.id, item.passedTests, item.totalTests, item.startedDate);
                    result.Add(model);
                }
            }
            return(result);
        }
        public static List <OfficialBuildModel> GetOfficialBuildDBModel(string vso, string project, string buildListQuery, string token)
        {
            var result = new List <OfficialBuildModel>();

            //Get list of PR;
            var response          = VSOApiUtil.GetResponse(buildListQuery, token);
            var buildListResponse = JsonConvert.DeserializeObject <OfficialBuildListResponse>(response);

            //For each PR, we get comment
            foreach (var build in buildListResponse.value)
            {
                var buildResult  = build.result == "succeeded";
                var creationDate = DateTime.Parse(build.queueTime);
                result.Add(new OfficialBuildModel(vso, project, build.id, buildResult, build.sourceBranch, creationDate));
            }
            return(result);
        }
Example #8
0
        public static List <PullRequestModel> GetPullRequestDBModel(string vso, string project, string prListQuery, string repo, string token)
        {
            var result = new List <PullRequestModel>();

            //Get list of PR;
            var response = VSOApiUtil.GetResponse(prListQuery, token);
            var pullReqeustListResponse = JsonConvert.DeserializeObject <PullRequestListResponse>(response);

            //For each PR, we get comment
            foreach (var pr in pullReqeustListResponse.value)
            {
                int numOfUnresolvedComment = GetNumOfUnresolvedComment(pr.pullRequestId, repo, vso, project, token);
                var creationDate           = DateTime.Parse(pr.creationDate);
                result.Add(new PullRequestModel(vso, project, repo, pr.pullRequestId, numOfUnresolvedComment, creationDate));
            }
            return(result);
        }
        public static List <TestCoverageModel> GetTestCoverageForBuild(string vso, string project, int buildId, string token)
        {
            var result   = new List <TestCoverageModel>();
            var url      = string.Format(TEST_COVERAGE_QUERY_TEMPLATE, vso, project, buildId);
            var response = VSOApiUtil.GetResponse(url, token);
            var coverage = JsonConvert.DeserializeObject <TestCoverageListResponse>(response);

            if (coverage.count > 0)
            {
                var moduleList = coverage.value[0].modules;
                foreach (var module in moduleList)
                {
                    var stat = new TestCoverageModel(vso, project, buildId, module.name, module.statistics.linesCovered, module.statistics.linesNotCovered);
                    result.Add(stat);
                }
            }
            return(result);
        }
        public static List <VSOWorkItemDBModel> GetVSOWorkItemDBModel(string vso, DateTime start, DateTime end, string token, string areaPath)
        {
            var result         = new List <VSOWorkItemDBModel>();
            var url            = string.Format(VSO_WIQL_END_POINT_TEMPLATE, vso);
            var alertListQuery = string.Format(VSO_WORK_ITEM_LIST_QUERY_TEMPLATE, start.ToString("yyyy-MM-dd"), end.ToString("yyyy-MM-dd"), areaPath);

            //Get list of Alert Error from VSO API
            var response             = GetWIQLResponse(url, token, alertListQuery);
            var workItemListResponse = JsonConvert.DeserializeObject <VSOWorkItemListResponse>(response);

            foreach (var workItem in workItemListResponse.workItems)
            {
                var witQuery            = string.Format(VSO_WORK_ITEM_INSTANCE_QUERY_TEMPLATE, vso, workItem.id);
                var workItemResponseStr = VSOApiUtil.GetResponse(witQuery, token);
                var workItemResponse    = JsonConvert.DeserializeObject <VSOResponse>(workItemResponseStr);
                var model = new VSOWorkItemDBModel(workItem.id, workItemResponse.fields);
                result.Add(model);
            }

            return(result);
        }