简体   繁体   English

Azure Devops 小部件使用 azure-devops-extension-api 获取项目的所有拉取请求,仅获取一个结果

[英]Azure Devops widget using azure-devops-extension-api to fetch all Pull requests by project only fetching one result

I am trying to create a azure devops widget to pull all PRs associated with the project.我正在尝试创建一个 azure devops 小部件来拉取与该项目关联的所有 PR。 The widget is working but only pulling one PR data and not all.该小部件正在工作,但只提取一个 PR 数据,而不是全部。 Below is the widget code I am using下面是我正在使用的小部件代码

        VSS.require(["TFS/Dashboards/WidgetHelpers","TFS/VersionControl/GitRestClient"], 
        function (WidgetHelpers, TFS_Wit_WebApi) {
            WidgetHelpers.IncludeWidgetStyles();
            VSS.register("PRDuration", function () {                
            var projectId = VSS.getWebContext().project.id;

                var getQueryInfo = function (widgetSettings) {
                    // Get a WIT client to make REST calls to Azure DevOps Services                       
                   return TFS_Wit_WebApi.getClient().getPullRequestsByProject(projectId,"status: All ",null,0,100)
                        .then(function (prs) {
                            var $list = $('<ul>');
                            prs.forEach(function(pr) {                             
                            
                            //$list.append($('<li>').text("Project ID: " + projectId));
                            //$list.append($('<li>').text("Pull Request ID: " + pr.pullRequestId));
                            $list.append($('<li>').text("Pull Request title: " + pr.title));
                            $list.append($('<li>').text("Pull Request createdBy: " + pr.createdBy))
                            $list.append($('<li>').text("Pull Request creationDate: " + pr.creationDate));
                            $list.append($('<li>').text("Pull Request closedDate: " + pr.closedDate));
                            ;
                            //$list.append($('<li>').text("Query Name: " + query.name));
                            //$list.append($('<li>').text("Created By: " + (query.createdBy ? query.createdBy.displayName: "<unknown>") ));
                            })

                            // Append the list to the query-info-container
                            var $container = $('#query-info-container');
                            $container.empty();
                            $container.append($list);

                            // Use the widget helper and return success as Widget Status
                            return WidgetHelpers.WidgetStatusHelper.Success();
                        }, function (error) {
                            // Use the widget helper and return failure as Widget Status
                            return WidgetHelpers.WidgetStatusHelper.Failure(error.message);
                        });
                }

                return {
                    load: function (widgetSettings) {
                        // Set your title
                        var $title = $('h2.title');
                        $title.text('Hello World');

                        return getQueryInfo(widgetSettings);
                    }
                }
            });
        VSS.notifyLoadSucceeded();
    });   

When I used this widget it seems to be making below API call and fetching just one result: https://dev.azure.com/orgname/projectId/_apis/git/pullRequests?searchCriteria=status:All&api-version=6.0 When I used this widget it seems to be making below API call and fetching just one result: https://dev.azure.com/orgname/projectId/_apis/git/pullRequests?searchCriteria=status:All&api-version=6.0

If I am changing the api URL as below then I get all the results: https://dev.azure.com/orgname/projectId/_apis/git/pullRequests?searchCriteria.status=All&api-version=6.0 If I am changing the api URL as below then I get all the results: https://dev.azure.com/orgname/projectId/_apis/git/pullRequests?searchCriteria.status=All&api-version=6.0

Is there a way I can fix this in search criteria of function getPullRequestsByProject to get all results?有没有办法可以在 function getPullRequestsByProject 的搜索条件中解决此问题以获取所有结果?

I had to give search criteria in below format and it worked:我必须以以下格式提供搜索条件并且它有效:

var search_criteria = {"status": "All"}                  
                   return TFS_Wit_WebApi.getClient().getPullRequestsByProject(projectId,search_criteria)

This translates the URL to: https://dev.azure.com/org/projectId/_apis/git/pullRequests?searchCriteria[status]=All&api-version=6.0这会将 URL 转换为: https://dev.azure.com/org/projectId/_apis/git/pullRequests?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM